Skip to content

Commit

Permalink
[migrate] replace Scaffold Built-in middleware with Next SSR middlewa…
Browse files Browse the repository at this point in the history
…re (#191)
  • Loading branch information
wangrunlin authored Aug 13, 2023
1 parent 63de96a commit 0853bb4
Show file tree
Hide file tree
Showing 25 changed files with 1,110 additions and 1,095 deletions.
29 changes: 15 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@
},
"dependencies": {
"@authing/native-js-ui-components": "^3.1.31",
"@fortawesome/fontawesome-svg-core": "^6.4.0",
"@fortawesome/free-brands-svg-icons": "^6.4.0",
"@fortawesome/free-regular-svg-icons": "^6.4.0",
"@fortawesome/free-solid-svg-icons": "^6.4.0",
"@fortawesome/fontawesome-svg-core": "^6.4.2",
"@fortawesome/free-brands-svg-icons": "^6.4.2",
"@fortawesome/free-regular-svg-icons": "^6.4.2",
"@fortawesome/free-solid-svg-icons": "^6.4.2",
"@fortawesome/react-fontawesome": "^0.2.0",
"@giscus/react": "^2.3.0",
"array-unique-proposal": "^0.3.4",
"classnames": "^2.3.2",
"echarts-jsx": "^0.5.0",
"idea-react": "^1.0.0-rc.5",
"idea-react": "1.0.0-rc.10",
"koajax": "^0.8.4",
"leaflet": "^1.9.4",
"leaflet.chinatmsproviders": "^3.0.6",
Expand All @@ -34,33 +34,34 @@
"mobx-restful": "^0.6.5",
"mobx-restful-table": "^1.0.4",
"next": "^12.3.4",
"next-ssr-middleware": "^0.5.0",
"react": "^17.0.2",
"react-bootstrap": "^2.8.0",
"react-bootstrap-editor": "^1.0.1",
"react-dom": "^17.0.2",
"react-leaflet": "^3.2.5",
"web-utility": "^4.0.0"
"web-utility": "^4.1.0"
},
"devDependencies": {
"@babel/core": "^7.22.8",
"@babel/core": "^7.22.10",
"@octokit/openapi-types": "^18.0.0",
"@types/leaflet": "^1.9.3",
"@types/lodash": "^4.14.195",
"@types/node": "^18.16.19",
"@types/react": "^17.0.62",
"eslint": "^8.44.0",
"@types/lodash": "^4.14.197",
"@types/node": "^18.17.5",
"@types/react": "^17.0.64",
"eslint": "^8.46.0",
"eslint-config-next": "^12.3.4",
"eslint-plugin-simple-import-sort": "^10.0.0",
"husky": "^8.0.3",
"less": "^4.1.3",
"less": "^4.2.0",
"less-loader": "^11.1.3",
"lint-staged": "^13.2.3",
"next-pwa": "^5.6.0",
"next-with-less": "^2.0.5",
"prettier": "^3.0.0",
"prettier": "^3.0.1",
"ts-node": "^10.9.1",
"typescript": "~5.1.6",
"webpack": "^5.88.1"
"webpack": "^5.88.2"
},
"prettier": {
"singleQuote": true,
Expand Down
11 changes: 7 additions & 4 deletions pages/activity/[name]/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { observer } from 'mobx-react';
import { ScrollList } from 'mobx-restful-table';
import { InferGetServerSidePropsType } from 'next';
import dynamic from 'next/dynamic';
import { cache, compose, errorLogger, translator } from 'next-ssr-middleware';
import { PureComponent } from 'react';
import {
Button,
Expand Down Expand Up @@ -43,22 +44,24 @@ import { Organization } from '../../../models/Organization';
import sessionStore from '../../../models/Session';
import { i18n } from '../../../models/Translation';
import { convertDatetime } from '../../../utils/time';
import { withErrorLog, withTranslation } from '../../api/core';

const { t } = i18n;

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

export const getServerSideProps = withErrorLog<
export const getServerSideProps = compose<
{ name?: string },
{
activity: Activity;
organizationList: Organization[];
}
>(
withTranslation(async ({ params: { name = '' } = {} }) => {
cache(),
errorLogger,
translator(i18n),
async ({ params: { name = '' } = {} }) => {
const activityStore = new ActivityModel();

const [activity, organizationList] = await Promise.all([
Expand All @@ -67,7 +70,7 @@ export const getServerSideProps = withErrorLog<
]);

return { props: { activity, organizationList } };
}),
},
);

const StatusName: () => Record<Enrollment['status'], string> = () => ({
Expand Down
7 changes: 5 additions & 2 deletions pages/activity/[name]/manage/administrator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { observable } from 'mobx';
import { observer } from 'mobx-react';
import { ScrollList } from 'mobx-restful-table';
import { InferGetServerSidePropsType } from 'next';
import { compose, RouteProps, router } from 'next-ssr-middleware';
import { FormEvent, PureComponent } from 'react';
import { Badge, Button, Col, Form, ListGroup, Row } from 'react-bootstrap';

Expand All @@ -12,9 +13,11 @@ import { AdministratorModal } from '../../../../components/User/ActivityAdminist
import { HackathonAdminList } from '../../../../components/User/HackathonAdminList';
import activityStore from '../../../../models/Activity';
import { i18n } from '../../../../models/Translation';
import { withRoute } from '../../../api/core';

export const getServerSideProps = withRoute<{ name: string }>();
export const getServerSideProps = compose<
{ name: string },
RouteProps<{ name: string }>
>(router);

const { t } = i18n;

Expand Down
7 changes: 5 additions & 2 deletions pages/activity/[name]/manage/award.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { observer } from 'mobx-react';
import { NewData } from 'mobx-restful';
import { InferGetServerSidePropsType } from 'next';
import { compose, RouteProps, router } from 'next-ssr-middleware';
import { FormEvent, PureComponent } from 'react';
import { Button, Col, Form, Row } from 'react-bootstrap';
import { formToJSON } from 'web-utility';
Expand All @@ -13,9 +14,11 @@ import {
import activityStore from '../../../../models/Activity';
import { Award } from '../../../../models/Award';
import { i18n } from '../../../../models/Translation';
import { withRoute } from '../../../api/core';

export const getServerSideProps = withRoute<{ name: string }>();
export const getServerSideProps = compose<
{ name: string },
RouteProps<{ name: string }>
>(router);

const { t } = i18n;

Expand Down
7 changes: 5 additions & 2 deletions pages/activity/[name]/manage/edit.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import { InferGetServerSidePropsType } from 'next';
import { compose, RouteProps, router } from 'next-ssr-middleware';

import { ActivityEditor } from '../../../../components/Activity/ActivityEditor';
import { ActivityManageFrame } from '../../../../components/Activity/ActivityManageFrame';
import { i18n } from '../../../../models/Translation';
import { withRoute } from '../../../api/core';

const { t } = i18n;

export const getServerSideProps = withRoute<{ name: string }>();
export const getServerSideProps = compose<
{ name: string },
RouteProps<{ name: string }>
>(router);

const ActivityEditPage = ({
route: { resolvedUrl, params },
Expand Down
9 changes: 6 additions & 3 deletions pages/activity/[name]/manage/evaluation.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
import { observer } from 'mobx-react';
import { NewData } from 'mobx-restful';
import { InferGetServerSidePropsType } from 'next';
import { compose, RouteProps, router } from 'next-ssr-middleware';
import { FormEvent, PureComponent } from 'react';
import { Button, Col, Form, InputGroup, Row } from 'react-bootstrap';
import { formToJSON } from 'web-utility';

import { ActivityManageFrame } from '../../../../components/Activity/ActivityManageFrame';
import { TeamAwardList } from '../../../../components/Team/TeamAwardList';
import activityStore from '../../../../models/Activity';
import { Award, AwardAssignment } from '../../../../models/Award';
import { AwardAssignment } from '../../../../models/Award';
import { i18n } from '../../../../models/Translation';
import { withRoute } from '../../../api/core';

const { t } = i18n;

export const getServerSideProps = withRoute<{ name: string }>();
export const getServerSideProps = compose<
{ name: string },
RouteProps<{ name: string }>
>(router);

@observer
class EvaluationPage extends PureComponent<
Expand Down
7 changes: 5 additions & 2 deletions pages/activity/[name]/manage/git.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { observable } from 'mobx';
import { observer } from 'mobx-react';
import { ScrollList } from 'mobx-restful-table';
import { InferGetServerSidePropsType } from 'next';
import { compose, RouteProps, router } from 'next-ssr-middleware';
import { FormEvent, PureComponent } from 'react';
import { Button, Container, Form } from 'react-bootstrap';

Expand All @@ -12,11 +13,13 @@ import { CardList } from '../../../../components/Git/CardList';
import { GitModal } from '../../../../components/Git/Modal';
import activityStore from '../../../../models/Activity';
import { i18n } from '../../../../models/Translation';
import { withRoute } from '../../../api/core';

const { t } = i18n;

export const getServerSideProps = withRoute<{ name: string }>();
export const getServerSideProps = compose<
{ name: string },
RouteProps<{ name: string }>
>(router);

@observer
export default class ActivityManageGitPage extends PureComponent<
Expand Down
7 changes: 5 additions & 2 deletions pages/activity/[name]/manage/log.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
import { observer } from 'mobx-react';
import { ScrollList } from 'mobx-restful-table';
import { InferGetServerSidePropsType } from 'next';
import { compose, RouteProps, router } from 'next-ssr-middleware';
import { PureComponent } from 'react';

import { ActivityLogListLayout } from '../../../../components/Activity/ActivityLogList';
import { ActivityManageFrame } from '../../../../components/Activity/ActivityManageFrame';
import activityStore from '../../../../models/Activity';
import { i18n } from '../../../../models/Translation';
import { withRoute } from '../../../api/core';

export const getServerSideProps = withRoute<{ name: string }>();
export const getServerSideProps = compose<
{ name: string },
RouteProps<{ name: string }>
>(router);

const { t } = i18n;

Expand Down
7 changes: 5 additions & 2 deletions pages/activity/[name]/manage/message.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { observable } from 'mobx';
import { observer } from 'mobx-react';
import { InferGetServerSidePropsType } from 'next';
import { compose, RouteProps, router } from 'next-ssr-middleware';
import { createRef, FormEvent, PureComponent } from 'react';
import { Button, Container, Form } from 'react-bootstrap';

Expand All @@ -11,11 +12,13 @@ import { MessageList } from '../../../../components/Message/MessageList';
import { MessageModal } from '../../../../components/Message/MessageModal';
import activityStore from '../../../../models/Activity';
import { i18n } from '../../../../models/Translation';
import { withRoute } from '../../../api/core';

const { t } = i18n;

export const getServerSideProps = withRoute<{ name: string }>();
export const getServerSideProps = compose<
{ name: string },
RouteProps<{ name: string }>
>(router);

@observer
export default class MessageListPage extends PureComponent<
Expand Down
7 changes: 5 additions & 2 deletions pages/activity/[name]/manage/organization.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { observable } from 'mobx';
import { observer } from 'mobx-react';
import { ScrollList } from 'mobx-restful-table';
import { InferGetServerSidePropsType } from 'next';
import { compose, RouteProps, router } from 'next-ssr-middleware';
import { FormEvent, PureComponent } from 'react';
import { Badge, Button, Col, Form, ListGroup, Row } from 'react-bootstrap';

Expand All @@ -12,9 +13,11 @@ import { OrganizationModal } from '../../../../components/Organization/ActivityO
import { OrganizationTableLayout } from '../../../../components/Organization/OrganizationList';
import activityStore from '../../../../models/Activity';
import { i18n } from '../../../../models/Translation';
import { withRoute } from '../../../api/core';

export const getServerSideProps = withRoute<{ name: string }>();
export const getServerSideProps = compose<
{ name: string },
RouteProps<{ name: string }>
>(router);

const { t } = i18n;

Expand Down
7 changes: 5 additions & 2 deletions pages/activity/[name]/manage/participant/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { observable } from 'mobx';
import { observer } from 'mobx-react';
import { InferGetServerSidePropsType } from 'next';
import { compose, RouteProps, router } from 'next-ssr-middleware';
import { PureComponent } from 'react';
import { Button, Modal } from 'react-bootstrap';

Expand All @@ -9,9 +10,11 @@ import { EnrollmentList } from '../../../../../components/Activity/EnrollmentLis
import activityStore from '../../../../../models/Activity';
import { Enrollment } from '../../../../../models/Enrollment';
import { i18n } from '../../../../../models/Translation';
import { withRoute } from '../../../../api/core';

export const getServerSideProps = withRoute<{ name: string }>();
export const getServerSideProps = compose<
{ name: string },
RouteProps<{ name: string }>
>(router);

const { t } = i18n;

Expand Down
7 changes: 5 additions & 2 deletions pages/activity/[name]/manage/participant/statistic.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import { Loading } from 'idea-react';
import { observer } from 'mobx-react';
import { InferGetServerSidePropsType } from 'next';
import dynamic from 'next/dynamic';
import { compose, RouteProps, router } from 'next-ssr-middleware';
import { PureComponent } from 'react';
import { Button } from 'react-bootstrap';

import { ActivityManageFrame } from '../../../../../components/Activity/ActivityManageFrame';
import activityStore from '../../../../../models/Activity';
import { i18n } from '../../../../../models/Translation';
import { withRoute } from '../../../../api/core';

const { t } = i18n;

Expand All @@ -17,7 +17,10 @@ const EnrollmentStatisticCharts = dynamic(
{ ssr: false },
);

export const getServerSideProps = withRoute<{ name: string }>();
export const getServerSideProps = compose<
{ name: string },
RouteProps<{ name: string }>
>(router);

@observer
export default class EnrollmentStatisticPage extends PureComponent<
Expand Down
7 changes: 5 additions & 2 deletions pages/activity/[name]/manage/questionnaire.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { observable } from 'mobx';
import { observer } from 'mobx-react';
import { InferGetServerSidePropsType } from 'next';
import { compose, RouteProps, router } from 'next-ssr-middleware';
import { PureComponent } from 'react';
import { Button, Col, Row } from 'react-bootstrap';

Expand All @@ -12,11 +13,13 @@ import activityStore from '../../../../models/Activity';
import { isServer } from '../../../../models/Base';
import { Extensions, Question } from '../../../../models/Question';
import { i18n } from '../../../../models/Translation';
import { withRoute } from '../../../api/core';

const { t } = i18n;

export const getServerSideProps = withRoute<{ name: string }>();
export const getServerSideProps = compose<
{ name: string },
RouteProps<{ name: string }>
>(router);

@observer
class ActivityQuestionnairePage extends PureComponent<
Expand Down
7 changes: 5 additions & 2 deletions pages/activity/[name]/manage/team.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { observer } from 'mobx-react';
import { ScrollList } from 'mobx-restful-table';
import { InferGetServerSidePropsType } from 'next';
import { compose, RouteProps, router } from 'next-ssr-middleware';
import { FormEvent, PureComponent } from 'react';
import {
Button,
Expand All @@ -15,9 +16,11 @@ import { ActivityManageFrame } from '../../../../components/Activity/ActivityMan
import { TeamListLayout } from '../../../../components/Team/TeamList';
import activityStore from '../../../../models/Activity';
import { i18n } from '../../../../models/Translation';
import { withRoute } from '../../../api/core';

export const getServerSideProps = withRoute<{ name: string }>();
export const getServerSideProps = compose<
{ name: string },
RouteProps<{ name: string }>
>(router);

const { t } = i18n;

Expand Down
Loading

1 comment on commit 0853bb4

@github-actions
Copy link

Choose a reason for hiding this comment

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

Deploy preview for open-hackathon ready!

✅ Preview
https://open-hackathon-43ur3213m-techquery.vercel.app

Built with commit 0853bb4.
This pull request is being automatically deployed with vercel-action

Please sign in to comment.