(props: { onClose?: () => void })
| 140 | } |
| 141 | |
| 142 | function UserPromptModal(props: { onClose?: () => void }) { |
| 143 | const promptStore = usePromptStore(); |
| 144 | const userPrompts = promptStore.getUserPrompts(); |
| 145 | const builtinPrompts = SearchService.builtinPrompts; |
| 146 | const allPrompts = userPrompts.concat(builtinPrompts); |
| 147 | const [searchInput, setSearchInput] = useState(""); |
| 148 | const [searchPrompts, setSearchPrompts] = useState<Prompt[]>([]); |
| 149 | const prompts = searchInput.length > 0 ? searchPrompts : allPrompts; |
| 150 | |
| 151 | const [editingPromptId, setEditingPromptId] = useState<string>(); |
| 152 | |
| 153 | useEffect(() => { |
| 154 | if (searchInput.length > 0) { |
| 155 | const searchResult = SearchService.search(searchInput); |
| 156 | setSearchPrompts(searchResult); |
| 157 | } else { |
| 158 | setSearchPrompts([]); |
| 159 | } |
| 160 | }, [searchInput]); |
| 161 | |
| 162 | return ( |
| 163 | <div className="modal-mask"> |
| 164 | <Modal |
| 165 | title={Locale.Settings.Prompt.Modal.Title} |
| 166 | onClose={() => props.onClose?.()} |
| 167 | actions={[ |
| 168 | <IconButton |
| 169 | key="add" |
| 170 | onClick={() => { |
| 171 | const promptId = promptStore.add({ |
| 172 | id: nanoid(), |
| 173 | createdAt: Date.now(), |
| 174 | title: "Empty Prompt", |
| 175 | content: "Empty Prompt Content", |
| 176 | }); |
| 177 | setEditingPromptId(promptId); |
| 178 | }} |
| 179 | icon={<AddIcon />} |
| 180 | bordered |
| 181 | text={Locale.Settings.Prompt.Modal.Add} |
| 182 | />, |
| 183 | ]} |
| 184 | > |
| 185 | <div className={styles["user-prompt-modal"]}> |
| 186 | <input |
| 187 | type="text" |
| 188 | className={styles["user-prompt-search"]} |
| 189 | placeholder={Locale.Settings.Prompt.Modal.Search} |
| 190 | value={searchInput} |
| 191 | onInput={(e) => setSearchInput(e.currentTarget.value)} |
| 192 | ></input> |
| 193 | |
| 194 | <div className={styles["user-prompt-list"]}> |
| 195 | {prompts.map((v, _) => ( |
| 196 | <div className={styles["user-prompt-item"]} key={v.id ?? v.title}> |
| 197 | <div className={styles["user-prompt-header"]}> |
| 198 | <div className={styles["user-prompt-title"]}>{v.title}</div> |
| 199 | <div className={styles["user-prompt-content"] + " one-line"}> |
nothing calls this directly
no test coverage detected