mirror of
https://github.com/docmost/docmost.git
synced 2025-11-22 23:01:10 +10:00
add recent changes tab to home
This commit is contained in:
@ -1,9 +1,8 @@
|
||||
import { desktopAsideAtom, desktopSidebarAtom } from '@/components/navbar/atoms/sidebar-atom';
|
||||
import { useToggleSidebar } from '@/components/navbar/hooks/use-toggle-sidebar';
|
||||
import { Navbar } from '@/components/navbar/navbar';
|
||||
import { ActionIcon, UnstyledButton, ActionIconGroup, AppShell, Avatar, Burger, Group } from '@mantine/core';
|
||||
import { AppShell, Burger, Group } from '@mantine/core';
|
||||
import { useDisclosure } from '@mantine/hooks';
|
||||
import { IconDots } from '@tabler/icons-react';
|
||||
import { useAtom } from 'jotai';
|
||||
import classes from './shell.module.css';
|
||||
import Header from '@/components/layouts/header';
|
||||
|
||||
@ -37,7 +37,7 @@
|
||||
align-items: center;
|
||||
width: 100%;
|
||||
font-size: var(--mantine-font-size-sm);
|
||||
padding: rem(8px) var(--mantine-spacing-xs);
|
||||
padding: rem(4px) var(--mantine-spacing-xs);
|
||||
border-radius: var(--mantine-radius-sm);
|
||||
font-weight: 500;
|
||||
color: light-dark(var(--mantine-color-gray-7), var(--mantine-color-dark-0));
|
||||
|
||||
@ -12,6 +12,7 @@ import {
|
||||
IconPlus,
|
||||
IconSettings,
|
||||
IconFilePlus,
|
||||
IconHome
|
||||
} from '@tabler/icons-react';
|
||||
|
||||
import classes from './navbar.module.css';
|
||||
@ -23,6 +24,7 @@ import SettingsModal from '@/features/settings/modal/settings-modal';
|
||||
import { SearchSpotlight } from '@/features/search/search-spotlight';
|
||||
import { treeApiAtom } from '@/features/page/tree/atoms/tree-api-atom';
|
||||
import PageTree from '@/features/page/tree/page-tree';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
|
||||
interface PrimaryMenuItem {
|
||||
icon: React.ElementType;
|
||||
@ -31,16 +33,22 @@ interface PrimaryMenuItem {
|
||||
}
|
||||
|
||||
const primaryMenu: PrimaryMenuItem[] = [
|
||||
{ icon: IconHome, label: 'Home' },
|
||||
{ icon: IconSearch, label: 'Search' },
|
||||
{ icon: IconSettings, label: 'Settings' },
|
||||
{ icon: IconFilePlus, label: 'New Page' },
|
||||
// { icon: IconFilePlus, label: 'New Page' },
|
||||
];
|
||||
|
||||
export function Navbar() {
|
||||
const [, setSettingsModalOpen] = useAtom(settingsModalAtom);
|
||||
const [tree] = useAtom(treeApiAtom);
|
||||
const navigate = useNavigate();
|
||||
|
||||
const handleMenuItemClick = (label: string) => {
|
||||
if (label === 'Home') {
|
||||
navigate('/home');
|
||||
}
|
||||
|
||||
if (label === 'Search') {
|
||||
spotlight.open();
|
||||
}
|
||||
@ -62,9 +70,9 @@ export function Navbar() {
|
||||
>
|
||||
<div className={classes.menuItemInner}>
|
||||
<menuItem.icon
|
||||
size={20}
|
||||
size={18}
|
||||
className={classes.menuItemIcon}
|
||||
stroke={1.5}
|
||||
stroke={2}
|
||||
/>
|
||||
<span>{menuItem.label}</span>
|
||||
</div>
|
||||
|
||||
34
client/src/features/home/components/home-tabs.tsx
Normal file
34
client/src/features/home/components/home-tabs.tsx
Normal file
@ -0,0 +1,34 @@
|
||||
import { Text, Tabs, Space } from '@mantine/core';
|
||||
import {
|
||||
IconClockHour3, IconStar,
|
||||
} from '@tabler/icons-react';
|
||||
import RecentChanges from '@/features/home/components/recent-changes';
|
||||
|
||||
export default function HomeTabs() {
|
||||
|
||||
return (
|
||||
<Tabs defaultValue="recent">
|
||||
<Tabs.List>
|
||||
<Tabs.Tab value="recent" leftSection={<IconClockHour3 size={18} />}>
|
||||
<Text size="sm" fw={500}>Recent changes</Text>
|
||||
</Tabs.Tab>
|
||||
|
||||
<Tabs.Tab value="favorites" leftSection={<IconStar size={18} />}>
|
||||
<Text size="sm" fw={500}>Favorites</Text>
|
||||
</Tabs.Tab>
|
||||
</Tabs.List>
|
||||
|
||||
<Space my="md" />
|
||||
|
||||
<Tabs.Panel value="recent">
|
||||
|
||||
<RecentChanges />
|
||||
|
||||
</Tabs.Panel>
|
||||
|
||||
<Tabs.Panel value="favorites">
|
||||
My favorite pages
|
||||
</Tabs.Panel>
|
||||
</Tabs>
|
||||
);
|
||||
}
|
||||
10
client/src/features/home/components/home.module.css
Normal file
10
client/src/features/home/components/home.module.css
Normal file
@ -0,0 +1,10 @@
|
||||
.page {
|
||||
display: block;
|
||||
width: 100%;
|
||||
padding: var(--mantine-spacing-md);
|
||||
color: light-dark(var(--mantine-color-black), var(--mantine-color-dark-0));
|
||||
|
||||
@mixin hover {
|
||||
background-color: light-dark(var(--mantine-color-gray-1), var(--mantine-color-dark-8));
|
||||
}
|
||||
}
|
||||
21
client/src/features/home/components/page-list-skeleton.tsx
Normal file
21
client/src/features/home/components/page-list-skeleton.tsx
Normal file
@ -0,0 +1,21 @@
|
||||
import { Skeleton } from '@mantine/core';
|
||||
|
||||
export default function PageListSkeleton() {
|
||||
return (
|
||||
<>
|
||||
<Skeleton height={25} my="xs" radius="xs" />
|
||||
<Skeleton height={25} my="xs" radius="xs" />
|
||||
<Skeleton height={25} my="xs" radius="xs" />
|
||||
<Skeleton height={25} my="xs" radius="xs" />
|
||||
<Skeleton height={25} my="xs" radius="xs" />
|
||||
<Skeleton height={25} my="xs" radius="xs" />
|
||||
<Skeleton height={25} my="xs" radius="xs" />
|
||||
<Skeleton height={25} my="xs" radius="xs" />
|
||||
<Skeleton height={25} my="xs" radius="xs" />
|
||||
<Skeleton height={25} my="xs" radius="xs" />
|
||||
<Skeleton height={25} my="xs" radius="xs" />
|
||||
<Skeleton height={25} my="xs" radius="xs" />
|
||||
<Skeleton height={25} my="xs" radius="xs" />
|
||||
</>
|
||||
);
|
||||
}
|
||||
46
client/src/features/home/components/recent-changes.tsx
Normal file
46
client/src/features/home/components/recent-changes.tsx
Normal file
@ -0,0 +1,46 @@
|
||||
import { Text, Group, Stack, UnstyledButton, Divider } from '@mantine/core';
|
||||
import { format } from 'date-fns';
|
||||
import classes from './home.module.css';
|
||||
import { Link } from 'react-router-dom';
|
||||
import PageListSkeleton from '@/features/home/components/page-list-skeleton';
|
||||
import usePage from '@/features/page/hooks/use-page';
|
||||
|
||||
function RecentChanges() {
|
||||
const { recentPagesQuery } = usePage();
|
||||
const { data, isLoading, isError } = recentPagesQuery;
|
||||
|
||||
if (isLoading) {
|
||||
return <PageListSkeleton />;
|
||||
}
|
||||
|
||||
if (isError) {
|
||||
return <Text>Failed to fetch recent pages</Text>;
|
||||
}
|
||||
|
||||
return (
|
||||
<div>
|
||||
{data.map((page) => (
|
||||
<>
|
||||
<UnstyledButton component={Link} to={`/p/${page.id}`}
|
||||
className={classes.page} p="xs" key={page.id}>
|
||||
<Group wrap="noWrap">
|
||||
|
||||
<Stack gap="xs" style={{ flex: 1 }}>
|
||||
<Text fw={500} size="sm">
|
||||
{page.title || 'Untitled'}
|
||||
</Text>
|
||||
</Stack>
|
||||
|
||||
<Text c="dimmed" size="xs">
|
||||
{format(new Date(page.createdAt), 'PPP')}
|
||||
</Text>
|
||||
</Group>
|
||||
</UnstyledButton>
|
||||
<Divider />
|
||||
</>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default RecentChanges;
|
||||
@ -1,5 +1,5 @@
|
||||
import { useMutation, useQuery, UseQueryResult } from '@tanstack/react-query';
|
||||
import { createPage, deletePage, getPageById, updatePage } from '@/features/page/services/page-service';
|
||||
import { createPage, deletePage, getPageById, getRecentChanges, updatePage } from '@/features/page/services/page-service';
|
||||
import { IPage } from '@/features/page/types/page.types';
|
||||
|
||||
export default function usePage(pageId?: string) {
|
||||
@ -15,6 +15,11 @@ export default function usePage(pageId?: string) {
|
||||
},
|
||||
);
|
||||
|
||||
const recentPagesQuery: UseQueryResult<IPage[], unknown> = useQuery(
|
||||
['recentChanges'],
|
||||
() => getRecentChanges()
|
||||
);
|
||||
|
||||
const updateMutation = useMutation(
|
||||
(data: Partial<IPage>) => updatePage(data),
|
||||
);
|
||||
@ -24,8 +29,9 @@ export default function usePage(pageId?: string) {
|
||||
);
|
||||
|
||||
return {
|
||||
create: createMutation.mutate,
|
||||
pageQuery: pageQueryResult,
|
||||
recentPagesQuery: recentPagesQuery,
|
||||
create: createMutation.mutate,
|
||||
updatePageMutation: updateMutation.mutate,
|
||||
remove: removeMutation.mutate,
|
||||
};
|
||||
|
||||
@ -11,6 +11,11 @@ export async function getPageById(id: string): Promise<IPage> {
|
||||
return req.data as IPage;
|
||||
}
|
||||
|
||||
export async function getRecentChanges(): Promise<IPage[]> {
|
||||
const req = await api.post<IPage[]>('/pages/recent');
|
||||
return req.data as IPage[];
|
||||
}
|
||||
|
||||
export async function getPages(): Promise<IPage[]> {
|
||||
const req = await api.post<IPage[]>('/pages');
|
||||
return req.data as IPage[];
|
||||
|
||||
@ -1,12 +1,17 @@
|
||||
import { useAtom } from 'jotai';
|
||||
import { currentUserAtom } from '@/features/user/atoms/current-user-atom';
|
||||
import { Container } from '@mantine/core';
|
||||
import HomeTabs from '@/features/home/components/home-tabs';
|
||||
|
||||
// Hello {currentUser && currentUser.user.name}!
|
||||
export default function Home() {
|
||||
const [currentUser] = useAtom(currentUserAtom);
|
||||
|
||||
return (
|
||||
<>
|
||||
Hello {currentUser && currentUser.user.name}!
|
||||
</>
|
||||
<Container size={'800'} pt="xl">
|
||||
|
||||
<HomeTabs/>
|
||||
|
||||
</Container>
|
||||
);
|
||||
}
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
import { Title, Text } from '@mantine/core';
|
||||
import { Title, Text, Stack } from '@mantine/core';
|
||||
import { ThemeToggle } from '@/components/theme-toggle';
|
||||
|
||||
export function Welcome() {
|
||||
return (
|
||||
<>
|
||||
<Stack>
|
||||
<Title ta="center" mt={100}>
|
||||
<Text
|
||||
inherit
|
||||
@ -18,6 +18,6 @@ export function Welcome() {
|
||||
Welcome to something new and interesting.
|
||||
</Text>
|
||||
<ThemeToggle />
|
||||
</>
|
||||
</Stack>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user