Skip to content

Commit

Permalink
feat: change share brain button logic (#1078)
Browse files Browse the repository at this point in the history
  • Loading branch information
mamadoudicko authored Aug 31, 2023
1 parent a43890c commit 08a1df0
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@ import { useState } from "react";
import { useBrainContext } from "@/lib/context/BrainProvider/hooks/useBrainContext";

import { BrainManagementTab } from "../types";
import { getTargetedTab } from "../utils/getTargetedTab";

// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
export const useBrainManagementTabs = () => {
const [selectedTab, setSelectedTab] =
useState<BrainManagementTab>("settings");
const [selectedTab, setSelectedTab] = useState<BrainManagementTab>(
getTargetedTab() ?? "settings"
);

const { deleteBrain, setCurrentBrainId } = useBrainContext();
const [isDeleteModalOpen, setIsDeleteModalOpen] = useState(false);
const router = useRouter();
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
export type BrainManagementTab = "settings" | "people" | "knowledge";
export const brainManagementTabs = ["settings", "people", "knowledge"] as const;

export type BrainManagementTab = (typeof brainManagementTabs)[number];
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { BrainManagementTab, brainManagementTabs } from "../types";

export const getTargetedTab = (): BrainManagementTab | undefined => {
const targetedTab = window.location.hash.split("#")[1];
if (brainManagementTabs.includes(targetedTab as BrainManagementTab)) {
return targetedTab as BrainManagementTab;
}
};
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { EntryComponentProps } from "@draft-js-plugins/mention/lib/MentionSuggestions/Entry/Entry";
import { UUID } from "crypto";
import { useRouter } from "next/navigation";
import { MdShare } from "react-icons/md";

import { MentionTriggerType } from "@/app/chat/[chatId]/components/ActionsBar/types";
import { ShareBrain } from "@/lib/components/ShareBrain";
import Button from "@/lib/components/ui/Button";

import { BrainSuggestion } from "./BrainSuggestion";
import { PromptSuggestion } from "./PromptSuggestion";
Expand All @@ -11,13 +12,23 @@ export const SuggestionRow = ({
mention,
...otherProps
}: EntryComponentProps): JSX.Element => {
const router = useRouter();
if ((mention.trigger as MentionTriggerType) === "@") {
return (
<div {...otherProps}>
<div className="relative flex group px-4">
<BrainSuggestion content={mention.name} />
<div className="absolute right-0 flex flex-row">
<ShareBrain brainId={mention.id as UUID} />
<Button
className="group-hover:visible invisible hover:text-red-500 transition-[colors,opacity] p-1"
onClick={() =>
router.push(`/brains-management/${mention.id as string}#people`)
}
variant={"tertiary"}
data-testId="share-brain-button"
>
<MdShare className="text-xl" />
</Button>
</div>
</div>
</div>
Expand Down

0 comments on commit 08a1df0

Please sign in to comment.