fix: page transition no longer play when changing collection

This commit is contained in:
Sonny
2024-11-03 18:40:54 +01:00
committed by Sonny
parent cc1e7b91c0
commit 343160f324
4 changed files with 53 additions and 30 deletions

View File

@@ -8,6 +8,7 @@ import {
NavLink, NavLink,
ScrollArea, ScrollArea,
Skeleton, Skeleton,
Stack,
Text, Text,
} from '@mantine/core'; } from '@mantine/core';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
@@ -29,12 +30,17 @@ export function DashboardNavbar({ isOpen, toggle }: DashboardNavbarProps) {
variant: 'subtle', variant: 'subtle',
color: 'blue', color: 'blue',
active: true, active: true,
styles: {
label: {
fontSize: '16px',
},
},
}; };
return ( return (
<AppShell.Navbar p="md"> <AppShell.Navbar p="md">
<Group hiddenFrom="sm" mb="md"> <Group hiddenFrom="sm" mb="md">
<Burger opened={isOpen} onClick={toggle} size="sm" /> <Burger opened={isOpen} onClick={toggle} size="sm" />
<Text>Menu</Text> <Text>Navigation</Text>
</Group> </Group>
<MantineUserCard /> <MantineUserCard />
<Divider mt="xs" mb="md" /> <Divider mt="xs" mb="md" />
@@ -52,6 +58,7 @@ export function DashboardNavbar({ isOpen, toggle }: DashboardNavbarProps) {
label={t('settings')} label={t('settings')}
leftSection={<PiGearLight size="1.5rem" />} leftSection={<PiGearLight size="1.5rem" />}
variant="subtle" variant="subtle"
styles={common.styles}
/> />
<NavLink <NavLink
{...common} {...common}
@@ -72,15 +79,17 @@ export function DashboardNavbar({ isOpen, toggle }: DashboardNavbarProps) {
label={t('link.create')} label={t('link.create')}
leftSection={<AiOutlineFolderAdd size="1.5rem" />} leftSection={<AiOutlineFolderAdd size="1.5rem" />}
/> />
<Text size="sm" fw={500} c="dimmed" mt="sm" ml="md"> <Text c="dimmed" mt="xs" ml="md" mb="sm">
{t('favorite')} {0} {t('favorite')} {0}
</Text> </Text>
<AppShell.Section grow component={ScrollArea}> <AppShell.Section grow component={ScrollArea}>
{Array(15) <Stack gap="xs">
.fill(0) {Array(15)
.map((_, index) => ( .fill(0)
<Skeleton key={index} h={28} mt="sm" animate={false} /> .map((_, index) => (
))} <Skeleton key={index} h={28} animate={false} />
))}
</Stack>
</AppShell.Section> </AppShell.Section>
</AppShell.Navbar> </AppShell.Navbar>
); );

View File

@@ -26,13 +26,24 @@ export default function BaseLayout({ children }: { children: ReactNode }) {
} }
}; };
const canTransition = (currentLocation: URL, newLocation: URL) =>
currentLocation.pathname !== newLocation.pathname;
useEffect(() => { useEffect(() => {
const currentLocation = new URL(window.location.href);
flipClass(TRANSITION_IN_CLASS, TRANSITION_OUT_CLASS); flipClass(TRANSITION_IN_CLASS, TRANSITION_OUT_CLASS);
router.on('start', () =>
flipClass(TRANSITION_OUT_CLASS, TRANSITION_IN_CLASS) router.on(
'start',
(event) =>
canTransition(currentLocation, event.detail.visit.url) &&
flipClass(TRANSITION_OUT_CLASS, TRANSITION_IN_CLASS)
); );
router.on('finish', () => router.on(
flipClass(TRANSITION_IN_CLASS, TRANSITION_OUT_CLASS) 'finish',
(event) =>
canTransition(currentLocation, event.detail.visit.url) &&
flipClass(TRANSITION_IN_CLASS, TRANSITION_OUT_CLASS)
); );
}, []); }, []);

