Skip to content

Commit 94f1364

Browse files
committed
[fix] some GitHub Copilot bugs
1 parent a320a10 commit 94f1364

File tree

13 files changed

+61
-55
lines changed

13 files changed

+61
-55
lines changed

components/Project/EvaluationDisplay.tsx

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@ import { FC, useContext } from 'react';
1010

1111
import { i18n, I18nContext } from '../../models/Translation';
1212
import userStore from '../../models/User';
13-
import {
14-
PrototypeGeneratorToolbar,
15-
PrototypeGeneratorToolbarProps,
16-
} from './PrototypeGeneratorToolbar';
13+
import { PrototypeGenerator, PrototypeGeneratorProps } from './PrototypeGenerator';
1714

1815
export const DevelopmentScopeName = ({ t }: typeof i18n) => [
1916
t('product_prototype'),
@@ -25,7 +22,7 @@ export const DevelopmentScopeName = ({ t }: typeof i18n) => [
2522

2623
export interface EvaluationDisplayProps
2724
extends RequirementEvaluation,
28-
Pick<PrototypeGeneratorToolbarProps, 'projectId' | 'messageId'> {
25+
Pick<PrototypeGeneratorProps, 'projectId' | 'messageId'> {
2926
prototypes?: PrototypeVersion[];
3027
}
3128

@@ -96,7 +93,7 @@ export const EvaluationDisplay: FC<EvaluationDisplayProps> = observer(
9693
{DevelopmentScopeName(i18n)[scope]}
9794

9895
{prototypeType && (
99-
<PrototypeGeneratorToolbar
96+
<PrototypeGenerator
10097
{...{ projectId, messageId }}
10198
type={prototypeType}
10299
prototype={prototypes?.find(({ type }) => type === prototypeType)}
@@ -108,7 +105,7 @@ export const EvaluationDisplay: FC<EvaluationDisplayProps> = observer(
108105
</Box>
109106
</Box>
110107
)}
111-
{models && models.length > 0 && (
108+
{models?.[0] && (
112109
<Box className="evaluation-item">
113110
<Typography component="h4" sx={{ fontWeight: 600 }}>
114111
{t('feature_modules')}

components/Project/NewCard.tsx

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,36 @@ import Link from 'next/link';
55
import { FC, useContext } from 'react';
66

77
import { I18nContext } from '../../models/Translation';
8+
import type zhCN from '../../translation/zh-CN';
89

9-
export const ProjectCard: FC<Project> = observer(({ id, name, status }) => {
10+
const statusTextKeys: (keyof typeof zhCN)[] = [
11+
'project_open', // Open
12+
'project_evaluated', // Evaluated
13+
'project_contract_generated', // ContractGenerated
14+
'project_in_development', // InDevelopment
15+
'project_in_testing', // InTesting
16+
'project_maintenance', // Maintenance
17+
];
18+
19+
const bgColors: string[] = [
20+
'grey.200', // Open
21+
'success.light', // Evaluated
22+
'warning.light', // ContractGenerated
23+
'info.light', // InDevelopment
24+
'secondary.light', // InTesting
25+
'primary.light', // Maintenance
26+
];
27+
28+
const textColors: string[] = [
29+
'text.primary', // Open
30+
'success.contrastText', // Evaluated
31+
'warning.contrastText', // ContractGenerated
32+
'info.contrastText', // InDevelopment
33+
'secondary.contrastText', // InTesting
34+
'primary.contrastText', // Maintenance
35+
];
36+
37+
export const ProjectCard: FC<Project> = observer(({ id, name, status = 0 }) => {
1038
const { t } = useContext(I18nContext);
1139

1240
return (
@@ -21,20 +49,11 @@ export const ProjectCard: FC<Project> = observer(({ id, name, status }) => {
2149
px: 1,
2250
py: 0.5,
2351
borderRadius: 1,
24-
bgcolor: status === 1 ? 'success.light' : status === 0 ? 'grey.200' : 'warning.light',
25-
color:
26-
status === 1
27-
? 'success.contrastText'
28-
: status === 0
29-
? 'text.primary'
30-
: 'warning.contrastText',
52+
bgcolor: bgColors[status] ?? 'grey.200',
53+
color: textColors[status] ?? 'text.primary',
3154
}}
3255
>
33-
{status === 1
34-
? t('project_open')
35-
: status === 0
36-
? t('project_closed')
37-
: t('project_pending')}
56+
{t((statusTextKeys[status] ?? 'project_open') as keyof typeof zhCN)}
3857
</Typography>
3958
</CardContent>
4059
<CardActions>

components/Project/PrototypeGeneratorToolbar.tsx renamed to components/Project/PrototypeGenerator.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,15 @@ import { inViewport, sleep } from 'web-utility';
99
import { PrototypeVersionModel } from '../../models/PrototypeVersion';
1010
import { i18n, I18nContext } from '../../models/Translation';
1111

12-
export interface PrototypeGeneratorToolbarProps {
12+
export interface PrototypeGeneratorProps {
1313
projectId: number;
1414
messageId: number;
1515
type: PrototypeType;
1616
prototype?: PrototypeVersion;
1717
}
1818

1919
@observer
20-
export class PrototypeGeneratorToolbar extends ObservedComponent<
21-
PrototypeGeneratorToolbarProps,
22-
typeof i18n
23-
> {
20+
export class PrototypeGenerator extends ObservedComponent<PrototypeGeneratorProps, typeof i18n> {
2421
static contextType = I18nContext;
2522

2623
versionStore = new PrototypeVersionModel(this.props.projectId, this.props.type);

components/Project/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { FC } from 'react';
22

33
import { Project } from '../../models/Project';
4-
import { ProjectCard } from './Card';
4+
import { ProjectCard } from './PublicCard';
55

66
export interface ProjectListLayoutProps {
77
defaultData: Project[];

models/PrototypeVersion.ts

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { PrototypeType, PrototypeVersion } from '@idea2app/data-server';
2-
import { toggle } from 'mobx-restful';
32

43
import { TableModel } from './Base';
54
import userStore from './User';
@@ -15,18 +14,4 @@ export class PrototypeVersionModel extends TableModel<PrototypeVersion> {
1514
super();
1615
this.baseURI = `project/${projectId}/prototype/${type}/version`;
1716
}
18-
19-
@toggle('downloading')
20-
async getVersionByMessageId(messageId: number) {
21-
try {
22-
const { body } = await this.client.get<PrototypeVersion>(
23-
`${this.baseURI}/message/${messageId}`,
24-
);
25-
return body;
26-
} catch (error: any) {
27-
if (error?.response?.status === 404) return;
28-
29-
console.error('Failed to fetch prototype version:', error);
30-
}
31-
}
3217
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
"globals": "^16.4.0",
7171
"husky": "^9.1.7",
7272
"jiti": "^2.6.1",
73-
"lint-staged": "^16.2.5",
73+
"lint-staged": "^16.2.6",
7474
"postcss": "^8.5.6",
7575
"prettier": "^3.6.2",
7676
"prettier-plugin-css-order": "^2.1.2",

pages/dashboard/project/[id].tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import { formToJSON, scrollTo, sleep } from 'web-utility';
99

1010
import { PageHead } from '../../../components/PageHead';
1111
import { EvaluationDisplay } from '../../../components/Project/EvaluationDisplay';
12-
import { PrototypeGeneratorToolbar } from '../../../components/Project/PrototypeGeneratorToolbar';
1312
import { ScrollList } from '../../../components/ScrollList';
1413
import { SessionBox } from '../../../components/User/SessionBox';
1514
import { ConsultMessageModel, ProjectModel } from '../../../models/ProjectEvaluation';

pages/project/[id].tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { FC, useContext } from 'react';
66
import { GitCard } from '../../components/Git/Card';
77
import { LarkImage } from '../../components/LarkImage';
88
import { PageHead } from '../../components/PageHead';
9-
import { ProjectCard } from '../../components/Project/Card';
9+
import { ProjectCard } from '../../components/Project/PublicCard';
1010
import { Project, ProjectModel } from '../../models/Project';
1111
import { GitRepositoryModel } from '../../models/Repository';
1212
import { I18nContext } from '../../models/Translation';

pnpm-lock.yaml

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)