From 8331d6936ed998440cd6642ed7a2e5145c44c229 Mon Sep 17 00:00:00 2001 From: TechQuery Date: Wed, 9 Jul 2025 05:35:05 +0800 Subject: [PATCH] [refactor] make Next.js i18n smoother with MobX-i18n 0.7 [refactor] rewrite Lark back-end API with Koa middlewares [optimize] use TS for ESLint configuration [optimize] upgrade Upstream packages [remove] useless Example files --- components/Git/Card.tsx | 88 +- components/LarkImage.tsx | 3 +- components/Layout/NotFoundCard.tsx | 12 +- components/Layout/PageHead.tsx | 7 +- components/Navigator/LanguageMenu.tsx | 10 +- components/Navigator/MainNavigator.tsx | 61 +- components/Navigator/SearchBar.tsx | 40 +- eslint.config.mjs => eslint.config.ts | 0 models/Base.ts | 34 +- models/Translation.ts | 65 +- models/configuration.ts | 23 + package.json | 99 +- pages/_app.tsx | 122 +- pages/_document.tsx | 78 +- pages/_error.tsx | 55 +- pages/api/Lark/bitable/v1/[...slug].ts | 41 +- pages/api/Lark/core.ts | 45 +- pages/api/Lark/file/[id].ts | 49 - pages/api/Lark/file/[id]/[name].ts | 52 + pages/api/core.ts | 71 +- pages/api/home.ts | 76 - pages/index.tsx | 5 +- pages/pagination.tsx | 75 - pages/scroll-list.tsx | 78 +- pages/search/[model]/index.tsx | 11 +- pnpm-lock.yaml | 5388 ++++++++++++++---------- 26 files changed, 3678 insertions(+), 2910 deletions(-) rename eslint.config.mjs => eslint.config.ts (100%) create mode 100644 models/configuration.ts delete mode 100644 pages/api/Lark/file/[id].ts create mode 100644 pages/api/Lark/file/[id]/[name].ts delete mode 100644 pages/api/home.ts delete mode 100644 pages/pagination.tsx diff --git a/components/Git/Card.tsx b/components/Git/Card.tsx index 9425c3878..53470db6c 100644 --- a/components/Git/Card.tsx +++ b/components/Git/Card.tsx @@ -1,10 +1,10 @@ import { text2color } from 'idea-react'; import { GitRepository } from 'mobx-github'; import { observer } from 'mobx-react'; -import { FC } from 'react'; +import { FC, useContext } from 'react'; import { Badge, Button, Card, CardProps, Col, Row } from 'react-bootstrap'; -import { t } from '../../models/Translation'; +import { I18nContext } from '../../models/Translation'; import { GitLogo } from './Logo'; export interface GitCardProps @@ -24,45 +24,49 @@ export const GitCard: FC = observer( description, homepage, ...props - }) => ( - - - - - {full_name} - - + }) => { + const { t } = useContext(I18nContext); - - - {languages.map(language => ( - - - - ))} - - {description} - - - {homepage && ( - - )} - - - ), + return ( + + + + + {full_name} + + + + + + {languages.map(language => ( + + + + ))} + + {description} + + + {homepage && ( + + )} + + + ); + }, ); diff --git a/components/LarkImage.tsx b/components/LarkImage.tsx index 6f0f91b22..e0cfbac06 100644 --- a/components/LarkImage.tsx +++ b/components/LarkImage.tsx @@ -2,7 +2,8 @@ import { TableCellValue } from 'mobx-lark'; import { FC } from 'react'; import { Image, ImageProps } from 'react-bootstrap'; -import { DefaultImage, fileURLOf } from '../pages/api/Lark/file/[id]'; +import { fileURLOf } from '../models/Base'; +import { DefaultImage } from '../models/configuration'; export interface LarkImageProps extends Omit { src?: TableCellValue; diff --git a/components/Layout/NotFoundCard.tsx b/components/Layout/NotFoundCard.tsx index 5ce190698..41a6a731c 100644 --- a/components/Layout/NotFoundCard.tsx +++ b/components/Layout/NotFoundCard.tsx @@ -1,10 +1,13 @@ +import { observer } from 'mobx-react'; import { ErrorProps } from 'next/error'; -import { FC } from 'react'; +import { FC, useContext } from 'react'; -import { i18n } from '../../models/Translation'; +import { I18nContext } from '../../models/Translation'; -export const NotFoundCard: FC = ({ title }) => - i18n.currentLanguage.startsWith('zh') ? ( +export const NotFoundCard: FC = observer(({ title }) => { + const { currentLanguage } = useContext(I18nContext); + + return currentLanguage.startsWith('zh') ? (