View File

@@ -7,13 +7,15 @@ import {
Text, Text,
} from '@mantine/core'; } from '@mantine/core';
import { useDisclosure } from '@mantine/hooks'; import { useDisclosure } from '@mantine/hooks';
import { useEffect } from 'react';
import DashboardProviders from '~/components/dashboard/dashboard_provider'; import DashboardProviders from '~/components/dashboard/dashboard_provider';
import LinkItem from '~/components/dashboard/link/link_item'; import LinkItem from '~/components/dashboard/link/link_item';
import { MantineFooter } from '~/components/footer/mantine_footer'; import { MantineFooter } from '~/components/footer/mantine_footer';
import useShortcut from '~/hooks/use_shortcut';
import { DashboardAside } from '~/mantine/components/dashboard/dashboard_aside';
import { DashboardNavbar } from '~/mantine/components/dashboard/dashboard_navbar'; import { DashboardNavbar } from '~/mantine/components/dashboard/dashboard_navbar';
import { MantineDashboardLayout } from '~/mantine/layouts/mantine_dashboard_layout'; import { MantineDashboardLayout } from '~/mantine/layouts/mantine_dashboard_layout';
import { CollectionWithLinks } from '~/types/app'; import { CollectionWithLinks } from '~/types/app';
import '../styles/body_overflow_hidden.css';
import classes from './dashboard.module.css'; import classes from './dashboard.module.css';
interface DashboardPageProps { interface DashboardPageProps {
@@ -22,15 +24,29 @@ interface DashboardPageProps {
} }
export default function MantineDashboard(props: Readonly<DashboardPageProps>) { export default function MantineDashboard(props: Readonly<DashboardPageProps>) {
const [openedNavbar, { toggle: toggleNavbar }] = useDisclosure(); const [openedNavbar, { toggle: toggleNavbar, close: closeNavbar }] =
const [openedAside, { toggle: toggleAside }] = useDisclosure(); useDisclosure();
const [openedAside, { toggle: toggleAside, close: closeAside }] =
useDisclosure();
useShortcut('ESCAPE_KEY', () => {
closeNavbar();
closeAside();
});
useEffect(() => {
document.body.style.overflow = 'hidden';
return () => {
document.body.style.overflow = 'auto';
};
}, []);
return ( return (
<MantineDashboardLayout> <MantineDashboardLayout>
<DashboardProviders {...props}> <DashboardProviders {...props}>
<AppShell <AppShell
layout="alt" layout="alt"
header={{ height: 60 }} header={{ height: 50 }}
navbar={{ navbar={{
width: 300, width: 300,
breakpoint: 'sm', breakpoint: 'sm',
@@ -57,7 +73,7 @@ export default function MantineDashboard(props: Readonly<DashboardPageProps>) {
hiddenFrom="sm" hiddenFrom="sm"
size="sm" size="sm"
/> />
{props.activeCollection.name} <Text lineClamp={1}>{props.activeCollection.name}</Text>
</Group> </Group>
<Burger <Burger
opened={openedAside} opened={openedAside}
@@ -80,17 +96,7 @@ export default function MantineDashboard(props: Readonly<DashboardPageProps>) {
</Stack> </Stack>
</ScrollArea> </ScrollArea>
</AppShell.Main> </AppShell.Main>
<AppShell.Aside p="md"> <DashboardAside isOpen={openedAside} toggle={toggleAside} />
<Group justify="space-between">
<Text>Aside</Text>
<Burger
opened={openedAside}
onClick={toggleAside}
hiddenFrom="md"
size="md"
/>
</Group>
</AppShell.Aside>
<AppShell.Footer pl="xs" pr="xs"> <AppShell.Footer pl="xs" pr="xs">
<MantineFooter /> <MantineFooter />
</AppShell.Footer> </AppShell.Footer>

View File

@@ -1,3 +0,0 @@
body {
overflow: hidden;
}