-
-
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.
Revert "Revert "feat: remove private prompts on related brain delete (#…
- Loading branch information
1 parent
8eb564f
commit 66c7eda
Showing
11 changed files
with
189 additions
and
58 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: 0 additions & 57 deletions
57
...ainId]/components/BrainManagementTabs/components/SettingsTab/components/PublicPrompts.tsx
This file was deleted.
Oops, something went wrong.
22 changes: 22 additions & 0 deletions
22
...nts/BrainManagementTabs/components/SettingsTab/components/PublicPrompts/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,22 @@ | ||
import { PublicPromptsList } from "./components/PublicPromptsList/PublicPromptsList"; | ||
import { usePublicPrompts } from "./hooks/usePublicPrompts"; | ||
|
||
type PublicPromptsProps = { | ||
onSelect: ({ title, content }: { title: string; content: string }) => void; | ||
}; | ||
|
||
export const PublicPrompts = ({ | ||
onSelect, | ||
}: PublicPromptsProps): JSX.Element => { | ||
const { handleChange, publicPrompts } = usePublicPrompts({ | ||
onSelect, | ||
}); | ||
|
||
return ( | ||
<PublicPromptsList | ||
options={publicPrompts} | ||
onChange={handleChange} | ||
onSelect={onSelect} | ||
/> | ||
); | ||
}; |
53 changes: 53 additions & 0 deletions
53
...s/SettingsTab/components/PublicPrompts/components/PublicPromptsList/PublicPromptsList.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,53 @@ | ||
import { ChangeEvent } from "react"; | ||
|
||
import { Prompt } from "@/lib/types/Prompt"; | ||
|
||
import { usePublicPromptsList } from "./hooks/usePublicPromptsList"; | ||
|
||
type PublicPromptsListProps = { | ||
options: Prompt[]; | ||
onChange: (event: ChangeEvent<HTMLSelectElement>) => void; | ||
onSelect: ({ title, content }: { title: string; content: string }) => void; | ||
}; | ||
|
||
export const PublicPromptsList = ({ | ||
options, | ||
onChange, | ||
onSelect, | ||
}: PublicPromptsListProps): JSX.Element => { | ||
const { | ||
handleOptionClick, | ||
isOpen, | ||
selectRef, | ||
selectedOption, | ||
toggleDropdown, | ||
} = usePublicPromptsList({ | ||
onChange, | ||
onSelect, | ||
}); | ||
|
||
return ( | ||
<div ref={selectRef} className="relative min-w-[200px] inline-block"> | ||
<button | ||
onClick={toggleDropdown} | ||
type="button" | ||
className="px-4 py-2 w-full text-gray-700 bg-white border rounded-md focus:outline-none focus:border-blue-500" | ||
> | ||
{selectedOption ? selectedOption.title : "Select a Quivr Personality"} | ||
</button> | ||
{isOpen && ( | ||
<div className="absolute top-10 w-full bg-white border rounded-md shadow-lg"> | ||
{options.map((option) => ( | ||
<div | ||
key={option.id} | ||
className="px-4 py-2 cursor-pointer hover:bg-gray-100" | ||
onClick={() => handleOptionClick(option)} | ||
> | ||
{option.title} | ||
</div> | ||
))} | ||
</div> | ||
)} | ||
</div> | ||
); | ||
}; |
59 changes: 59 additions & 0 deletions
59
...gsTab/components/PublicPrompts/components/PublicPromptsList/hooks/usePublicPromptsList.ts
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,59 @@ | ||
import { ChangeEvent, useEffect, useRef, useState } from "react"; | ||
|
||
import { Prompt } from "@/lib/types/Prompt"; | ||
|
||
type UsePublicPromptsListProps = { | ||
onChange: (event: ChangeEvent<HTMLSelectElement>) => void; | ||
onSelect: ({ title, content }: { title: string; content: string }) => void; | ||
}; | ||
|
||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types | ||
export const usePublicPromptsList = ({ | ||
onChange, | ||
onSelect, | ||
}: UsePublicPromptsListProps) => { | ||
const [isOpen, setIsOpen] = useState(false); | ||
const [selectedOption, setSelectedOption] = useState<Prompt | null>(null); | ||
const selectRef = useRef<HTMLDivElement>(null); | ||
|
||
const toggleDropdown = () => { | ||
setIsOpen((prevIsOpen) => !prevIsOpen); | ||
}; | ||
|
||
const handleOptionClick = (option: Prompt) => { | ||
setSelectedOption(option); | ||
setIsOpen(false); | ||
onChange({ | ||
target: { value: option.id }, | ||
} as ChangeEvent<HTMLSelectElement>); | ||
onSelect({ | ||
title: option.title, | ||
content: option.content, | ||
}); | ||
}; | ||
|
||
const handleClickOutside = (event: MouseEvent) => { | ||
if ( | ||
selectRef.current && | ||
!selectRef.current.contains(event.target as Node) | ||
) { | ||
setIsOpen(false); | ||
} | ||
}; | ||
|
||
useEffect(() => { | ||
document.addEventListener("click", handleClickOutside, true); | ||
|
||
return () => { | ||
document.removeEventListener("click", handleClickOutside, true); | ||
}; | ||
}, []); | ||
|
||
return { | ||
isOpen, | ||
selectedOption, | ||
selectRef, | ||
toggleDropdown, | ||
handleOptionClick, | ||
}; | ||
}; |
1 change: 1 addition & 0 deletions
1
...abs/components/SettingsTab/components/PublicPrompts/components/PublicPromptsList/index.ts
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 @@ | ||
export * from "./PublicPromptsList"; |
1 change: 1 addition & 0 deletions
1
...s/BrainManagementTabs/components/SettingsTab/components/PublicPrompts/components/index.ts
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 @@ | ||
export * from "./PublicPromptsList"; |
38 changes: 38 additions & 0 deletions
38
...nManagementTabs/components/SettingsTab/components/PublicPrompts/hooks/usePublicPrompts.ts
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,38 @@ | ||
import { ChangeEvent, useEffect, useState } from "react"; | ||
|
||
import { usePromptApi } from "@/lib/api/prompt/usePromptApi"; | ||
import { Prompt } from "@/lib/types/Prompt"; | ||
|
||
type UsePublicPromptsProps = { | ||
onSelect: ({ title, content }: { title: string; content: string }) => void; | ||
}; | ||
|
||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types | ||
export const usePublicPrompts = ({ onSelect }: UsePublicPromptsProps) => { | ||
const [publicPrompts, setPublicPrompts] = useState<Prompt[]>([]); | ||
const { getPublicPrompts } = usePromptApi(); | ||
|
||
useEffect(() => { | ||
const fetchPublicPrompts = async () => { | ||
setPublicPrompts(await getPublicPrompts()); | ||
}; | ||
void fetchPublicPrompts(); | ||
}, []); | ||
|
||
const handleChange = (event: ChangeEvent<HTMLSelectElement>) => { | ||
const selectedPrompt = publicPrompts.find( | ||
(prompt) => prompt.id === event.target.value | ||
); | ||
if (selectedPrompt) { | ||
onSelect({ | ||
title: selectedPrompt.title, | ||
content: selectedPrompt.content, | ||
}); | ||
} | ||
}; | ||
|
||
return { | ||
publicPrompts, | ||
handleChange, | ||
}; | ||
}; |
1 change: 1 addition & 0 deletions
1
...]/components/BrainManagementTabs/components/SettingsTab/components/PublicPrompts/index.ts
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 @@ | ||
export * from "./PublicPrompts"; |
1 change: 1 addition & 0 deletions
1
...ement/[brainId]/components/BrainManagementTabs/components/SettingsTab/components/index.ts
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 @@ | ||
export * from "./PublicPrompts"; |