1- import { GetServerSideProps , InferGetServerSidePropsType } from 'next' ;
1+ import { NextPage } from 'next' ;
22import Error from 'next/error' ;
33import { Container } from '@material-ui/core' ;
44import GroupBase from '@zoonk/components/GroupBase' ;
@@ -9,7 +9,7 @@ import PostShare from '@zoonk/components/PostShare';
99import PostsList from '@zoonk/components/PostsList' ;
1010import { Group , Post } from '@zoonk/models' ;
1111import { getGroup , getPosts } from '@zoonk/services' ;
12- import { appLanguage } from '@zoonk/utils' ;
12+ import { appLanguage , preRender } from '@zoonk/utils' ;
1313
1414interface GroupPageProps {
1515 group : Group . Get | null ;
@@ -18,20 +18,7 @@ interface GroupPageProps {
1818
1919const limit = 10 ;
2020
21- export const getServerSideProps : GetServerSideProps < GroupPageProps > = async ( {
22- params,
23- } ) => {
24- const groupId = String ( params ?. id ) ;
25- const groupReq = getGroup ( groupId ) ;
26- const postsReq = getPosts ( { groupId, limit } ) ;
27- const [ group , posts ] = await Promise . all ( [ groupReq , postsReq ] ) ;
28- return { props : { group, posts } } ;
29- } ;
30-
31- const GroupPage = ( {
32- group,
33- posts,
34- } : InferGetServerSidePropsType < typeof getServerSideProps > ) => {
21+ const GroupPage : NextPage < GroupPageProps > = ( { group, posts } ) => {
3522 if ( ! group ) return < Error statusCode = { 404 } /> ;
3623
3724 const { description, id, language, photo, title, topics } = group ;
@@ -56,4 +43,13 @@ const GroupPage = ({
5643 ) ;
5744} ;
5845
46+ GroupPage . getInitialProps = async ( { query } ) => {
47+ const groupId = String ( query . id ) ;
48+ const groupReq = getGroup ( groupId ) ;
49+ const postsReq = getPosts ( { groupId, limit } ) ;
50+ const [ group , posts ] = await Promise . all ( [ groupReq , postsReq ] ) ;
51+ preRender ( ) ;
52+ return { group, posts } ;
53+ } ;
54+
5955export default GroupPage ;
0 commit comments