timetable-app

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit 5320da3a48b252d3faaf71c178aa01a38f53c7b3
parent d3fe5b35e6cc9a7ae7cebe999be60dab2dc9ba29
Author: Yuukin256 <52195426+Yuukin256@users.noreply.github.com>
Date:   Thu, 10 Nov 2022 23:48:32 +0900

Merge pull request #1 from Yuukin256/dev

臨時変更に対応
Diffstat:
Mpackage.json | 4++--
Msrc/constant/index.tsx | 2+-
Msrc/pages/[class].tsx | 44+++++++++++++++++++++++++++++---------------
Msrc/pages/index.tsx | 9++++++++-
Asrc/prisma/migrations/20221110132920_modify_unusual_change/migration.sql | 25+++++++++++++++++++++++++
Msrc/prisma/schema.prisma | 45++++++++++++++++++++++++---------------------
Myarn.lock | 40++++++++++++++++++++--------------------
7 files changed, 109 insertions(+), 60 deletions(-)

diff --git a/package.json b/package.json @@ -27,7 +27,7 @@ "@mui/lab": "^5.0.0-alpha.107", "@mui/material": "^5.10.12", "@mui/x-date-pickers": "^5.0.7", - "@prisma/client": "^4.5.0", + "@prisma/client": "^4.6.0", "aspida": "^1.11.0", "date-fns": "^2.29.3", "immutable": "^4.1.0", @@ -62,7 +62,7 @@ "husky": "^8.0.1", "lint-staged": "^13.0.3", "prettier": "^2.7.1", - "prisma": "^4.5.0", + "prisma": "^4.6.0", "typescript": "^4.8.4" }, "packageManager": "yarn@3.2.4" diff --git a/src/constant/index.tsx b/src/constant/index.tsx @@ -2,7 +2,7 @@ import type { AbstractLessonNameEn, AbstractLessonNameJa } from 'types'; export const APP_TITLE = '岸高時間割アプリ'; export const APP_DESCRIPTION = '岸和田高校の時間割を確認できるアプリ'; -export const APP_URL = ''; +export const APP_URL = process.env['NEXT_PUBLIC_VERCEL_URL']; export const GRADED_CLASSES = [ ['1-1', '1-2', '1-3', '1-4', '1-5', '1-6', '1-7', '1-8'], diff --git a/src/pages/[class].tsx b/src/pages/[class].tsx @@ -1,5 +1,5 @@ import Box from '@mui/material/Box'; -import format from 'date-fns/format'; +import { format, isEqual } from 'date-fns'; import { Map } from 'immutable'; import Head from 'components/common/Head'; @@ -49,7 +49,7 @@ export const getStaticProps: GetStaticProps<PageProps, UrlQuery> = async ({ para const [schoolClass, dayTimetables] = await Promise.all([ prisma.schoolClass.findUnique({ where: { grade_class: { grade: gradeNum, class: classNum } }, - select: { Standard: true, UnusualTimetableUnit: true }, + select: { Standard: true, UnusualChanges: true }, }), prisma.dayTimetable.findMany({ where: { grade: gradeNum }, orderBy: { date: 'asc' } }), ]); @@ -62,22 +62,36 @@ export const getStaticProps: GetStaticProps<PageProps, UrlQuery> = async ({ para } const standard = schoolClass.Standard; + const unusualChanges = schoolClass.UnusualChanges; - // TODO: 臨時変更に対応 const calendar: Calendar = Map( dayTimetables.map((dayTimetable) => { - return [ - format(dayTimetable.date, DATE_FORMAT), - { - period1: dayTimetable.period1 ? standard[dayTimetable.period1] : [], - period2: dayTimetable.period2 ? standard[dayTimetable.period2] : [], - period3: dayTimetable.period3 ? standard[dayTimetable.period3] : [], - period4: dayTimetable.period4 ? standard[dayTimetable.period4] : [], - period5: dayTimetable.period5 ? standard[dayTimetable.period5] : [], - period6: dayTimetable.period6 ? standard[dayTimetable.period6] : [], - period7: dayTimetable.period7 ? standard[dayTimetable.period7] : [], - }, - ]; + const originalTimetable = { + period1: dayTimetable.period1 ? standard[dayTimetable.period1] : [], + period2: dayTimetable.period2 ? standard[dayTimetable.period2] : [], + period3: dayTimetable.period3 ? standard[dayTimetable.period3] : [], + period4: dayTimetable.period4 ? standard[dayTimetable.period4] : [], + period5: dayTimetable.period5 ? standard[dayTimetable.period5] : [], + period6: dayTimetable.period6 ? standard[dayTimetable.period6] : [], + period7: dayTimetable.period7 ? standard[dayTimetable.period7] : [], + }; + const unusualChange = unusualChanges.find((unusual) => isEqual(dayTimetable.date, unusual.date)); + + if (!unusualChange) { + return [format(dayTimetable.date, DATE_FORMAT), originalTimetable]; + } + + const timetableWithUnusualChange = { + period1: unusualChange.period1.length ? unusualChange.period1 : originalTimetable.period1, + period2: unusualChange.period2.length ? unusualChange.period2 : originalTimetable.period2, + period3: unusualChange.period3.length ? unusualChange.period3 : originalTimetable.period3, + period4: unusualChange.period4.length ? unusualChange.period4 : originalTimetable.period4, + period5: unusualChange.period5.length ? unusualChange.period5 : originalTimetable.period5, + period6: unusualChange.period6.length ? unusualChange.period6 : originalTimetable.period6, + period7: unusualChange.period7.length ? unusualChange.period7 : originalTimetable.period7, + }; + + return [format(dayTimetable.date, DATE_FORMAT), timetableWithUnusualChange]; }) ); diff --git a/src/pages/index.tsx b/src/pages/index.tsx @@ -23,7 +23,14 @@ const Page: NextPage = () => { {GRADED_CLASSES.map((classes, g) => ( <Stack spacing={2} width='100%' key={g}> {classes.map((c) => ( - <Button fullWidth variant='outlined' href={`/${c}`} sx={{ fontSize: 15 }} key={c}> + <Button + fullWidth + variant='outlined' + href={`/${c}`} + sx={{ fontSize: 15 }} + LinkComponent={Link} + key={c} + > {c} </Button> ))} diff --git a/src/prisma/migrations/20221110132920_modify_unusual_change/migration.sql b/src/prisma/migrations/20221110132920_modify_unusual_change/migration.sql @@ -0,0 +1,25 @@ +/* + Warnings: + + - The primary key for the `UnusualChange` table will be changed. If it partially fails, the table could be left without primary key constraint. + - You are about to drop the column `id` on the `UnusualChange` table. All the data in the column will be lost. + - You are about to drop the column `lessonName` on the `UnusualChange` table. All the data in the column will be lost. + - You are about to drop the column `schoolTime` on the `UnusualChange` table. All the data in the column will be lost. + +*/ +-- DropIndex +DROP INDEX "UnusualChange_classId_date_schoolTime_key"; + +-- AlterTable +ALTER TABLE "UnusualChange" DROP CONSTRAINT "UnusualChange_pkey", +DROP COLUMN "id", +DROP COLUMN "lessonName", +DROP COLUMN "schoolTime", +ADD COLUMN "period1" TEXT[], +ADD COLUMN "period2" TEXT[], +ADD COLUMN "period3" TEXT[], +ADD COLUMN "period4" TEXT[], +ADD COLUMN "period5" TEXT[], +ADD COLUMN "period6" TEXT[], +ADD COLUMN "period7" TEXT[], +ADD CONSTRAINT "UnusualChange_pkey" PRIMARY KEY ("classId", "date"); diff --git a/src/prisma/schema.prisma b/src/prisma/schema.prisma @@ -17,12 +17,12 @@ model SchoolGrade { } model SchoolClass { - id Int @id - SchoolGrade SchoolGrade @relation(fields: [grade], references: [grade]) - class Int - grade Int - Standard Standard? - UnusualTimetableUnit UnusualChange[] + id Int @id + SchoolGrade SchoolGrade @relation(fields: [grade], references: [grade]) + class Int + grade Int + Standard Standard? + UnusualChanges UnusualChange[] @@unique([grade, class]) } @@ -70,27 +70,30 @@ model DayTimetable { SchoolGrade SchoolGrade @relation(fields: [grade], references: [grade]) grade Int date DateTime @db.Date - period1 AbstractLessonName? - period2 AbstractLessonName? - period3 AbstractLessonName? - period4 AbstractLessonName? - period5 AbstractLessonName? - period6 AbstractLessonName? - period7 AbstractLessonName? + period1 AbstractLessonName? + period2 AbstractLessonName? + period3 AbstractLessonName? + period4 AbstractLessonName? + period5 AbstractLessonName? + period6 AbstractLessonName? + period7 AbstractLessonName? @@id([grade, date]) } -// TODO: モデル定期変更 DayTimetable に近い形にする model UnusualChange { - id Int @id @default(autoincrement()) - class SchoolClass @relation(fields: [classId], references: [id]) - classId Int - date DateTime @db.Date - schoolTime Int - lessonName String[] + SchoolClass SchoolClass @relation(fields: [classId], references: [id]) + classId Int + date DateTime @db.Date + period1 String[] + period2 String[] + period3 String[] + period4 String[] + period5 String[] + period6 String[] + period7 String[] - @@unique([classId, date, schoolTime]) + @@id([classId, date]) } enum AbstractLessonName { diff --git a/yarn.lock b/yarn.lock @@ -882,31 +882,31 @@ __metadata: languageName: node linkType: hard -"@prisma/client@npm:^4.5.0": - version: 4.5.0 - resolution: "@prisma/client@npm:4.5.0" +"@prisma/client@npm:^4.6.0": + version: 4.6.0 + resolution: "@prisma/client@npm:4.6.0" dependencies: - "@prisma/engines-version": 4.5.0-43.0362da9eebca54d94c8ef5edd3b2e90af99ba452 + "@prisma/engines-version": 4.6.0-53.2e719efb80b56a3f32d18a62489de95bb9c130e3 peerDependencies: prisma: "*" peerDependenciesMeta: prisma: optional: true - checksum: 1e6b76c104f17e6fc78c537d17879a17dcde8443cd6d084530068453c4f2620050c273f5683d7cdb5012a0d5b4854907fe993fcf5752fb11f2bcca7221d34e59 + checksum: 9ea358059c01d5ed18b683a1bf4c713c08eb084622aadafa0b80d0439d5ea46e8930efa3fc72a915914f306f505bc7874954466ba13fdd385ca39e8009702e03 languageName: node linkType: hard -"@prisma/engines-version@npm:4.5.0-43.0362da9eebca54d94c8ef5edd3b2e90af99ba452": - version: 4.5.0-43.0362da9eebca54d94c8ef5edd3b2e90af99ba452 - resolution: "@prisma/engines-version@npm:4.5.0-43.0362da9eebca54d94c8ef5edd3b2e90af99ba452" - checksum: 619626ff5dc16a292065a5318f76653f589bf170a769edbabb07d62b4a589ab0eba287a00faf3e31eaf3280c99662e210376a61a68f91b7690a955fd43f346eb +"@prisma/engines-version@npm:4.6.0-53.2e719efb80b56a3f32d18a62489de95bb9c130e3": + version: 4.6.0-53.2e719efb80b56a3f32d18a62489de95bb9c130e3 + resolution: "@prisma/engines-version@npm:4.6.0-53.2e719efb80b56a3f32d18a62489de95bb9c130e3" + checksum: 88510cec375f1505953121a41fa464f26be4022859cfe40659e4cb15c7e8d22d163203a30d65f2e66c828287cf029eb92ab6ba7325c6b3f551f92fb52424477b languageName: node linkType: hard -"@prisma/engines@npm:4.5.0": - version: 4.5.0 - resolution: "@prisma/engines@npm:4.5.0" - checksum: d34ba4ceee67809b4a6d756763b118b3fbf273ab35378e568495248c7c62633c4cccca1e6b94411d5312a272f268f3dec5e8ae0a3e4177ad5f593f38daca7c58 +"@prisma/engines@npm:4.6.0": + version: 4.6.0 + resolution: "@prisma/engines@npm:4.6.0" + checksum: d964ab9641153410d1e4b5c81dfb4be309964b133eb891140cf8636a7e8bfd33228f92b83a3b700b1b97eaa0b58aa5ad113836e8d76ff3cc901b500938736214 languageName: node linkType: hard @@ -4366,15 +4366,15 @@ __metadata: languageName: node linkType: hard -"prisma@npm:^4.5.0": - version: 4.5.0 - resolution: "prisma@npm:4.5.0" +"prisma@npm:^4.6.0": + version: 4.6.0 + resolution: "prisma@npm:4.6.0" dependencies: - "@prisma/engines": 4.5.0 + "@prisma/engines": 4.6.0 bin: prisma: build/index.js prisma2: build/index.js - checksum: 83a6d28475a31e8d69b355f949c0484b6d64324c45c452c57bf9ed50f85129b8df22fecb671c00a28f0cb80360a3f691888c463548949e94078f7f9be4bd0c79 + checksum: eee15955638c67dcdff8d0338a1cad5f4b3fc62f6894336543d6f3d09456295f5e23916f7bedbb396a5ca5d7be5fa62dc52d49e95f971ad3968e6d650d9934ea languageName: node linkType: hard @@ -5346,7 +5346,7 @@ __metadata: "@mui/material": ^5.10.12 "@mui/x-date-pickers": ^5.0.7 "@next/eslint-plugin-next": ^13.0.2 - "@prisma/client": ^4.5.0 + "@prisma/client": ^4.6.0 "@tsconfig/strictest": ^1.0.2 "@types/node": ^18.11.9 "@types/react": ^18.0.25 @@ -5370,7 +5370,7 @@ __metadata: next-connect: ^1.0.0-next.3 notistack: ^2.0.8 prettier: ^2.7.1 - prisma: ^4.5.0 + prisma: ^4.6.0 react: ^18.2.0 react-dom: ^18.2.0 react-query: ^3.39.2