Skip to content

Commit 96e9c9b

Browse files
committed
[fix] many GitHub copilot bugs
1 parent 0ce9f38 commit 96e9c9b

File tree

14 files changed

+65
-63
lines changed

14 files changed

+65
-63
lines changed

.gitignore

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,7 @@ yarn-debug.log*
3535
yarn-error.log*
3636

3737
# local env files
38-
.env.local
39-
.env.development.local
40-
.env.test.local
41-
.env.production.local
38+
.env*local
4239

4340
# vercel
4441
.vercel

components/Git/Issue/Card.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export const IssueCard: FC<IssueCardProps> = ({
4848
)}
4949
</div>
5050

51-
<article dangerouslySetInnerHTML={{ __html: marked(body || '', { async: false }) as string }} />
51+
<article dangerouslySetInnerHTML={{ __html: marked(body || '', { async: false }) }} />
5252

5353
<footer className="flex items-center justify-between">
5454
{user && (

components/Member/Card.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export const MemberCard: FC<MemberCardProps> = observer(
5959
</ul>
6060

6161
<p
62-
dangerouslySetInnerHTML={{ __html: marked((summary as string) || '', { async: false }) as string }}
62+
dangerouslySetInnerHTML={{ __html: marked((summary as string) || '', { async: false }) }}
6363
className="text-neutral-500"
6464
/>
6565
</li>

components/User/SessionBox.tsx

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1+
import { User } from '@idea2app/data-server';
12
import { Drawer, List, ListItem, ListItemButton, ListItemText } from '@mui/material';
2-
import { JwtPayload } from 'jsonwebtoken';
33
import { observable } from 'mobx';
44
import { observer } from 'mobx-react';
55
import Link from 'next/link';
6+
import { JWTProps } from 'next-ssr-middleware';
67
import { Component, HTMLAttributes, JSX } from 'react';
78

89
import { PageHead } from '../PageHead';
910
import { SessionForm } from './SessionForm';
1011

1112
export type MenuItem = Pick<JSX.IntrinsicElements['a'], 'href' | 'title'>;
1213

13-
export interface SessionBoxProps extends HTMLAttributes<HTMLDivElement> {
14+
export interface SessionBoxProps extends HTMLAttributes<HTMLDivElement>, JWTProps<User> {
1415
path?: string;
1516
menu?: MenuItem[];
16-
jwtPayload?: JwtPayload;
1717
}
1818

1919
@observer
@@ -33,7 +33,7 @@ export class SessionBox extends Component<SessionBoxProps> {
3333
<div>
3434
<List
3535
component="nav"
36-
className="flex-col px-3 sticky-top"
36+
className="sticky-top flex-col px-3"
3737
style={{ top: '5rem', minWidth: '200px' }}
3838
>
3939
{menu.map(({ href, title }) => (
@@ -53,17 +53,14 @@ export class SessionBox extends Component<SessionBoxProps> {
5353
<main className="flex-1 pb-3">
5454
<PageHead title={title} />
5555

56-
<h1 className="text-3xl font-bold mb-4">{title}</h1>
56+
<h1 className="mb-4 text-3xl font-bold">{title}</h1>
5757

5858
{children}
5959

6060
<Drawer
6161
anchor="right"
62+
slotProps={{ paper: { className: 'p-4', style: { width: '400px' } } }}
6263
open={this.modalShown}
63-
PaperProps={{
64-
className: 'p-4',
65-
style: { width: '400px' },
66-
}}
6764
onClose={() => (this.modalShown = false)}
6865
>
6966
<SessionForm onSignIn={() => window.location.reload()} />
@@ -72,4 +69,4 @@ export class SessionBox extends Component<SessionBoxProps> {
7269
</div>
7370
);
7471
}
75-
}
72+
}

components/User/SessionForm.tsx

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { PhoneSignInData } from '@idea2app/data-server';
12
import { Button, IconButton, InputAdornment, Tab, Tabs, TextField } from '@mui/material';
23
import { observable } from 'mobx';
34
import { observer } from 'mobx-react';
@@ -10,12 +11,7 @@ import userStore from '../../models/User';
1011
import { SymbolIcon } from '../Icon';
1112

1213
export interface SessionFormProps {
13-
onSignIn?: (data?: SignInData) => any;
14-
}
15-
16-
export interface SignInData {
17-
phone: string;
18-
password: string;
14+
onSignIn?: (data?: PhoneSignInData) => any;
1915
}
2016

2117
@observer
@@ -32,11 +28,11 @@ export class SessionForm extends ObservedComponent<SessionFormProps, typeof i18n
3228
const { t } = this.observedContext;
3329

3430
if (this.signType === 'up') {
35-
const { phone } = formToJSON<SignInData>(event.currentTarget.form!);
31+
const { mobilePhone } = formToJSON<PhoneSignInData>(event.currentTarget.form!);
3632

37-
if (!phone) throw new Error(t('phone_required_for_webauthn'));
33+
if (!mobilePhone) throw new Error(t('phone_required_for_webauthn'));
3834

39-
await userStore.signUpWebAuthn(phone);
35+
await userStore.signUpWebAuthn(mobilePhone);
4036
} else {
4137
await userStore.signInWebAuthn();
4238
}
@@ -48,18 +44,18 @@ export class SessionForm extends ObservedComponent<SessionFormProps, typeof i18n
4844
event.stopPropagation();
4945

5046
const { t } = this.observedContext;
51-
const { phone, password } = formToJSON<SignInData>(event.currentTarget);
47+
const { mobilePhone, password } = formToJSON<PhoneSignInData>(event.currentTarget);
5248

5349
if (this.signType === 'up') {
54-
await userStore.signUp(phone, password);
50+
await userStore.signUp(mobilePhone, password);
5551

5652
this.signType = 'in';
5753

5854
alert(t('registration_success_please_login'));
5955
} else {
60-
await userStore.signIn(phone, password);
56+
await userStore.signIn(mobilePhone, password);
6157

62-
this.props.onSignIn?.({ phone, password });
58+
this.props.onSignIn?.({ mobilePhone, password });
6359
}
6460
};
6561

@@ -82,7 +78,7 @@ export class SessionForm extends ObservedComponent<SessionFormProps, typeof i18n
8278
</Tabs>
8379

8480
<TextField
85-
name="phone"
81+
name="mobilePhone"
8682
type="tel"
8783
required
8884
fullWidth

models/Base.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1+
import { Base, ListChunk } from '@idea2app/data-server';
12
import { HTTPClient } from 'koajax';
23
import MIME from 'mime';
34
import { githubClient } from 'mobx-github';
45
import { TableCellValue, TableCellMedia, TableCellAttachment } from 'mobx-lark';
5-
import { Filter, ListModel, toggle, IDType, DataObject } from 'mobx-restful';
6-
import type { PageData } from 'mobx-restful';
6+
import { Filter, ListModel, toggle, IDType } from 'mobx-restful';
77
import { buildURLData } from 'web-utility';
88

9-
import { API_Host, GITHUB_TOKEN, isServer } from './configuration';
9+
import { Own_API_Host, GITHUB_TOKEN, isServer } from './configuration';
1010

11-
if (!isServer()) githubClient.baseURI = `${API_Host}/api/GitHub/`;
11+
if (!isServer()) githubClient.baseURI = `${Own_API_Host}/api/GitHub/`;
1212

1313
githubClient.use(({ request }, next) => {
1414
if (GITHUB_TOKEN)
@@ -22,7 +22,7 @@ githubClient.use(({ request }, next) => {
2222
export { githubClient };
2323

2424
export const larkClient = new HTTPClient({
25-
baseURI: `${API_Host}/api/Lark/`,
25+
baseURI: `${Own_API_Host}/api/Lark/`,
2626
responseType: 'json',
2727
});
2828

@@ -38,7 +38,7 @@ export function fileURLOf(field: TableCellValue, cache = false) {
3838
return URI;
3939
}
4040

41-
export abstract class TableModel<D extends DataObject, F extends Filter<D> = Filter<D>> extends ListModel<
41+
export abstract class TableModel<D extends Base, F extends Filter<D> = Filter<D>> extends ListModel<
4242
D,
4343
F
4444
> {
@@ -52,7 +52,7 @@ export abstract class TableModel<D extends DataObject, F extends Filter<D> = Fil
5252
}
5353

5454
async loadPage(pageIndex: number, pageSize: number, filter: F) {
55-
const { body } = await this.client.get<{ list: D[], count: number }>(
55+
const { body } = await this.client.get<ListChunk<D>>(
5656
`${this.baseURI}?${buildURLData({ ...filter, pageIndex, pageSize })}`,
5757
);
5858

models/User.ts

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,12 @@
1+
import { User, WebAuthnChallenge } from '@idea2app/data-server';
12
import { clear } from 'idb-keyval';
23
import { HTTPClient } from 'koajax';
34
import { observable, reaction } from 'mobx';
45
import { persist, restore, toggle } from 'mobx-restful';
56
import { setCookie } from 'web-utility';
6-
import { User as GitHubUser } from 'mobx-github';
77

88
import { TableModel } from './Base';
9-
import { API_Host, isServer } from './configuration';
10-
11-
export interface User extends GitHubUser {
12-
token?: string;
13-
}
14-
15-
export interface WebAuthnChallenge {
16-
string: string;
17-
}
9+
import { API_HOST, isServer } from './configuration';
1810

1911
export class UserModel extends TableModel<User> {
2012
baseURI = 'user';
@@ -29,8 +21,8 @@ export class UserModel extends TableModel<User> {
2921
);
3022
restored = !isServer() && restore(this, 'User');
3123

32-
client = new HTTPClient({ baseURI: API_Host, responseType: 'json' }).use(({ request }, next) => {
33-
const isSameDomain = API_Host.startsWith(new URL(request.path, API_Host).origin);
24+
client = new HTTPClient({ baseURI: API_HOST, responseType: 'json' }).use(({ request }, next) => {
25+
const isSameDomain = API_HOST.startsWith(new URL(request.path, API_HOST).origin);
3426

3527
if (isSameDomain && this.session)
3628
request.headers = {

models/configuration.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,20 @@ export const isServer = () => typeof window === 'undefined';
77

88
export const { VERCEL, VERCEL_URL, JWT_SECRET, GITHUB_TOKEN, CACHE_REPOSITORY } = process.env;
99

10-
export const API_Host = isServer()
10+
export const Own_API_Host = isServer()
1111
? VERCEL_URL
1212
? `https://${VERCEL_URL}`
1313
: 'http://localhost:3000'
1414
: globalThis.location.origin;
1515

16+
export const API_HOST = process.env.NEXT_PUBLIC_API_HOST!;
17+
1618
export const CACHE_HOST = process.env.NEXT_PUBLIC_CACHE_HOST!,
1719
CrawlerEmail = `[email protected]`;
1820

1921
export const ProxyBaseURL = `https://idea2.app/proxy`;
2022

21-
export const LARK_API_HOST = `${API_Host}/api/Lark/`;
23+
export const LARK_API_HOST = `${Own_API_Host}/api/Lark/`;
2224

2325
export const LarkAppMeta = {
2426
id: process.env.LARK_APP_ID!,

next.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ const nextConfig = withPWA({
4545
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
4646
return config;
4747
},
48-
rewrites: rewrites as any,
48+
rewrites,
4949
});
5050

5151
export default isDev || !SENTRY_AUTH_TOKEN

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
"@emotion/server": "^11.11.0",
1313
"@emotion/styled": "^11.14.1",
1414
"@giscus/react": "^3.1.0",
15-
"@idea2app/data-server": "^1.0.0-rc.0",
1615
"@koa/bodyparser": "^6.0.0",
1716
"@koa/router": "^14.0.0",
1817
"@mui/lab": "^7.0.0-beta.16",
@@ -51,6 +50,7 @@
5150
"@cspell/eslint-plugin": "^9.2.0",
5251
"@eslint/compat": "^1.3.2",
5352
"@eslint/js": "^9.34.0",
53+
"@idea2app/data-server": "^1.0.0-rc.0",
5454
"@next/eslint-plugin-next": "^15.5.2",
5555
"@stylistic/eslint-plugin": "^5.2.3",
5656
"@tailwindcss/postcss": "^4.1.12",
@@ -82,6 +82,7 @@
8282
"typescript-eslint": "^8.41.0"
8383
},
8484
"resolutions": {
85+
"mobx-github": "$mobx-github",
8586
"next": "$next"
8687
},
8788
"pnpm": {
@@ -107,6 +108,7 @@
107108
"*.{html,md,less,json,yml,js,mjs,ts,tsx}": "prettier --write"
108109
},
109110
"scripts": {
111+
"e": "pnpx dotenv-cli -e .env.personal.local -- pnpm",
110112
"prepare": "husky || true",
111113
"install": "xgit download https://github.com/idea2app/key-vault main idea2app.github.io || true",
112114
"dev": "next dev",

0 commit comments

Comments
 (0)