Skip to content
This repository was archived by the owner on Jan 30, 2025. It is now read-only.

Commit becd8f0

Browse files
committed
display breadcrumb on post edit page (closes #31)
1 parent de0530d commit becd8f0

File tree

4 files changed

+53
-35
lines changed

4 files changed

+53
-35
lines changed

src/components/BackButton.tsx

Lines changed: 0 additions & 21 deletions
This file was deleted.

src/components/PostEdit.tsx

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ import { CircularProgress, IconButton } from '@material-ui/core';
55
import { Delete } from '@material-ui/icons';
66
import { Post } from '@zoonk/models';
77
import { deletePost, getPost } from '@zoonk/services';
8-
import BackButton from './BackButton';
98
import EditNotAllowed from './EditNotAllowed';
109
import LoginForm from './LoginForm';
1110
import PostEditForm from './PostEditForm';
11+
import PostsBreadcrumb from './PostsBreadcrumb';
1212
import useAuth from './useAuth';
1313
import useSnackbar from './useSnackbar';
1414
import useTranslation from './useTranslation';
@@ -42,11 +42,12 @@ const PostEdit = ({ id }: PostEditProps) => {
4242
if (data === undefined || user === undefined) return <CircularProgress />;
4343
if (!canEdit) return <EditNotAllowed />;
4444

45+
const { chapterId, chapterData, groupId, groupData, title, topics } = data;
46+
4547
const handleDelete = () => {
4648
if (profile && window.confirm(translate('post_delete_confirmation'))) {
4749
snackbar('progress', translate('deleting'));
4850

49-
const { chapterId, topics } = data;
5051
const linkPath = chapterId ? '/chapters/[id]' : '/topics/[id]';
5152
const linkAs = chapterId
5253
? `/chapters/${chapterId}`
@@ -70,7 +71,16 @@ const PostEdit = ({ id }: PostEditProps) => {
7071
alignItems: 'center',
7172
}}
7273
>
73-
<BackButton />
74+
<PostsBreadcrumb
75+
chapterId={chapterId}
76+
chapterName={chapterData?.title}
77+
groupId={groupId}
78+
groupName={groupData?.title}
79+
postId={id}
80+
postTitle={title}
81+
title={translate('edit')}
82+
topicId={topics[0]}
83+
/>
7484
{canDelete && (
7585
<IconButton
7686
color="secondary"

src/components/PostsBreadcrumb.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,16 @@ import { theme } from '@zoonk/utils';
33
import LinkChapter from './LinkChapter';
44
import LinkGroup from './LinkGroup';
55
import LinkHome from './LinkHome';
6+
import LinkPost from './LinkPost';
67
import LinkTopic from './LinkTopic';
78

89
interface PostsBreadcrumbProps {
910
chapterId?: string | null;
1011
chapterName?: string;
1112
groupId?: string | null;
1213
groupName?: string;
14+
postId?: string;
15+
postTitle?: string;
1316
title?: string;
1417
topicId?: string;
1518
}
@@ -19,6 +22,8 @@ const PostsBreadcrumb = ({
1922
chapterName,
2023
groupId,
2124
groupName,
25+
postId,
26+
postTitle,
2227
title,
2328
topicId,
2429
}: PostsBreadcrumbProps) => {
@@ -29,6 +34,7 @@ const PostsBreadcrumb = ({
2934
{topicId && <LinkTopic id={topicId} />}
3035
{chapterId && <LinkChapter id={chapterId} title={chapterName} />}
3136
{groupId && <LinkGroup id={groupId} title={groupName} />}
37+
{postId && postTitle && <LinkPost id={postId} title={postTitle} />}
3238
{title && <Typography color="textPrimary">{title}</Typography>}
3339
</Breadcrumbs>
3440
</Paper>

src/pages/posts/[id]/edits.tsx

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
import { GetStaticPaths, GetStaticProps, InferGetStaticPropsType } from 'next';
2+
import Error from 'next/error';
23
import { useRouter } from 'next/router';
34
import { CircularProgress, Container } from '@material-ui/core';
4-
import BackButton from '@zoonk/components/BackButton';
55
import EditsList from '@zoonk/components/EditsList';
66
import Meta from '@zoonk/components/Meta';
7+
import PostsBreadcrumb from '@zoonk/components/PostsBreadcrumb';
78
import useTranslation from '@zoonk/components/useTranslation';
8-
import { Activity } from '@zoonk/models';
9-
import { getActivities } from '@zoonk/services';
9+
import { Activity, Post } from '@zoonk/models';
10+
import { getActivities, getPost } from '@zoonk/services';
1011

1112
const limit = 10;
1213

1314
interface PostEditsProps {
14-
postId: string;
15-
data: Activity.Get[];
15+
edits: Activity.Get[];
16+
post: Post.Get | null;
1617
}
1718

1819
export const getStaticPaths: GetStaticPaths = async () => {
@@ -23,24 +24,46 @@ export const getStaticProps: GetStaticProps<PostEditsProps> = async ({
2324
params,
2425
}) => {
2526
const postId = String(params?.id);
26-
const data = await getActivities(limit, `posts/${postId}`);
27-
return { props: { postId, data }, unstable_revalidate: 1 };
27+
const editsReq = getActivities(limit, `posts/${postId}`);
28+
const postReq = getPost(postId);
29+
const [edits, post] = await Promise.all([editsReq, postReq]);
30+
return { props: { edits, post }, unstable_revalidate: 1 };
2831
};
2932

3033
const PostEdits = ({
31-
postId,
32-
data,
34+
edits,
35+
post,
3336
}: InferGetStaticPropsType<typeof getStaticProps>) => {
3437
const translate = useTranslation();
3538
const { isFallback } = useRouter();
3639

3740
if (isFallback) return <CircularProgress />;
41+
if (!post) return <Error statusCode={404} />;
42+
43+
const {
44+
chapterId,
45+
chapterData,
46+
groupId,
47+
groupData,
48+
id,
49+
title,
50+
topics,
51+
} = post;
3852

3953
return (
4054
<Container component="main">
4155
<Meta title={translate('page_edits')} noIndex />
42-
<BackButton />
43-
<EditsList data={data} itemPath={`posts/${postId}`} limit={limit} />
56+
<PostsBreadcrumb
57+
chapterId={chapterId}
58+
chapterName={chapterData?.title}
59+
groupId={groupId}
60+
groupName={groupData?.title}
61+
postId={id}
62+
postTitle={title}
63+
title={translate('page_edits')}
64+
topicId={topics[0]}
65+
/>
66+
<EditsList data={edits} itemPath={`posts/${id}`} limit={limit} />
4467
</Container>
4568
);
4669
};

0 commit comments

Comments
 (0)