-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: add ActionsBar * feat: add brain trigger
- Loading branch information
1 parent
69d0893
commit 69a73f5
Showing
16 changed files
with
258 additions
and
25 deletions.
There are no files selected for viewing
52 changes: 52 additions & 0 deletions
52
frontend/app/v2/chat/[chatId]/components/ActionsBar/ActionsBar.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,52 @@ | ||
import { useTranslation } from "react-i18next"; | ||
import { Mention } from "react-mentions"; // Import the required components | ||
|
||
import { useBrainContext } from "@/lib/context/BrainProvider/hooks/useBrainContext"; | ||
|
||
import { MentionItem, MentionsInput } from "./components"; | ||
import { useActionsBar } from "./hooks/useActionsBar"; | ||
|
||
export const ActionsBar = (): JSX.Element => { | ||
const { t } = useTranslation(["chat"]); | ||
const { allBrains } = useBrainContext(); | ||
const { | ||
handleAddMention, | ||
handleChange, | ||
handleRemoveMention, | ||
mentions, | ||
value, | ||
} = useActionsBar(); | ||
|
||
return ( | ||
<div className="flex flex-row w-full shadow-md dark:shadow-primary/25 hover:shadow-xl transition-shadow rounded-xl bg-white dark:bg-black border border-black/10 dark:border-white/25 p-6"> | ||
<div className="flex flex-row"> | ||
{mentions.map((mention) => ( | ||
<MentionItem | ||
key={mention.id} | ||
text={mention.display} | ||
onRemove={() => handleRemoveMention(mention.id)} | ||
prefix="@" | ||
/> | ||
))} | ||
</div> | ||
<div className="flex flex-1 flex-col"> | ||
<MentionsInput | ||
onChange={handleChange} | ||
value={value} | ||
placeholder={t("actions_bar_placeholder")} | ||
disabled={mentions.length !== 0} | ||
> | ||
<Mention | ||
trigger="@" | ||
data={allBrains.map(({ id, name }) => ({ id, display: name }))} | ||
renderSuggestion={(_, __, content) => ( | ||
<p className="mb-2">{content}</p> | ||
)} | ||
onAdd={(id, display) => handleAddMention(String(id), display)} | ||
displayTransform={() => ""} | ||
/> | ||
</MentionsInput> | ||
</div> | ||
</div> | ||
); | ||
}; |
25 changes: 25 additions & 0 deletions
25
frontend/app/v2/chat/[chatId]/components/ActionsBar/components/MentionItem.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,25 @@ | ||
import { MdRemoveCircleOutline } from "react-icons/md"; | ||
|
||
type MentionItemProps = { | ||
text: string; | ||
onRemove: () => void; | ||
prefix?: string; | ||
}; | ||
|
||
export const MentionItem = ({ | ||
text, | ||
prefix = "", | ||
onRemove, | ||
}: MentionItemProps): JSX.Element => { | ||
return ( | ||
<div className="relative"> | ||
<div className="flex items-center bg-gray-300 mr-2 text-gray-600 rounded-2xl py-1 px-2"> | ||
<span className="flex-grow">{`${prefix}${text}`}</span> | ||
<MdRemoveCircleOutline | ||
className="cursor-pointer absolute top-[-10px] right-[5px]" | ||
onClick={onRemove} | ||
/> | ||
</div> | ||
</div> | ||
); | ||
}; |
74 changes: 74 additions & 0 deletions
74
frontend/app/v2/chat/[chatId]/components/ActionsBar/components/MentionsInput.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,74 @@ | ||
import { | ||
MentionProps, | ||
MentionsInput as ReactMentionsInput, | ||
} from "react-mentions"; | ||
|
||
type StyleMentionsInputProps = { | ||
value: string; | ||
onChange: (value: string) => void; | ||
placeholder: string; | ||
children: | ||
| React.ReactElement<MentionProps> | ||
| Array<React.ReactElement<MentionProps>>; | ||
disabled?: boolean; | ||
}; | ||
|
||
export const MentionsInput = ({ | ||
children, | ||
onChange, | ||
placeholder, | ||
value, | ||
disabled = false, | ||
}: StyleMentionsInputProps): JSX.Element => { | ||
if (disabled) { | ||
return ( | ||
<input | ||
autoFocus | ||
placeholder={placeholder} | ||
onChange={(event) => onChange(event.target.value)} | ||
value={value} | ||
className="focus:outline-none focus:border-none" | ||
/> | ||
); | ||
} | ||
|
||
return ( | ||
<ReactMentionsInput | ||
placeholder={placeholder} | ||
value={value} | ||
autoFocus | ||
onChange={(_, __, newValue) => onChange(newValue)} | ||
forceSuggestionsAboveCursor | ||
style={{ | ||
input: { | ||
outline: "none", | ||
border: "none", | ||
"&:focus": { | ||
outline: "none", | ||
border: "none", | ||
}, | ||
}, | ||
suggestions: { | ||
zIndex: 99999, | ||
boxShadow: | ||
"0px 4px 6px rgba(0, 0, 0, 0.1), 0px 2px 4px rgba(0, 0, 0, 0.06)", | ||
"@media (prefers-color-scheme: dark)": { | ||
boxShadow: | ||
"0px 4px 6px rgba(255, 255, 255, 0.25), 0px 2px 4px rgba(255, 255, 255, 0.125)", | ||
}, | ||
"&:hover": { | ||
boxShadow: | ||
"0px 10px 15px rgba(0, 0, 0, 0.1), 0px 4px 6px rgba(0, 0, 0, 0.06)", | ||
}, | ||
transition: "box-shadow 0.3s ease", | ||
borderRadius: "0.75rem", | ||
background: "white", | ||
border: "1px solid rgba(0, 0, 0, 0.1)", | ||
padding: "1.5rem", | ||
}, | ||
}} | ||
> | ||
{children} | ||
</ReactMentionsInput> | ||
); | ||
}; |
2 changes: 2 additions & 0 deletions
2
frontend/app/v2/chat/[chatId]/components/ActionsBar/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,2 @@ | ||
export * from "./MentionItem"; | ||
export * from "./MentionsInput"; |
33 changes: 33 additions & 0 deletions
33
frontend/app/v2/chat/[chatId]/components/ActionsBar/hooks/useActionsBar.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,33 @@ | ||
import { useState } from "react"; | ||
|
||
import { MentionType } from "../types"; | ||
|
||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types | ||
export const useActionsBar = () => { | ||
const [value, setValue] = useState(""); | ||
const [mentions, setMentions] = useState<MentionType[]>([]); // Store the list of mentions | ||
|
||
const handleChange = (newPlainTextValue: string) => { | ||
setValue(newPlainTextValue); | ||
}; | ||
|
||
const handleAddMention: (id: string, display: string) => void = ( | ||
id, | ||
display | ||
) => { | ||
setMentions([...mentions, { id, display }]); | ||
}; | ||
|
||
const handleRemoveMention = (id: string) => { | ||
const updatedMentions = mentions.filter((m) => m.id !== id); | ||
setMentions(updatedMentions); | ||
}; | ||
|
||
return { | ||
mentions, | ||
handleAddMention, | ||
handleRemoveMention, | ||
handleChange, | ||
value, | ||
}; | ||
}; |
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 "./ActionsBar"; |
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 type MentionType = { id: string; display: string }; |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,2 +1,2 @@ | ||
export * from "./ColoredText"; | ||
export * from "./ActionsBar"; | ||
export * from "./ShortCuts"; |
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.