Skip to content
This repository has been archived by the owner on Sep 30, 2024. It is now read-only.

Commit

Permalink
display breadcrumb on post edit page (closes #31)
Browse files Browse the repository at this point in the history
  • Loading branch information
ceolinwill committed Jun 27, 2020
1 parent de0530d commit becd8f0
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 35 deletions.
21 changes: 0 additions & 21 deletions src/components/BackButton.tsx

This file was deleted.

16 changes: 13 additions & 3 deletions src/components/PostEdit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import { CircularProgress, IconButton } from '@material-ui/core';
import { Delete } from '@material-ui/icons';
import { Post } from '@zoonk/models';
import { deletePost, getPost } from '@zoonk/services';
import BackButton from './BackButton';
import EditNotAllowed from './EditNotAllowed';
import LoginForm from './LoginForm';
import PostEditForm from './PostEditForm';
import PostsBreadcrumb from './PostsBreadcrumb';
import useAuth from './useAuth';
import useSnackbar from './useSnackbar';
import useTranslation from './useTranslation';
Expand Down Expand Up @@ -42,11 +42,12 @@ const PostEdit = ({ id }: PostEditProps) => {
if (data === undefined || user === undefined) return <CircularProgress />;
if (!canEdit) return <EditNotAllowed />;

const { chapterId, chapterData, groupId, groupData, title, topics } = data;

const handleDelete = () => {
if (profile && window.confirm(translate('post_delete_confirmation'))) {
snackbar('progress', translate('deleting'));

const { chapterId, topics } = data;
const linkPath = chapterId ? '/chapters/[id]' : '/topics/[id]';
const linkAs = chapterId
? `/chapters/${chapterId}`
Expand All @@ -70,7 +71,16 @@ const PostEdit = ({ id }: PostEditProps) => {
alignItems: 'center',
}}
>
<BackButton />
<PostsBreadcrumb
chapterId={chapterId}
chapterName={chapterData?.title}
groupId={groupId}
groupName={groupData?.title}
postId={id}
postTitle={title}
title={translate('edit')}
topicId={topics[0]}
/>
{canDelete && (
<IconButton
color="secondary"
Expand Down
6 changes: 6 additions & 0 deletions src/components/PostsBreadcrumb.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@ import { theme } from '@zoonk/utils';
import LinkChapter from './LinkChapter';
import LinkGroup from './LinkGroup';
import LinkHome from './LinkHome';
import LinkPost from './LinkPost';
import LinkTopic from './LinkTopic';

interface PostsBreadcrumbProps {
chapterId?: string | null;
chapterName?: string;
groupId?: string | null;
groupName?: string;
postId?: string;
postTitle?: string;
title?: string;
topicId?: string;
}
Expand All @@ -19,6 +22,8 @@ const PostsBreadcrumb = ({
chapterName,
groupId,
groupName,
postId,
postTitle,
title,
topicId,
}: PostsBreadcrumbProps) => {
Expand All @@ -29,6 +34,7 @@ const PostsBreadcrumb = ({
{topicId && <LinkTopic id={topicId} />}
{chapterId && <LinkChapter id={chapterId} title={chapterName} />}
{groupId && <LinkGroup id={groupId} title={groupName} />}
{postId && postTitle && <LinkPost id={postId} title={postTitle} />}
{title && <Typography color="textPrimary">{title}</Typography>}
</Breadcrumbs>
</Paper>
Expand Down
45 changes: 34 additions & 11 deletions src/pages/posts/[id]/edits.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import { GetStaticPaths, GetStaticProps, InferGetStaticPropsType } from 'next';
import Error from 'next/error';
import { useRouter } from 'next/router';
import { CircularProgress, Container } from '@material-ui/core';
import BackButton from '@zoonk/components/BackButton';
import EditsList from '@zoonk/components/EditsList';
import Meta from '@zoonk/components/Meta';
import PostsBreadcrumb from '@zoonk/components/PostsBreadcrumb';
import useTranslation from '@zoonk/components/useTranslation';
import { Activity } from '@zoonk/models';
import { getActivities } from '@zoonk/services';
import { Activity, Post } from '@zoonk/models';
import { getActivities, getPost } from '@zoonk/services';

const limit = 10;

interface PostEditsProps {
postId: string;
data: Activity.Get[];
edits: Activity.Get[];
post: Post.Get | null;
}

export const getStaticPaths: GetStaticPaths = async () => {
Expand All @@ -23,24 +24,46 @@ export const getStaticProps: GetStaticProps<PostEditsProps> = async ({
params,
}) => {
const postId = String(params?.id);
const data = await getActivities(limit, `posts/${postId}`);
return { props: { postId, data }, unstable_revalidate: 1 };
const editsReq = getActivities(limit, `posts/${postId}`);
const postReq = getPost(postId);
const [edits, post] = await Promise.all([editsReq, postReq]);
return { props: { edits, post }, unstable_revalidate: 1 };
};

const PostEdits = ({
postId,
data,
edits,
post,
}: InferGetStaticPropsType<typeof getStaticProps>) => {
const translate = useTranslation();
const { isFallback } = useRouter();

if (isFallback) return <CircularProgress />;
if (!post) return <Error statusCode={404} />;

const {
chapterId,
chapterData,
groupId,
groupData,
id,
title,
topics,
} = post;

return (
<Container component="main">
<Meta title={translate('page_edits')} noIndex />
<BackButton />
<EditsList data={data} itemPath={`posts/${postId}`} limit={limit} />
<PostsBreadcrumb
chapterId={chapterId}
chapterName={chapterData?.title}
groupId={groupId}
groupName={groupData?.title}
postId={id}
postTitle={title}
title={translate('page_edits')}
topicId={topics[0]}
/>
<EditsList data={edits} itemPath={`posts/${id}`} limit={limit} />
</Container>
);
};
Expand Down

1 comment on commit becd8f0

@vercel
Copy link

@vercel vercel bot commented on becd8f0 Jun 27, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.