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

Commit f090d4e

Browse files
committed
enable ssg for pages
1 parent 5019574 commit f090d4e

File tree

109 files changed

+2547
-1813
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

109 files changed

+2547
-1813
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
"@material-ui/lab": "^4.0.0-alpha.52",
3535
"algoliasearch": "^4.0.3",
3636
"diff": "^4.0.2",
37-
"firebase": "^7.15.1",
37+
"firebase": "^7.15.2",
3838
"is-hotkey": "^0.1.6",
3939
"lodash": "^4.17.15",
4040
"mitt": "^2.0.1",

src/components/CategoryFilter.tsx

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

src/components/CommentCard.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import CommentActions from './CommentActions';
77
import CommentForm from './CommentForm';
88
import CommentUser from './CommentUser';
99
import ReplyList from './ReplyList';
10-
import EditorRead from './rich-text/EditorRead';
10+
import RichTextViewer from './rich-text/RichTextViewer';
1111

1212
interface CommentCardProps {
1313
data: Comment.Get;
@@ -36,7 +36,7 @@ const CommentCard = ({ data }: CommentCardProps) => {
3636
>
3737
<CommentUser user={createdBy} />
3838
<div className={classes.content}>
39-
<EditorRead content={content} />
39+
<RichTextViewer content={content} />
4040
</div>
4141
<CommentActions
4242
data={data}

src/components/DiscussionList.tsx

Lines changed: 19 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,24 @@
1-
import { Fragment, useEffect } from 'react';
2-
import { Button, Grid } from '@material-ui/core';
1+
import { Fragment, useState } from 'react';
2+
import dynamic from 'next/dynamic';
3+
import { Grid } from '@material-ui/core';
34
import { Comment } from '@zoonk/models';
4-
import { listComments } from '@zoonk/services';
5-
import { theme } from '@zoonk/utils';
65
import DiscussionListItem from './DiscussionListItem';
7-
import ListSkeleton from './ListSkeleton';
86
import NoItems from './NoItems';
9-
import useLoadMore from './useLoadMore';
10-
import useTranslation from './useTranslation';
7+
8+
const DiscussionLoadMore = dynamic(() => import('./DiscussionLoadMore'), {
9+
ssr: false,
10+
});
1111

1212
interface DiscussionListProps {
13-
allowLoadMore?: boolean;
14-
createdById?: string;
13+
data: Comment.Get[];
1514
limit?: number;
15+
userId?: string;
1616
}
1717

18-
const DiscussionList = ({
19-
allowLoadMore,
20-
createdById,
21-
limit = 10,
22-
}: DiscussionListProps) => {
23-
const translate = useTranslation();
24-
const { get, items, lastVisible, loading } = useLoadMore<Comment.Snapshot>(
25-
limit,
26-
);
27-
28-
const loadMore = () => {
29-
get({ data: listComments(lastVisible, createdById, limit) });
30-
};
18+
const DiscussionList = ({ data, limit = 10, userId }: DiscussionListProps) => {
19+
const [items, setItems] = useState<Comment.Get[]>(data);
3120

32-
useEffect(() => {
33-
get({ data: listComments(undefined, createdById, limit) });
34-
}, [get, createdById, limit]);
35-
36-
if (items.length === 0 && loading === false) {
37-
return <NoItems />;
38-
}
21+
if (items.length === 0) return <NoItems />;
3922

4023
return (
4124
<Fragment>
@@ -47,19 +30,13 @@ const DiscussionList = ({
4730
))}
4831
</Grid>
4932

50-
{loading && <ListSkeleton items={limit} />}
51-
52-
{allowLoadMore && lastVisible && (
53-
<Button
54-
fullWidth
55-
variant="contained"
56-
color="primary"
57-
onClick={loadMore}
58-
style={{ margin: theme.spacing(3, 0, 2) }}
59-
>
60-
{translate('load_more')}
61-
</Button>
62-
)}
33+
<DiscussionLoadMore
34+
lastItem={items[items.length - 1].id}
35+
length={items.length}
36+
limit={limit}
37+
userId={userId}
38+
onLoadMore={(res) => setItems([...items, ...res])}
39+
/>
6340
</Fragment>
6441
);
6542
};

src/components/DiscussionListItem.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
Typography,
1212
} from '@material-ui/core';
1313
import { Comment } from '@zoonk/models';
14-
import EditorRead from './rich-text/EditorRead';
14+
import RichTextViewer from './rich-text/RichTextViewer';
1515
import useAuth from './useAuth';
1616
import useTranslation from './useTranslation';
1717

@@ -66,7 +66,7 @@ const DiscussionListItem = ({
6666
subheader={createdAt}
6767
/>
6868
<CardContent>
69-
<EditorRead content={content} />
69+
<RichTextViewer content={content} />
7070
</CardContent>
7171
<CardActions disableSpacing>
7272
<NextLink href={`/${link}/[id]`} as={`/${link}/${linkId}`} passHref>
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { Comment } from '@zoonk/models';
2+
import { getCommentsSnapshot } from '@zoonk/services';
3+
import LoadMore from './LoadMore';
4+
5+
interface DiscussionLoadMoreProps {
6+
lastItem: string | firebase.firestore.DocumentSnapshot;
7+
length: number;
8+
limit: number;
9+
userId?: string;
10+
onLoadMore: (posts: Comment.Get[]) => void;
11+
}
12+
13+
const DiscussionLoadMore = ({
14+
lastItem,
15+
length,
16+
limit,
17+
userId,
18+
onLoadMore,
19+
}: DiscussionLoadMoreProps) => {
20+
const lastPath =
21+
typeof lastItem === 'string' ? `comments/${lastItem}` : lastItem;
22+
23+
return (
24+
<LoadMore<Comment.Snapshot>
25+
lastPath={lastPath}
26+
length={length}
27+
limit={limit}
28+
onLoadMore={onLoadMore}
29+
request={(last) => getCommentsSnapshot(last, limit, userId)}
30+
/>
31+
);
32+
};
33+
34+
export default DiscussionLoadMore;

src/components/EditGet.tsx

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

src/components/EditsItem.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { useEffect, useState } from 'react';
2+
import dynamic from 'next/dynamic';
23
import NextLink from 'next/link';
34
import {
45
Button,
@@ -14,11 +15,12 @@ import { editableFields } from '@zoonk/utils';
1415
import { getFieldDiff } from '@zoonk/utils/diff';
1516
import EditsDiffBox from './EditsDiffBox';
1617
import EditsHeader from './EditsHeader';
17-
import EditsReport from './EditsReport';
18-
import EditsRevert from './EditsRevert';
1918
import { getPlainText } from './rich-text/posts';
2019
import useTranslation from './useTranslation';
2120

21+
const EditsReport = dynamic(() => import('./EditsReport'), { ssr: false });
22+
const EditsRevert = dynamic(() => import('./EditsRevert'), { ssr: false });
23+
2224
interface EditsItemProps {
2325
displayTitle?: boolean;
2426
edits: Activity.Get;

src/components/EditsList.tsx

Lines changed: 20 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,39 @@
1-
import { Fragment, useEffect } from 'react';
2-
import { Button } from '@material-ui/core';
1+
import { Fragment, useState } from 'react';
2+
import dynamic from 'next/dynamic';
33
import { Activity } from '@zoonk/models';
4-
import { listActivities } from '@zoonk/services';
5-
import { theme } from '@zoonk/utils';
64
import EditsItem from './EditsItem';
7-
import EditsSkeleton from './EditsSkeleton';
8-
import useLoadMore from './useLoadMore';
9-
import useTranslation from './useTranslation';
5+
import NoItems from './NoItems';
6+
7+
// Dynamically loading this component to reduce the first load size.
8+
const EditsLoadMore = dynamic(() => import('./EditsLoadMore'), {
9+
ssr: false,
10+
});
1011

1112
interface EditsListProps {
13+
data: Activity.Get[];
1214
displayTitle?: boolean;
1315
itemPath?: string;
14-
limit?: number;
16+
limit: number;
1517
}
1618

17-
const EditsList = ({ displayTitle, itemPath, limit = 10 }: EditsListProps) => {
18-
const translate = useTranslation();
19-
const { get, items, lastVisible, loading } = useLoadMore<Activity.Snapshot>(
20-
limit,
21-
);
22-
23-
const loadMore = () => {
24-
get({ data: listActivities(itemPath, lastVisible, limit) });
25-
};
19+
const EditsList = ({ data, displayTitle, itemPath, limit }: EditsListProps) => {
20+
const [items, setItems] = useState<Activity.Get[]>(data);
2621

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

3124
return (
3225
<Fragment>
3326
{items.map((item) => (
3427
<EditsItem displayTitle={displayTitle} edits={item} key={item.id} />
3528
))}
3629

37-
{loading && <EditsSkeleton />}
38-
39-
{lastVisible && (
40-
<Button
41-
fullWidth
42-
variant="contained"
43-
color="primary"
44-
onClick={loadMore}
45-
style={{ margin: theme.spacing(3, 0, 2) }}
46-
>
47-
{translate('load_more')}
48-
</Button>
49-
)}
30+
<EditsLoadMore
31+
itemPath={itemPath}
32+
lastItem={items[items.length - 1].id}
33+
length={items.length}
34+
limit={limit}
35+
onLoadMore={(res) => setItems([...items, ...res])}
36+
/>
5037
</Fragment>
5138
);
5239
};

0 commit comments

Comments
 (0)