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

Commit

Permalink
enable ssg for pages
Browse files Browse the repository at this point in the history
  • Loading branch information
wceolin committed Jun 20, 2020
1 parent 5019574 commit f090d4e
Show file tree
Hide file tree
Showing 109 changed files with 2,547 additions and 1,813 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"@material-ui/lab": "^4.0.0-alpha.52",
"algoliasearch": "^4.0.3",
"diff": "^4.0.2",
"firebase": "^7.15.1",
"firebase": "^7.15.2",
"is-hotkey": "^0.1.6",
"lodash": "^4.17.15",
"mitt": "^2.0.1",
Expand Down
95 changes: 0 additions & 95 deletions src/components/CategoryFilter.tsx

This file was deleted.

4 changes: 2 additions & 2 deletions src/components/CommentCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import CommentActions from './CommentActions';
import CommentForm from './CommentForm';
import CommentUser from './CommentUser';
import ReplyList from './ReplyList';
import EditorRead from './rich-text/EditorRead';
import RichTextViewer from './rich-text/RichTextViewer';

interface CommentCardProps {
data: Comment.Get;
Expand Down Expand Up @@ -36,7 +36,7 @@ const CommentCard = ({ data }: CommentCardProps) => {
>
<CommentUser user={createdBy} />
<div className={classes.content}>
<EditorRead content={content} />
<RichTextViewer content={content} />
</div>
<CommentActions
data={data}
Expand Down
61 changes: 19 additions & 42 deletions src/components/DiscussionList.tsx
Original file line number Diff line number Diff line change
@@ -1,41 +1,24 @@
import { Fragment, useEffect } from 'react';
import { Button, Grid } from '@material-ui/core';
import { Fragment, useState } from 'react';
import dynamic from 'next/dynamic';
import { Grid } from '@material-ui/core';
import { Comment } from '@zoonk/models';
import { listComments } from '@zoonk/services';
import { theme } from '@zoonk/utils';
import DiscussionListItem from './DiscussionListItem';
import ListSkeleton from './ListSkeleton';
import NoItems from './NoItems';
import useLoadMore from './useLoadMore';
import useTranslation from './useTranslation';

const DiscussionLoadMore = dynamic(() => import('./DiscussionLoadMore'), {
ssr: false,
});

interface DiscussionListProps {
allowLoadMore?: boolean;
createdById?: string;
data: Comment.Get[];
limit?: number;
userId?: string;
}

const DiscussionList = ({
allowLoadMore,
createdById,
limit = 10,
}: DiscussionListProps) => {
const translate = useTranslation();
const { get, items, lastVisible, loading } = useLoadMore<Comment.Snapshot>(
limit,
);

const loadMore = () => {
get({ data: listComments(lastVisible, createdById, limit) });
};
const DiscussionList = ({ data, limit = 10, userId }: DiscussionListProps) => {
const [items, setItems] = useState<Comment.Get[]>(data);

useEffect(() => {
get({ data: listComments(undefined, createdById, limit) });
}, [get, createdById, limit]);

if (items.length === 0 && loading === false) {
return <NoItems />;
}
if (items.length === 0) return <NoItems />;

return (
<Fragment>
Expand All @@ -47,19 +30,13 @@ const DiscussionList = ({
))}
</Grid>

{loading && <ListSkeleton items={limit} />}

{allowLoadMore && lastVisible && (
<Button
fullWidth
variant="contained"
color="primary"
onClick={loadMore}
style={{ margin: theme.spacing(3, 0, 2) }}
>
{translate('load_more')}
</Button>
)}
<DiscussionLoadMore
lastItem={items[items.length - 1].id}
length={items.length}
limit={limit}
userId={userId}
onLoadMore={(res) => setItems([...items, ...res])}
/>
</Fragment>
);
};
Expand Down
4 changes: 2 additions & 2 deletions src/components/DiscussionListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
Typography,
} from '@material-ui/core';
import { Comment } from '@zoonk/models';
import EditorRead from './rich-text/EditorRead';
import RichTextViewer from './rich-text/RichTextViewer';
import useAuth from './useAuth';
import useTranslation from './useTranslation';

Expand Down Expand Up @@ -66,7 +66,7 @@ const DiscussionListItem = ({
subheader={createdAt}
/>
<CardContent>
<EditorRead content={content} />
<RichTextViewer content={content} />
</CardContent>
<CardActions disableSpacing>
<NextLink href={`/${link}/[id]`} as={`/${link}/${linkId}`} passHref>
Expand Down
34 changes: 34 additions & 0 deletions src/components/DiscussionLoadMore.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { Comment } from '@zoonk/models';
import { getCommentsSnapshot } from '@zoonk/services';
import LoadMore from './LoadMore';

interface DiscussionLoadMoreProps {
lastItem: string | firebase.firestore.DocumentSnapshot;
length: number;
limit: number;
userId?: string;
onLoadMore: (posts: Comment.Get[]) => void;
}

const DiscussionLoadMore = ({
lastItem,
length,
limit,
userId,
onLoadMore,
}: DiscussionLoadMoreProps) => {
const lastPath =
typeof lastItem === 'string' ? `comments/${lastItem}` : lastItem;

return (
<LoadMore<Comment.Snapshot>
lastPath={lastPath}
length={length}
limit={limit}
onLoadMore={onLoadMore}
request={(last) => getCommentsSnapshot(last, limit, userId)}
/>
);
};

export default DiscussionLoadMore;
25 changes: 0 additions & 25 deletions src/components/EditGet.tsx

This file was deleted.

6 changes: 4 additions & 2 deletions src/components/EditsItem.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useEffect, useState } from 'react';
import dynamic from 'next/dynamic';
import NextLink from 'next/link';
import {
Button,
Expand All @@ -14,11 +15,12 @@ import { editableFields } from '@zoonk/utils';
import { getFieldDiff } from '@zoonk/utils/diff';
import EditsDiffBox from './EditsDiffBox';
import EditsHeader from './EditsHeader';
import EditsReport from './EditsReport';
import EditsRevert from './EditsRevert';
import { getPlainText } from './rich-text/posts';
import useTranslation from './useTranslation';

const EditsReport = dynamic(() => import('./EditsReport'), { ssr: false });
const EditsRevert = dynamic(() => import('./EditsRevert'), { ssr: false });

interface EditsItemProps {
displayTitle?: boolean;
edits: Activity.Get;
Expand Down
53 changes: 20 additions & 33 deletions src/components/EditsList.tsx
Original file line number Diff line number Diff line change
@@ -1,52 +1,39 @@
import { Fragment, useEffect } from 'react';
import { Button } from '@material-ui/core';
import { Fragment, useState } from 'react';
import dynamic from 'next/dynamic';
import { Activity } from '@zoonk/models';
import { listActivities } from '@zoonk/services';
import { theme } from '@zoonk/utils';
import EditsItem from './EditsItem';
import EditsSkeleton from './EditsSkeleton';
import useLoadMore from './useLoadMore';
import useTranslation from './useTranslation';
import NoItems from './NoItems';

// Dynamically loading this component to reduce the first load size.
const EditsLoadMore = dynamic(() => import('./EditsLoadMore'), {
ssr: false,
});

interface EditsListProps {
data: Activity.Get[];
displayTitle?: boolean;
itemPath?: string;
limit?: number;
limit: number;
}

const EditsList = ({ displayTitle, itemPath, limit = 10 }: EditsListProps) => {
const translate = useTranslation();
const { get, items, lastVisible, loading } = useLoadMore<Activity.Snapshot>(
limit,
);

const loadMore = () => {
get({ data: listActivities(itemPath, lastVisible, limit) });
};
const EditsList = ({ data, displayTitle, itemPath, limit }: EditsListProps) => {
const [items, setItems] = useState<Activity.Get[]>(data);

useEffect(() => {
get({ data: listActivities(itemPath, undefined, limit), replace: true });
}, [get, itemPath, limit]);
if (items.length === 0) return <NoItems />;

return (
<Fragment>
{items.map((item) => (
<EditsItem displayTitle={displayTitle} edits={item} key={item.id} />
))}

{loading && <EditsSkeleton />}

{lastVisible && (
<Button
fullWidth
variant="contained"
color="primary"
onClick={loadMore}
style={{ margin: theme.spacing(3, 0, 2) }}
>
{translate('load_more')}
</Button>
)}
<EditsLoadMore
itemPath={itemPath}
lastItem={items[items.length - 1].id}
length={items.length}
limit={limit}
onLoadMore={(res) => setItems([...items, ...res])}
/>
</Fragment>
);
};
Expand Down
Loading

1 comment on commit f090d4e

@vercel
Copy link

@vercel vercel bot commented on f090d4e Jun 20, 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.