Skip to content

Commit f057917

Browse files
TechQueryCopilot
andcommitted
[optimize] simplify AI codes
Co-authored-by: Copilot <copilot@github.com>
1 parent 848345f commit f057917

2 files changed

Lines changed: 8 additions & 18 deletions

File tree

components/Activity/Hackathon/constant.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { TableCellUser } from 'mobx-lark';
12
import { Activity, ActivityModel } from '../../../models/Activity';
23
import { Agenda, Organization, Person, Prize, Project, Template } from '../../../models/Hackathon';
34
import { i18n } from '../../../models/Translation';
@@ -11,7 +12,6 @@ import {
1112
formatPeriod,
1213
normalizeAgendaType,
1314
previewText,
14-
userOf,
1515
} from './utility';
1616

1717
export const RequiredTableKeys = [
@@ -335,7 +335,6 @@ export const buildProjectItems = (
335335
{ projects, activity }: { projects: Project[]; activity: Activity },
336336
) =>
337337
projects.map(({ id, name, score, summary, createdBy, members }) => {
338-
const creator = userOf(createdBy);
339338
const scoreText = score === null || score === undefined || score === '' ? '—' : `${score}`;
340339

341340
return {
@@ -345,10 +344,10 @@ export const buildProjectItems = (
345344
score: scoreText,
346345
description: (summary as string) || '',
347346
meta: [
348-
creator
347+
createdBy
349348
? {
350349
label: t('created_by'),
351-
value: creator.name || '—',
350+
value: (createdBy as TableCellUser)?.name || '—',
352351
}
353352
: { label: t('created_by'), value: '—' },
354353
{

components/Activity/Hackathon/utility.ts

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { TableCellUser, TableCellValue, TableFormView } from 'mobx-lark';
2-
import { formatDate } from 'web-utility';
1+
import { TableCellValue, TableFormView } from 'mobx-lark';
2+
import { Day, formatDate } from 'web-utility';
33

44
import type { HackathonScheduleTone } from './Schedule';
55
import { i18n, I18nKey } from '../../../models/Translation';
@@ -94,16 +94,6 @@ const textOf = (value: TextLike) => {
9494
export const firstTextOf = (value: TextListLike) =>
9595
(Array.isArray(value) ? value.map(textOf).find(Boolean) : textOf(value)) || '';
9696

97-
export const textListOf = (value: TextListLike) =>
98-
(Array.isArray(value) ? value : [value]).map(textOf).filter(Boolean);
99-
100-
export const relationNameOf = (value: TextListLike) => firstTextOf(value);
101-
102-
export const userOf = (value?: TableCellValue | TableCellUser) =>
103-
value && typeof value === 'object' && !Array.isArray(value) && 'name' in value
104-
? (value as TableCellUser)
105-
: undefined;
106-
10797
export const formatMoment = (value?: TableCellValue) => (value ? formatDate(value as string) : '');
10898

10999
export const formatPeriod = (startedAt?: TableCellValue, endedAt?: TableCellValue) =>
@@ -152,7 +142,8 @@ export const resolveCountdownState = <T extends CountdownWindow>(
152142
? nextItem?.startedAt
153143
: nextItem?.endedAt;
154144
const fallbackCountdownTarget = timeOf(startTime) > referenceTime ? startTime : endTime;
155-
const countdownTo = countdownTextOf(nextCountdownTarget) || countdownTextOf(fallbackCountdownTarget);
145+
const countdownTo =
146+
countdownTextOf(nextCountdownTarget) || countdownTextOf(fallbackCountdownTarget);
156147

157148
return { nextItem, countdownTo };
158149
};
@@ -219,7 +210,7 @@ export const daysBetween = (startedAt?: TableCellValue, endedAt?: TableCellValue
219210

220211
if (!Number.isFinite(start) || !Number.isFinite(end) || end < start) return 0;
221212

222-
return Math.max(1, Math.ceil((end - start) / (24 * 60 * 60 * 1000)));
213+
return Math.max(1, Math.ceil((end - start) / Day));
223214
};
224215

225216
export const normalizeAgendaType = (value?: TableCellValue) =>

0 commit comments

Comments
 (0)