-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
dc1bcc9
commit ab237c6
Showing
11 changed files
with
58 additions
and
189 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
57 changes: 57 additions & 0 deletions
57
...ainId]/components/BrainManagementTabs/components/SettingsTab/components/PublicPrompts.tsx
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,57 @@ | ||
import * as Accordion from "@radix-ui/react-accordion"; | ||
import { ChangeEvent, useEffect, useState } from "react"; | ||
|
||
import { usePromptApi } from "@/lib/api/prompt/usePromptApi"; | ||
import { Prompt } from "@/lib/types/Prompt"; | ||
|
||
type PublicPromptsProps = { | ||
onSelect: ({ title, content }: { title: string; content: string }) => void; | ||
}; | ||
|
||
export const PublicPrompts = ({ | ||
onSelect, | ||
}: PublicPromptsProps): JSX.Element => { | ||
const [publicPrompts, setPublicPrompts] = useState<Prompt[]>([]); | ||
|
||
const { getPublicPrompts } = usePromptApi(); | ||
|
||
const fetchPublicPrompts = async () => { | ||
setPublicPrompts(await getPublicPrompts()); | ||
}; | ||
|
||
const handleChange = (event: ChangeEvent<HTMLSelectElement>) => { | ||
const selectedPrompt = publicPrompts.find( | ||
(prompt) => prompt.id === event.target.value | ||
); | ||
if (selectedPrompt) { | ||
onSelect({ | ||
title: selectedPrompt.title, | ||
content: selectedPrompt.content, | ||
}); | ||
} | ||
}; | ||
|
||
useEffect(() => { | ||
void fetchPublicPrompts(); | ||
}, []); | ||
|
||
return ( | ||
<Accordion.Root className="AccordionRoot" type="single" collapsible> | ||
<Accordion.Item className="AccordionItem" value="item-1"> | ||
<Accordion.Trigger>Pick in public prompts</Accordion.Trigger> | ||
<Accordion.Content> | ||
<select | ||
onChange={handleChange} | ||
className="px-5 w-full py-2 dark:bg-gray-700 bg-gray-200 rounded-md" | ||
> | ||
{publicPrompts.map((prompt) => ( | ||
<option value={prompt.id} key={prompt.id}> | ||
{prompt.title} | ||
</option> | ||
))} | ||
</select> | ||
</Accordion.Content> | ||
</Accordion.Item> | ||
</Accordion.Root> | ||
); | ||
}; |
22 changes: 0 additions & 22 deletions
22
...nts/BrainManagementTabs/components/SettingsTab/components/PublicPrompts/PublicPrompts.tsx
This file was deleted.
Oops, something went wrong.
53 changes: 0 additions & 53 deletions
53
...s/SettingsTab/components/PublicPrompts/components/PublicPromptsList/PublicPromptsList.tsx
This file was deleted.
Oops, something went wrong.
59 changes: 0 additions & 59 deletions
59
...gsTab/components/PublicPrompts/components/PublicPromptsList/hooks/usePublicPromptsList.ts
This file was deleted.
Oops, something went wrong.
1 change: 0 additions & 1 deletion
1
...abs/components/SettingsTab/components/PublicPrompts/components/PublicPromptsList/index.ts
This file was deleted.
Oops, something went wrong.
1 change: 0 additions & 1 deletion
1
...s/BrainManagementTabs/components/SettingsTab/components/PublicPrompts/components/index.ts
This file was deleted.
Oops, something went wrong.
38 changes: 0 additions & 38 deletions
38
...nManagementTabs/components/SettingsTab/components/PublicPrompts/hooks/usePublicPrompts.ts
This file was deleted.
Oops, something went wrong.
1 change: 0 additions & 1 deletion
1
...]/components/BrainManagementTabs/components/SettingsTab/components/PublicPrompts/index.ts
This file was deleted.
Oops, something went wrong.
1 change: 0 additions & 1 deletion
1
...ement/[brainId]/components/BrainManagementTabs/components/SettingsTab/components/index.ts
This file was deleted.
Oops, something went wrong.