feat: add user dropdown in navbar

This commit is contained in:
Sonny
2024-05-14 13:11:10 +02:00
committed by Sonny
parent 243984ca66
commit c916b5870b
6 changed files with 47 additions and 34 deletions

View File

@@ -10,7 +10,10 @@ export default defineConfig({
| will be scanned automatically from the "./commands" directory. | 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'),
],
/* /*
|-------------------------------------------------------------------------- |--------------------------------------------------------------------------

View File

@@ -12,7 +12,7 @@ export default defineConfig({
*/ */
sharedData: { sharedData: {
errors: (ctx) => ctx.session?.flashMessages.get('errors'), 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) => { auth: async (ctx) => {
await ctx.auth?.check(); await ctx.auth?.check();
return { return {

View File

@@ -1,16 +1,19 @@
import styled from '@emotion/styled'; import styled from '@emotion/styled';
import { Link } from '@inertiajs/react'; import { Link } from '@inertiajs/react';
const DropdownItemBase = styled.div(({ theme }) => ({ const DropdownItemBase = styled.div<{ danger?: boolean }>(
({ theme, danger }) => ({
fontSize: '14px', fontSize: '14px',
whiteSpace: 'nowrap', whiteSpace: 'nowrap',
color: danger ? theme.colors.lightRed : theme.colors.primary,
padding: '8px 12px', padding: '8px 12px',
borderRadius: theme.border.radius, borderRadius: theme.border.radius,
'&:hover': { '&:hover': {
backgroundColor: theme.colors.background, backgroundColor: theme.colors.background,
}, },
})); })
);
const DropdownItemButton = styled(DropdownItemBase)({ const DropdownItemButton = styled(DropdownItemBase)({
display: 'flex', display: 'flex',

View File

@@ -1,5 +1,4 @@
import PATHS from '#constants/paths'; import PATHS from '#constants/paths';
import styled from '@emotion/styled';
import { BsThreeDotsVertical } from 'react-icons/bs'; import { BsThreeDotsVertical } from 'react-icons/bs';
import { HiOutlinePencil } from 'react-icons/hi2'; import { HiOutlinePencil } from 'react-icons/hi2';
import { IoIosAddCircleOutline } from 'react-icons/io'; import { IoIosAddCircleOutline } from 'react-icons/io';
@@ -7,10 +6,6 @@ import { IoTrashOutline } from 'react-icons/io5';
import Dropdown from '~/components/common/dropdown/dropdown'; import Dropdown from '~/components/common/dropdown/dropdown';
import { DropdownItemLink } from '~/components/common/dropdown/dropdown_item'; import { DropdownItemLink } from '~/components/common/dropdown/dropdown_item';
const DeleteItem = styled(DropdownItemLink)(({ theme }) => ({
color: theme.colors.lightRed,
}));
const CollectionControls = () => ( const CollectionControls = () => (
<Dropdown label={<BsThreeDotsVertical />}> <Dropdown label={<BsThreeDotsVertical />}>
<DropdownItemLink href={PATHS.LINK.CREATE}> <DropdownItemLink href={PATHS.LINK.CREATE}>
@@ -19,9 +14,9 @@ const CollectionControls = () => (
<DropdownItemLink href={PATHS.COLLECTION.EDIT}> <DropdownItemLink href={PATHS.COLLECTION.EDIT}>
<HiOutlinePencil /> Edit <HiOutlinePencil /> Edit
</DropdownItemLink> </DropdownItemLink>
<DeleteItem href={PATHS.COLLECTION.REMOVE}> <DropdownItemLink href={PATHS.COLLECTION.REMOVE} danger>
<IoTrashOutline /> Delete <IoTrashOutline /> Delete
</DeleteItem> </DropdownItemLink>
</Dropdown> </Dropdown>
); );

View File

@@ -20,10 +20,6 @@ const StartItem = styled(DropdownItemButton)(({ theme }) => ({
color: theme.colors.yellow, color: theme.colors.yellow,
})); }));
const DeleteItem = styled(DropdownItemLink)(({ theme }) => ({
color: theme.colors.lightRed,
}));
export default function LinkControls({ link }: { link: Link }) { export default function LinkControls({ link }: { link: Link }) {
const theme = useTheme(); const theme = useTheme();
const { collections, setCollections } = useCollections(); const { collections, setCollections } = useCollections();
@@ -87,11 +83,12 @@ export default function LinkControls({ link }: { link: Link }) {
> >
<HiOutlinePencil /> Edit <HiOutlinePencil /> Edit
</DropdownItemLink> </DropdownItemLink>
<DeleteItem <DropdownItemLink
href={appendCollectionId(PATHS.LINK.REMOVE, link.collectionId)} href={appendCollectionId(PATHS.LINK.REMOVE, link.collectionId)}
danger
> >
<IoTrashOutline /> Delete <IoTrashOutline /> Delete
</DeleteItem> </DropdownItemLink>
</Dropdown> </Dropdown>
); );
} }

View File

@@ -1,5 +1,8 @@
import styled from '@emotion/styled'; import styled from '@emotion/styled';
import { Link } from '@inertiajs/react'; 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 ExternalLink from '~/components/common/external_link';
import RoundedImage from '~/components/common/rounded_image'; import RoundedImage from '~/components/common/rounded_image';
import UnstyledList from '~/components/common/unstyled/unstyled_list'; import UnstyledList from '~/components/common/unstyled/unstyled_list';
@@ -25,10 +28,16 @@ const NavList = styled(UnstyledList)<NavbarListDirection>(
gap: '1.5em', gap: '1.5em',
justifyContent: right ? 'flex-end' : 'flex-start', justifyContent: right ? 'flex-end' : 'flex-start',
transition: theme.transition.delay, transition: theme.transition.delay,
'& li': {
display: 'flex',
alignItems: 'center',
},
}) })
); );
const UserCard = styled.div({ const UserCard = styled.div({
padding: '0.25em 0.5em',
display: 'flex', display: 'flex',
gap: '0.35em', gap: '0.35em',
alignItems: 'center', alignItems: 'center',
@@ -64,7 +73,8 @@ export default function Navbar() {
<Link href={PATHS.DASHBOARD}>Dashboard</Link> <Link href={PATHS.DASHBOARD}>Dashboard</Link>
</li> </li>
<li> <li>
<a href={PATHS.AUTH.LOGOUT}> <Dropdown
label={
<UserCard> <UserCard>
<RoundedImage <RoundedImage
src={user.avatarUrl} src={user.avatarUrl}
@@ -73,7 +83,12 @@ export default function Navbar() {
/> />
{user.nickName} {user.nickName}
</UserCard> </UserCard>
</a> }
>
<DropdownItemLink href={PATHS.AUTH.LOGOUT} danger>
<IoIosLogOut /> Logout
</DropdownItemLink>
</Dropdown>
</li> </li>
</> </>
) : ( ) : (