From c916b5870bdba1e430d8ef0c329e190ebdabcb7d Mon Sep 17 00:00:00 2001 From: Sonny Date: Tue, 14 May 2024 13:11:10 +0200 Subject: [PATCH] feat: add user dropdown in navbar --- adonisrc.ts | 5 ++- config/inertia.ts | 2 +- .../common/dropdown/dropdown_item.tsx | 21 ++++++----- .../collection/collection_controls.tsx | 9 ++--- .../dashboard/link_list/link_controls.tsx | 9 ++--- inertia/components/navbar/navbar.tsx | 35 +++++++++++++------ 6 files changed, 47 insertions(+), 34 deletions(-) diff --git a/adonisrc.ts b/adonisrc.ts index 5bc6446..a2d8852 100644 --- a/adonisrc.ts +++ b/adonisrc.ts @@ -10,7 +10,10 @@ export default defineConfig({ | will be scanned automatically from the "./commands" directory. | */ - commands: [() => import('@adonisjs/core/commands'), () => import('@adonisjs/lucid/commands')], + commands: [ + () => import('@adonisjs/core/commands'), + () => import('@adonisjs/lucid/commands'), + ], /* |-------------------------------------------------------------------------- diff --git a/config/inertia.ts b/config/inertia.ts index 1903819..357ec89 100644 --- a/config/inertia.ts +++ b/config/inertia.ts @@ -12,7 +12,7 @@ export default defineConfig({ */ sharedData: { errors: (ctx) => ctx.session?.flashMessages.get('errors'), - preferDarkTheme: (ctx) => ctx.session.get(PREFER_DARK_THEME, true), + preferDarkTheme: (ctx) => ctx.session?.get(PREFER_DARK_THEME, true), auth: async (ctx) => { await ctx.auth?.check(); return { diff --git a/inertia/components/common/dropdown/dropdown_item.tsx b/inertia/components/common/dropdown/dropdown_item.tsx index be72f13..0c1d64f 100644 --- a/inertia/components/common/dropdown/dropdown_item.tsx +++ b/inertia/components/common/dropdown/dropdown_item.tsx @@ -1,16 +1,19 @@ import styled from '@emotion/styled'; import { Link } from '@inertiajs/react'; -const DropdownItemBase = styled.div(({ theme }) => ({ - fontSize: '14px', - whiteSpace: 'nowrap', - padding: '8px 12px', - borderRadius: theme.border.radius, +const DropdownItemBase = styled.div<{ danger?: boolean }>( + ({ theme, danger }) => ({ + fontSize: '14px', + whiteSpace: 'nowrap', + color: danger ? theme.colors.lightRed : theme.colors.primary, + padding: '8px 12px', + borderRadius: theme.border.radius, - '&:hover': { - backgroundColor: theme.colors.background, - }, -})); + '&:hover': { + backgroundColor: theme.colors.background, + }, + }) +); const DropdownItemButton = styled(DropdownItemBase)({ display: 'flex', diff --git a/inertia/components/dashboard/collection/collection_controls.tsx b/inertia/components/dashboard/collection/collection_controls.tsx index 05f6209..08ad781 100644 --- a/inertia/components/dashboard/collection/collection_controls.tsx +++ b/inertia/components/dashboard/collection/collection_controls.tsx @@ -1,5 +1,4 @@ import PATHS from '#constants/paths'; -import styled from '@emotion/styled'; import { BsThreeDotsVertical } from 'react-icons/bs'; import { HiOutlinePencil } from 'react-icons/hi2'; import { IoIosAddCircleOutline } from 'react-icons/io'; @@ -7,10 +6,6 @@ import { IoTrashOutline } from 'react-icons/io5'; import Dropdown from '~/components/common/dropdown/dropdown'; import { DropdownItemLink } from '~/components/common/dropdown/dropdown_item'; -const DeleteItem = styled(DropdownItemLink)(({ theme }) => ({ - color: theme.colors.lightRed, -})); - const CollectionControls = () => ( }> @@ -19,9 +14,9 @@ const CollectionControls = () => ( Edit - + Delete - + ); diff --git a/inertia/components/dashboard/link_list/link_controls.tsx b/inertia/components/dashboard/link_list/link_controls.tsx index 359bfc1..db765ea 100644 --- a/inertia/components/dashboard/link_list/link_controls.tsx +++ b/inertia/components/dashboard/link_list/link_controls.tsx @@ -20,10 +20,6 @@ const StartItem = styled(DropdownItemButton)(({ theme }) => ({ color: theme.colors.yellow, })); -const DeleteItem = styled(DropdownItemLink)(({ theme }) => ({ - color: theme.colors.lightRed, -})); - export default function LinkControls({ link }: { link: Link }) { const theme = useTheme(); const { collections, setCollections } = useCollections(); @@ -87,11 +83,12 @@ export default function LinkControls({ link }: { link: Link }) { > Edit - Delete - + ); } diff --git a/inertia/components/navbar/navbar.tsx b/inertia/components/navbar/navbar.tsx index c648dc8..2c0104b 100644 --- a/inertia/components/navbar/navbar.tsx +++ b/inertia/components/navbar/navbar.tsx @@ -1,5 +1,8 @@ import styled from '@emotion/styled'; import { Link } from '@inertiajs/react'; +import { IoIosLogOut } from 'react-icons/io'; +import Dropdown from '~/components/common/dropdown/dropdown'; +import { DropdownItemLink } from '~/components/common/dropdown/dropdown_item'; import ExternalLink from '~/components/common/external_link'; import RoundedImage from '~/components/common/rounded_image'; import UnstyledList from '~/components/common/unstyled/unstyled_list'; @@ -25,10 +28,16 @@ const NavList = styled(UnstyledList)( gap: '1.5em', justifyContent: right ? 'flex-end' : 'flex-start', transition: theme.transition.delay, + + '& li': { + display: 'flex', + alignItems: 'center', + }, }) ); const UserCard = styled.div({ + padding: '0.25em 0.5em', display: 'flex', gap: '0.35em', alignItems: 'center', @@ -64,16 +73,22 @@ export default function Navbar() { Dashboard
  • - - - - {user.nickName} - - + + + {user.nickName} + + } + > + + Logout + +
  • ) : (