-
-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #70 from n4ze3m/next
v1.1.8
- Loading branch information
Showing
20 changed files
with
391 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import { useQuery } from "@tanstack/react-query" | ||
import { Dropdown, Empty, Tooltip } from "antd" | ||
import { BookIcon, ComputerIcon, ZapIcon } from "lucide-react" | ||
import React from "react" | ||
import { useTranslation } from "react-i18next" | ||
import { getAllPrompts } from "@/db" | ||
import { useMessageOption } from "@/hooks/useMessageOption" | ||
|
||
export const PromptSelect: React.FC = () => { | ||
const { t } = useTranslation("option") | ||
const { | ||
selectedSystemPrompt, | ||
setSelectedQuickPrompt, | ||
setSelectedSystemPrompt | ||
} = useMessageOption() | ||
|
||
const { data } = useQuery({ | ||
queryKey: ["getAllPromptsForSelect"], | ||
queryFn: getAllPrompts | ||
}) | ||
const handlePromptChange = (value?: string) => { | ||
if (!value) { | ||
setSelectedSystemPrompt(undefined) | ||
setSelectedQuickPrompt(undefined) | ||
return | ||
} | ||
const prompt = data?.find((prompt) => prompt.id === value) | ||
if (prompt?.is_system) { | ||
setSelectedSystemPrompt(prompt.id) | ||
} else { | ||
setSelectedSystemPrompt(undefined) | ||
setSelectedQuickPrompt(prompt!.content) | ||
} | ||
} | ||
return ( | ||
<> | ||
{data && ( | ||
<Dropdown | ||
menu={{ | ||
items: | ||
data.length > 0 | ||
? data?.map((prompt) => ({ | ||
key: prompt.id, | ||
label: ( | ||
<div className="w-52 gap-2 text-lg truncate inline-flex line-clamp-3 items-center dark:border-gray-700"> | ||
<span | ||
key={prompt.title} | ||
className="flex flex-row gap-3 items-center"> | ||
{prompt.is_system ? ( | ||
<ComputerIcon className="w-4 h-4" /> | ||
) : ( | ||
<ZapIcon className="w-4 h-4" /> | ||
)} | ||
{prompt.title} | ||
</span> | ||
</div> | ||
), | ||
onClick: () => { | ||
if (selectedSystemPrompt === prompt.id) { | ||
setSelectedSystemPrompt(undefined) | ||
} else { | ||
handlePromptChange(prompt.id) | ||
} | ||
} | ||
})) | ||
: [ | ||
{ | ||
key: "empty", | ||
label: <Empty /> | ||
} | ||
], | ||
style: { | ||
maxHeight: 500, | ||
overflowY: "scroll" | ||
}, | ||
className: "no-scrollbar", | ||
activeKey: selectedSystemPrompt | ||
}} | ||
placement={"topLeft"} | ||
trigger={["click"]}> | ||
<Tooltip title={t("selectAPrompt")}> | ||
<button type="button" className="dark:text-gray-300"> | ||
<BookIcon className="h-5 w-5" /> | ||
</button> | ||
</Tooltip> | ||
</Dropdown> | ||
)} | ||
</> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.