commit c4372bc2bd60d8972665189bc6e063428c51a8fe
parent 56e84b60246f6ba483ea5ebe90b8e4fa39ade047
Author: Yuukin256 <Yuukin256@gmail.com>
Date: Thu, 3 Nov 2022 23:46:32 +0900
型定義変更
Diffstat:
4 files changed, 177 insertions(+), 96 deletions(-)
diff --git a/src/constant/index.tsx b/src/constant/index.tsx
@@ -1,3 +1,5 @@
+import type { AbstractLessonNameEn, AbstractLessonNameJa } from 'types';
+
export const APP_TITLE = '岸高時間割アプリ';
export const APP_DESCRIPTION = '岸和田高校の時間割を確認できるアプリ';
export const APP_URL = '';
@@ -35,5 +37,79 @@ export const CLASSES = [
'3-8',
] as const;
+export const ABSTRACT_LESSON_NAMES = [
+ 'Mon1',
+ 'Mon2',
+ 'Mon3',
+ 'Mon4',
+ 'Mon5',
+ 'Mon6',
+ 'Mon7',
+ 'Tue1',
+ 'Tue2',
+ 'Tue3',
+ 'Tue4',
+ 'Tue5',
+ 'Tue6',
+ 'Tue7',
+ 'Wed1',
+ 'Wed2',
+ 'Wed3',
+ 'Wed4',
+ 'Wed5',
+ 'Wed6',
+ 'Wed7',
+ 'Thu1',
+ 'Thu2',
+ 'Thu3',
+ 'Thu4',
+ 'Thu5',
+ 'Thu6',
+ 'Fri1',
+ 'Fri2',
+ 'Fri3',
+ 'Fri4',
+ 'Fri5',
+ 'Fri6',
+ 'Fri7',
+] as const;
+
+export const ABSTRACT_LESSON_NAME_MAP: Record<AbstractLessonNameEn, AbstractLessonNameJa> = {
+ Mon1: '月1',
+ Mon2: '月2',
+ Mon3: '月3',
+ Mon4: '月4',
+ Mon5: '月5',
+ Mon6: '月6',
+ Mon7: '月7',
+ Tue1: '火1',
+ Tue2: '火2',
+ Tue3: '火3',
+ Tue4: '火4',
+ Tue5: '火5',
+ Tue6: '火6',
+ Tue7: '火7',
+ Wed1: '水1',
+ Wed2: '水2',
+ Wed3: '水3',
+ Wed4: '水4',
+ Wed5: '水5',
+ Wed6: '水6',
+ Wed7: '水7',
+ Thu1: '木1',
+ Thu2: '木2',
+ Thu3: '木3',
+ Thu4: '木4',
+ Thu5: '木5',
+ Thu6: '木6',
+ Fri1: '金1',
+ Fri2: '金2',
+ Fri3: '金3',
+ Fri4: '金4',
+ Fri5: '金5',
+ Fri6: '金6',
+ Fri7: '金7',
+};
+
export const BUG_REPORT_FORM_URL = process.env['NEXT_PUBLIC_BUG_REPORT_FORM_URL'];
export const REQUEST_FORM_URL = process.env['NEXT_PUBLIC_REQUEST_FORM_URL'];
diff --git a/src/index.ts b/src/index.ts
@@ -1,100 +1,102 @@
-import { Temporal } from '@js-temporal/polyfill';
-import { Map, merge } from 'immutable';
+// import { Temporal } from '@js-temporal/polyfill';
+// import { Map, merge } from 'immutable';
-import { isAbstractLessonName } from './utils';
+// import { isAbstractLessonName } from './utils';
-import type { Grade, Class, Calendar, Standard, Unusual } from './types';
+// import type { Grade, Class, Calendar, StandardJa, Unusual } from './types';
-export const main = async (g: Grade, c: Class) => {
- console.log(g, c);
+// export const main = async (g: Grade, c: Class) => {
+// console.log(g, c);
- let calendar: Calendar = Map();
- calendar = calendar.set(new Temporal.PlainDate(2022, 1, 26).toJSON(), {
- 1: '水1',
- 2: '水2',
- 3: '水5',
- 4: '水6',
- 5: '水3',
- 6: '水4',
- 7: '水7',
- });
+// let calendar: Calendar = Map();
+// calendar = calendar.set(new Temporal.PlainDate(2022, 1, 26).toJSON(), {
+// 1: '水1',
+// 2: '水2',
+// 3: '水5',
+// 4: '水6',
+// 5: '水3',
+// 6: '水4',
+// 7: '水7',
+// });
- const standard: Standard = {
- 月1: '',
- 月2: '',
- 月3: '',
- 月4: '',
- 月5: '',
- 月6: '',
- 月7: '',
- 火1: '',
- 火2: '',
- 火3: '',
- 火4: '',
- 火5: '',
- 火6: '',
- 火7: '',
- 水1: '古典',
- 水2: '化学',
- 水3: '英語G',
- 水4: '数学Ⅰ',
- 水5: '書道',
- 水6: '体育',
- 水7: 'SD',
- 木1: '',
- 木2: '',
- 木3: '',
- 木4: '',
- 木5: '',
- 木6: '',
- 金1: '',
- 金2: '',
- 金3: '',
- 金4: '',
- 金5: '',
- 金6: '',
- 金7: '',
- };
- let unusual: Unusual = Map();
- unusual = unusual.set(new Temporal.PlainDate(2022, 1, 26).toJSON(), { 1: '数学A', 3: '古典' });
+// const standard: StandardJa = {
+// 月1: '',
+// 月2: '',
+// 月3: '',
+// 月4: '',
+// 月5: '',
+// 月6: '',
+// 月7: '',
+// 火1: '',
+// 火2: '',
+// 火3: '',
+// 火4: '',
+// 火5: '',
+// 火6: '',
+// 火7: '',
+// 水1: '古典',
+// 水2: '化学',
+// 水3: '英語G',
+// 水4: '数学Ⅰ',
+// 水5: '書道',
+// 水6: '体育',
+// 水7: 'SD',
+// 木1: '',
+// 木2: '',
+// 木3: '',
+// 木4: '',
+// 木5: '',
+// 木6: '',
+// 金1: '',
+// 金2: '',
+// 金3: '',
+// 金4: '',
+// 金5: '',
+// 金6: '',
+// 金7: '',
+// };
+// let unusual: Unusual = Map();
+// unusual = unusual.set(new Temporal.PlainDate(2022, 1, 26).toJSON(), { 1: '数学A', 3: '古典' });
- const standardAppliedCalendar = applyStandard(calendar, standard);
+// const standardAppliedCalendar = applyStandard(calendar, standard);
- return applyUnusual(standardAppliedCalendar, unusual);
-};
+// return applyUnusual(standardAppliedCalendar, unusual);
+// };
-const applyStandard = (calendar: Calendar, standard: Standard): Calendar => {
- // 標準時間割表のオブジェクトからから授業名を取り出す関数
- const getActualLesson = (lessonName: string | null) => {
- if (lessonName !== null && isAbstractLessonName(lessonName)) {
- return standard[lessonName];
- } else {
- return lessonName;
- }
- };
+// const applyStandard = (calendar: Calendar, standard: StandardJa): Calendar => {
+// // 標準時間割表のオブジェクトからから授業名を取り出す関数
+// const getActualLesson = (lessonName: string | null) => {
+// if (lessonName !== null && isAbstractLessonName(lessonName)) {
+// return standard[lessonName];
+// } else {
+// return lessonName;
+// }
+// };
- return calendar.map((lessons) => ({
- 1: getActualLesson(lessons[1]),
- 2: getActualLesson(lessons[2]),
- 3: getActualLesson(lessons[3]),
- 4: getActualLesson(lessons[4]),
- 5: getActualLesson(lessons[5]),
- 6: getActualLesson(lessons[6]),
- 7: getActualLesson(lessons[7]),
- }));
-};
+// return calendar.map((lessons) => ({
+// 1: getActualLesson(lessons[1]),
+// 2: getActualLesson(lessons[2]),
+// 3: getActualLesson(lessons[3]),
+// 4: getActualLesson(lessons[4]),
+// 5: getActualLesson(lessons[5]),
+// 6: getActualLesson(lessons[6]),
+// 7: getActualLesson(lessons[7]),
+// }));
+// };
-const applyUnusual = (calendar: Calendar, unusual: Unusual): Calendar => {
- return calendar.map((originalLessons, date) => {
- // この日の臨時時間割
- const unusualLessons = unusual.find((_, k) => k === date);
+// const applyUnusual = (calendar: Calendar, unusual: Unusual): Calendar => {
+// return calendar.map((originalLessons, date) => {
+// // この日の臨時時間割
+// const unusualLessons = unusual.find((_, k) => k === date);
- // ない場合は終了
- if (typeof unusualLessons === 'undefined') {
- return originalLessons;
- }
+// // ない場合は終了
+// if (typeof unusualLessons === 'undefined') {
+// return originalLessons;
+// }
- // merge して返す
- return merge(originalLessons, unusualLessons);
- });
-};
+// // merge して返す
+// return merge(originalLessons, unusualLessons);
+// });
+// };
+
+export default {};
diff --git a/src/types/index.ts b/src/types/index.ts
@@ -5,21 +5,24 @@ export type Grade = 1 | 2 | 3;
// クラス
export type Class = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8;
-type Weekday = '月' | '火' | '水' | '木' | '金';
-type SchoolPeriod = 1 | 2 | 3 | 4 | 5 | 6 | 7;
+type WeekdayEn = 'Mon' | 'Tue' | 'Wed' | 'Thu' | 'Fri';
+type WeekdayJa = '月' | '火' | '水' | '木' | '金';
+type SchoolTime = 1 | 2 | 3 | 4 | 5 | 6 | 7;
// 月1 から 金7 (木7 以外)
-export type AbstractLessonName = Exclude<`${Weekday}${SchoolPeriod}`, '木7'>;
+export type AbstractLessonNameJa = Exclude<`${WeekdayJa}${SchoolTime}`, '木7'>;
+export type AbstractLessonNameEn = Exclude<`${WeekdayEn}${SchoolTime}`, 'Thu7'>;
// 授業名
export type ActualLessonName = string;
-export type LessonName = AbstractLessonName | ActualLessonName;
+export type LessonName = AbstractLessonNameJa | ActualLessonName;
// 1日の授業
-export type DayLessons = Record<SchoolPeriod, LessonName | null>;
+export type DayLessons = Record<SchoolTime, LessonName | null>;
// クラスの標準時間割
-export type Standard = Readonly<Record<AbstractLessonName, string>>;
+export type StandardJa = Readonly<Record<AbstractLessonNameJa, string[]>>;
+export type StandardEn = Readonly<Record<AbstractLessonNameEn, string[]>>;
// 曜日変更込みの時間割表 (月1, 月2,… など) または、授業名代入済みの時間割表
export type Calendar = Map<string, DayLessons>;
diff --git a/src/utils.ts b/src/utils.ts
@@ -1,8 +1,8 @@
import { Temporal } from '@js-temporal/polyfill';
-import type { AbstractLessonName } from 'types';
+import type { AbstractLessonNameJa } from 'types';
-export const isAbstractLessonName = (value: string): value is AbstractLessonName => {
+export const isAbstractLessonName = (value: string): value is AbstractLessonNameJa => {
return /((月|火|水|金)(1|2|3|4|5|6|7)|木(1|2|3|4|5|6))/.test(value);
};