Skip to content

Commit

Permalink
[optimize] update index.tsx getStaticProps ISR
Browse files Browse the repository at this point in the history
  • Loading branch information
wangrunlin committed Aug 5, 2023
1 parent 34ef4f6 commit 640eb19
Show file tree
Hide file tree
Showing 3 changed files with 1,071 additions and 1,107 deletions.
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,21 @@
"dependencies": {
"classnames": "^2.3.2",
"file-type": "^18.5.0",
"idea-react": "^1.0.0-beta.1",
"idea-react": "1.0.0-rc.10",
"koajax": "^0.8.4",
"lodash": "^4.17.21",
"mobx": "^5.15.7",
"mobx-i18n": "^0.3.14",
"mobx-lark": "^1.0.0-beta.6",
"mobx-i18n": "^0.3.15",
"mobx-lark": "1.0.0-rc.2",
"mobx-react": "^6.3.1",
"mobx-restful": "^0.6.5",
"mobx-restful-table": "^1.0.2",
"mobx-restful-table": "^1.0.4",
"next": "^12.3.4",
"react": "^17.0.2",
"react-bootstrap": "^2.7.4",
"react-dom": "^17.0.2",
"web-utility": "^4.0.0",
"webpack": "^5.85.1"
"web-utility": "^4.1.0",
"webpack": "^5.88.2"
},
"devDependencies": {
"@octokit/openapi-types": "^17.2.0",
Expand Down
52 changes: 26 additions & 26 deletions pages/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { observer } from 'mobx-react';
import { InferGetServerSidePropsType } from 'next';
import { InferGetStaticPropsType } from 'next';
import { FC } from 'react';
import { Button, Card, Col, Container, Image, Row } from 'react-bootstrap';

Expand All @@ -15,36 +15,35 @@ import { ProjectModel } from '../models/Project';
import { RepositoryModel } from '../models/Repository';
import { i18n } from '../models/Translation';
import styles from '../styles/Home.module.less';
import { getTarget, withErrorLog, withTranslation } from './api/core';
import { getTarget } from './api/core';
import { service } from './api/home';

export const getServerSideProps = withErrorLog(
withTranslation(async () => {
const [projects, repositories, partners, members] = await Promise.all([
new ProjectModel().getList({}, 1, 9),
new RepositoryModel().getList(),
new ClientModel().getList({ partnership: '战略合作' }),
new MemberModel().getList({ type: '全职' }),
]);
export const getStaticProps = async () => {
const [projects, repositories, partners, members] = await Promise.all([
new ProjectModel().getList({}, 1, 9),
new RepositoryModel().getList(),
new ClientModel().getList({ partnership: '战略合作' }),
new MemberModel().getList({ type: '全职' }),
]);

return {
props: {
projects,
repositories,
partners,
members: [...members].sort(
({ joinedAt: a }, { joinedAt: b }) =>
+new Date(a as number) - +new Date(b as number),
),
},
};
}),
);
return {
props: {
projects,
repositories,
partners,
members: [...members].sort(
({ joinedAt: a }, { joinedAt: b }) =>
+new Date(a as number) - +new Date(b as number),
),
},
revalidate: 60,
};
};

const { t } = i18n;

const HomePage: FC<InferGetServerSidePropsType<typeof getServerSideProps>> =
observer(({ projects, repositories, partners, members }) => (
const HomePage: FC<InferGetStaticPropsType<typeof getStaticProps>> = observer(
({ projects, repositories, partners, members }) => (
<>
<PageHead />

Expand Down Expand Up @@ -106,6 +105,7 @@ const HomePage: FC<InferGetServerSidePropsType<typeof getServerSideProps>> =
</Section>
</Container>
</>
));
),
);

export default HomePage;
Loading

0 comments on commit 640eb19

Please sign in to comment.