diff --git a/.env b/.env index f38bb1b..1a130bc 100644 --- a/.env +++ b/.env @@ -1,4 +1,4 @@ -NEXT_PUBLIC_SITE_NAME=open-disaster-rescue +NEXT_PUBLIC_SITE_NAME=开放救灾系统 NEXT_PUBLIC_SITE_SUMMARY=Lark project scaffold based on TypeScript, React, Next.js, Bootstrap & Workbox. NEXT_PUBLIC_SENTRY_DSN = @@ -6,3 +6,5 @@ SENTRY_ORG = SENTRY_PROJECT = LARK_API_HOST = https://open.larksuite.com/open-apis/ +NEXT_PUBLIC_BASE_ID = Gc4WbVtmWajgZzssqeAcZw25n7S +NEXT_PUBLIC_DISASTER_TABLE_ID = tblxpQ9wlidYAJ4f diff --git a/README.md b/README.md index 48a8932..a65dd33 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# open-disaster-rescue +# Open Disaster Rescue [Lark][0] project scaffold based on [TypeScript][2], [React][1], [Next.js][3], [Bootstrap][4] & [Workbox][5]. And this project bootstrapped with [`create-next-app`][6]. diff --git a/models/Disaster.ts b/models/Disaster.ts new file mode 100644 index 0000000..0c9a66a --- /dev/null +++ b/models/Disaster.ts @@ -0,0 +1,28 @@ +import { BiDataQueryOptions, BiDataTable, TableCellValue } from 'mobx-lark'; + +import { larkClient } from './Base'; + +export type Disaster = Record< + | 'id' + | 'name' + | 'englishName' + | 'type' + | `${'start' | 'end'}edAt` + | 'originLocation' + | 'coordinate' + | 'impactScope', + TableCellValue +>; + +export const BASE_ID = process.env.NEXT_PUBLIC_BASE_ID!, + DISASTER_TABLE_ID = process.env.NEXT_PUBLIC_DISASTER_TABLE_ID!; + +export class DisasterModel extends BiDataTable() { + client = larkClient; + + queryOptions: BiDataQueryOptions = { text_field_as_array: false }; + + constructor(appId = BASE_ID, tableId = DISASTER_TABLE_ID) { + super(appId, tableId); + } +} diff --git a/pages/index.tsx b/pages/index.tsx index 2b958ca..b295771 100644 --- a/pages/index.tsx +++ b/pages/index.tsx @@ -1,48 +1,56 @@ import { observer } from 'mobx-react'; -import { compose, translator } from 'next-ssr-middleware'; -import { Card, Col, Container, Row } from 'react-bootstrap'; +import { cache, compose, errorLogger, translator } from 'next-ssr-middleware'; +import { FC } from 'react'; +import { Badge, Card, Col, Container, Row } from 'react-bootstrap'; +import { formatDate } from 'web-utility'; import { GitCard } from '../components/Git/Card'; import { PageHead } from '../components/Layout/PageHead'; +import { Disaster, DisasterModel } from '../models/Disaster'; import { i18n, t } from '../models/Translation'; import styles from '../styles/Home.module.less'; -import { framework, mainNav } from './api/home'; +import { framework } from './api/home'; -export const getServerSideProps = compose(translator(i18n)); +interface HomePageProps { + disasters: Disaster[]; +} -const HomePage = observer(() => ( +export const getServerSideProps = compose( + cache(), + errorLogger, + translator(i18n), + async () => { + const disasters = await new DisasterModel().getList({}, 1, 3); + + return { props: { disasters } }; + }, +); + +const HomePage: FC = observer(({ disasters }) => (

- {t('welcome_to')} - - Next.js! - + {t('open_disaster_rescue')}

-

- {t('get_started_by_editing')} - - pages/index.tsx - -

- - - {mainNav().map(({ link, title, summary }) => ( - - +

{t('disaster_rescue_history')}

+ + {disasters.map(({ id, name, type, startedAt, endedAt }) => ( + + - - {title} → + {type + ''} + + {name + ''} - {summary} + + {formatDate(+startedAt!, 'YYYY-MM-DD')} ~{' '} + {formatDate(+endedAt!, 'YYYY-MM-DD')} + ))} diff --git a/public/manifest.json b/public/manifest.json index d5060a3..d08dc98 100644 --- a/public/manifest.json +++ b/public/manifest.json @@ -1,12 +1,12 @@ { - "name": "open-disaster-rescue scaffold", - "short_name": "Next.ts demo", + "name": "开放救灾系统", + "short_name": "开放救灾", "start_url": ".", "description": "Lark project scaffold based on TypeScript, React, Next.js, Bootstrap & Workbox.", "scope": "/", "display": "standalone", "orientation": "any", - "lang": "en-US", + "lang": "zh-CN", "dir": "ltr", "theme_color": "rgba(0,0,0,0.5)", "background_color": "transparent", diff --git a/translation/en-US.ts b/translation/en-US.ts index 2d682c8..4e97126 100644 --- a/translation/en-US.ts +++ b/translation/en-US.ts @@ -1,6 +1,9 @@ import { IDType } from 'mobx-restful'; export default { + open_disaster_rescue: 'Open Disaster Rescue', + disaster_rescue_history: 'Disaster Rescue History', + welcome_to: 'Welcome to', get_started_by_editing: 'Get started by editing', upstream_projects: 'Upstream projects', diff --git a/translation/zh-CN.ts b/translation/zh-CN.ts index 65a5698..e48cf9f 100644 --- a/translation/zh-CN.ts +++ b/translation/zh-CN.ts @@ -1,6 +1,9 @@ import { IDType } from 'mobx-restful'; export default { + open_disaster_rescue: '开放救灾系统', + disaster_rescue_history: '救灾历史', + welcome_to: '欢迎使用', get_started_by_editing: '开始你的项目吧,编辑', upstream_projects: '上游项目', diff --git a/translation/zh-TW.ts b/translation/zh-TW.ts index 1eca7cd..f773285 100644 --- a/translation/zh-TW.ts +++ b/translation/zh-TW.ts @@ -1,6 +1,9 @@ import { IDType } from 'mobx-restful'; export default { + open_disaster_rescue: '開放救災系統', + disaster_rescue_history: '救災歷史', + welcome_to: '歡迎使用', get_started_by_editing: '開始你的專案吧,編輯', upstream_projects: '上游專案',