-
-
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.
SidebarFooterButton: clean code + remove hover link on buttons
- Loading branch information
1 parent
fb082dc
commit 9a78b04
Showing
6 changed files
with
60 additions
and
33 deletions.
There are no files selected for viewing
14 changes: 6 additions & 8 deletions
14
...tend/lib/components/Sidebar/components/SidebarFooter/components/BrainManagementButton.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 |
---|---|---|
@@ -1,22 +1,20 @@ | ||
import Link from "next/link"; | ||
import { useTranslation } from "react-i18next"; | ||
import { FaBrain } from "react-icons/fa"; | ||
|
||
import { sidebarLinkStyle } from "@/lib/components/Sidebar/components/SidebarFooter/styles/SidebarLinkStyle"; | ||
import { useBrainContext } from "@/lib/context/BrainProvider/hooks/useBrainContext"; | ||
|
||
import { SidebarFooterButton } from "./SidebarFooterButton"; | ||
|
||
export const BrainManagementButton = (): JSX.Element => { | ||
const { currentBrainId } = useBrainContext(); | ||
const { t } = useTranslation("brain"); | ||
|
||
return ( | ||
<Link | ||
<SidebarFooterButton | ||
href={`/brains-management/${currentBrainId ?? ""}`} | ||
className={sidebarLinkStyle} | ||
icon={<FaBrain className="w-8 h-8" />} | ||
label={t("myBrains")} | ||
data-testid="brain-management-button" | ||
> | ||
<FaBrain className="w-8 h-8" /> | ||
<span>{t("myBrains")}</span> | ||
</Link> | ||
/> | ||
); | ||
}; |
34 changes: 34 additions & 0 deletions
34
frontend/lib/components/Sidebar/components/SidebarFooter/components/SidebarFooterButton.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,34 @@ | ||
import { useRouter } from "next/navigation"; | ||
|
||
type SidebarFooterButtonProps = { | ||
icon: JSX.Element; | ||
label: string | JSX.Element; | ||
href?: string; | ||
onClick?: () => void; | ||
}; | ||
|
||
export const SidebarFooterButton = ({ | ||
icon, | ||
label, | ||
href, | ||
onClick, | ||
}: SidebarFooterButtonProps): JSX.Element => { | ||
const router = useRouter(); | ||
|
||
if (href !== undefined) { | ||
onClick = () => { | ||
void router.push(href); | ||
}; | ||
} | ||
|
||
return ( | ||
<button | ||
type="button" | ||
className="w-full rounded-lg px-5 py-2 text-base flex justify-start items-center gap-4 hover:bg-gray-200 dark:hover:bg-gray-800 hover:text-primary focus:outline-none" | ||
onClick={onClick} | ||
> | ||
{icon} | ||
<span className="text-ellipsis overflow-hidden">{label}</span> | ||
</button> | ||
); | ||
}; |
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
15 changes: 6 additions & 9 deletions
15
frontend/lib/components/Sidebar/components/SidebarFooter/components/UserButton.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 |
---|---|---|
@@ -1,21 +1,18 @@ | ||
import Link from "next/link"; | ||
|
||
import { Avatar } from "@/lib/components/ui/Avatar"; | ||
import { useSupabase } from "@/lib/context/SupabaseProvider"; | ||
|
||
import { SidebarFooterButton } from "./SidebarFooterButton"; | ||
import { useGravatar } from "../../../../../hooks/useGravatar"; | ||
import { sidebarLinkStyle } from "../styles/SidebarLinkStyle"; | ||
|
||
export const UserButton = (): JSX.Element => { | ||
const { session } = useSupabase(); | ||
const { gravatarUrl } = useGravatar(); | ||
|
||
return ( | ||
<Link aria-label="account" className={sidebarLinkStyle} href={"/user"}> | ||
<Avatar url={gravatarUrl} alt="user-gravatar" /> | ||
<span className="text-ellipsis overflow-hidden"> | ||
{session?.user.email ?? ""} | ||
</span> | ||
</Link> | ||
<SidebarFooterButton | ||
href={"/user"} | ||
icon={<Avatar url={gravatarUrl} />} | ||
label={session?.user.email ?? ""} | ||
/> | ||
); | ||
}; |
2 changes: 0 additions & 2 deletions
2
frontend/lib/components/Sidebar/components/SidebarFooter/styles/SidebarLinkStyle.tsx
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