mirror of
https://github.com/Sonny93/my-links.git
synced 2025-12-09 23:15:36 +00:00
feat: add user dropdown in navbar
This commit is contained in:
@@ -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'),
|
||||||
|
],
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|--------------------------------------------------------------------------
|
|--------------------------------------------------------------------------
|
||||||
|
|||||||
@@ -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 {
|
||||||
|
|||||||
@@ -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 }>(
|
||||||
fontSize: '14px',
|
({ theme, danger }) => ({
|
||||||
whiteSpace: 'nowrap',
|
fontSize: '14px',
|
||||||
padding: '8px 12px',
|
whiteSpace: 'nowrap',
|
||||||
borderRadius: theme.border.radius,
|
color: danger ? theme.colors.lightRed : theme.colors.primary,
|
||||||
|
padding: '8px 12px',
|
||||||
|
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',
|
||||||
|
|||||||
@@ -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>
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -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>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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,16 +73,22 @@ 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
|
||||||
<UserCard>
|
label={
|
||||||
<RoundedImage
|
<UserCard>
|
||||||
src={user.avatarUrl}
|
<RoundedImage
|
||||||
width={22}
|
src={user.avatarUrl}
|
||||||
referrerPolicy="no-referrer"
|
width={22}
|
||||||
/>
|
referrerPolicy="no-referrer"
|
||||||
{user.nickName}
|
/>
|
||||||
</UserCard>
|
{user.nickName}
|
||||||
</a>
|
</UserCard>
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<DropdownItemLink href={PATHS.AUTH.LOGOUT} danger>
|
||||||
|
<IoIosLogOut /> Logout
|
||||||
|
</DropdownItemLink>
|
||||||
|
</Dropdown>
|
||||||
</li>
|
</li>
|
||||||
</>
|
</>
|
||||||
) : (
|
) : (
|
||||||
|
|||||||
Reference in New Issue
Block a user