From 6d9430f1b5e6f9e4eaf3dc610159e1ffa137e753 Mon Sep 17 00:00:00 2001 From: jpnsantoss Date: Wed, 7 Feb 2024 15:18:21 +0000 Subject: [PATCH 1/5] preview config --- .env.example | 6 ------ src/api/backend.ts | 29 +++++++++++++++++++++-------- src/config/preview.json | 19 +++++++++++++++++++ src/utils/utils.ts | 39 ++++++++++----------------------------- 4 files changed, 50 insertions(+), 43 deletions(-) delete mode 100644 .env.example create mode 100644 src/config/preview.json diff --git a/.env.example b/.env.example deleted file mode 100644 index c4f59d90..00000000 --- a/.env.example +++ /dev/null @@ -1,6 +0,0 @@ -REACT_APP_PROD=0 -REACT_APP_RELEASE_DATE=2023-01-27 -PORT=3100 -REACT_APP_SEMESTER= -REACT_APP_SITE_TITLE= -REACT_APP_BACKEND_URL= \ No newline at end of file diff --git a/src/api/backend.ts b/src/api/backend.ts index a1d611cc..a5b41fa6 100644 --- a/src/api/backend.ts +++ b/src/api/backend.ts @@ -1,11 +1,24 @@ -import { CheckedCourse, Major } from '../@types' -import { extraCoursesData } from '../utils/data' -import { getSemester, config, dev_config } from '../utils/utils' - +import { CheckedCourse, Major } from '../@types'; +import { extraCoursesData } from '../utils/data'; +import { config, dev_config, getSemester, preview_config } from '../utils/utils'; + +const prod_val = Number(process.env.REACT_APP_PROD) +let BE_CONFIG + +switch (prod_val) { + case 1: + BE_CONFIG = config + break + case 2: + BE_CONFIG = preview_config + break + default: + BE_CONFIG = dev_config +} -const prod_val = process.env.REACT_APP_PROD -const BE_CONFIG = Number(prod_val) ? config : dev_config -const BACKEND_URL = process.env.REACT_APP_BACKEND_URL || `${BE_CONFIG.api.protocol}://${BE_CONFIG.api.host}:${BE_CONFIG.api.port}${BE_CONFIG.api.pathPrefix}` +const BACKEND_URL = + process.env.REACT_APP_BACKEND_URL || + `${BE_CONFIG.api.protocol}://${BE_CONFIG.api.host}:${BE_CONFIG.api.port}${BE_CONFIG.api.pathPrefix}` const SEMESTER = process.env.REACT_APP_SEMESTER || getSemester() /** @@ -114,7 +127,7 @@ const api = { getCoursesSchedules, getMajorCoursesSchedules, getExtraCourses, - getInfo + getInfo, } export default api diff --git a/src/config/preview.json b/src/config/preview.json new file mode 100644 index 00000000..0a2e5033 --- /dev/null +++ b/src/config/preview.json @@ -0,0 +1,19 @@ +{ + "pathPrefix": "/", + "paths": { + "about": "about", + "profile": "profile", + "planner": "planner", + "exchange": "exchange", + "faqs": "faqs", + "notfound": "*", + "home": "home" + }, + "api": { + "port": 443, + "protocol": "https", + "host": "ni.fe.up.pt", + "pathPrefix": "/tts/api", + "year": 2023 + } +} diff --git a/src/utils/utils.ts b/src/utils/utils.ts index 21ad2099..684955aa 100644 --- a/src/utils/utils.ts +++ b/src/utils/utils.ts @@ -1,8 +1,9 @@ -import config from '../config/prod.json' -import dev_config from '../config/local.json' -import { CourseOption, CourseSchedule, Lesson } from '../@types' -import { type ClassValue, clsx } from "clsx" -import { twMerge } from "tailwind-merge" +import { clsx, type ClassValue } from "clsx"; +import { twMerge } from "tailwind-merge"; +import { CourseOption, CourseSchedule, Lesson } from '../@types'; +import dev_config from '../config/local.json'; +import preview_config from '../config/preview.json'; +import config from '../config/prod.json'; const minHour = 8 const maxHour = 23 const dayNames = ['Dom', 'Seg', 'Ter', 'Qua', 'Qui', 'Sex', 'Sab'] @@ -204,27 +205,7 @@ const removeDuplicatesFromCourseOption = (courses: CourseOption[]): CourseOption } export { - config, - dev_config, - getPath, - minHour, - maxHour, - dayNames, - monthNames, - getDisplayDate, - getSemester, - getSchoolYear, - convertWeekday, - convertWeekdayLong, - convertHour, - timesCollide, - schedulesConflict, - getScheduleOptionDisplayText, - getLessonBoxTime, - getLessonBoxStyles, - getClassTypeClassName, - getLessonTypeLongName, - getCourseTeachers, - cn, - removeDuplicatesFromCourseOption -} + cn, config, convertHour, convertWeekday, + convertWeekdayLong, dayNames, dev_config, getClassTypeClassName, getCourseTeachers, getDisplayDate, getLessonBoxStyles, getLessonBoxTime, getLessonTypeLongName, getPath, getScheduleOptionDisplayText, getSchoolYear, getSemester, maxHour, minHour, monthNames, preview_config, removeDuplicatesFromCourseOption, schedulesConflict, timesCollide +}; + From 36183eda0b71b4941c2b7f1f2b13560812e46b77 Mon Sep 17 00:00:00 2001 From: jpnsantoss Date: Wed, 7 Feb 2024 15:22:16 +0000 Subject: [PATCH 2/5] added .env.example --- .env.example | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .env.example diff --git a/.env.example b/.env.example new file mode 100644 index 00000000..c4f59d90 --- /dev/null +++ b/.env.example @@ -0,0 +1,6 @@ +REACT_APP_PROD=0 +REACT_APP_RELEASE_DATE=2023-01-27 +PORT=3100 +REACT_APP_SEMESTER= +REACT_APP_SITE_TITLE= +REACT_APP_BACKEND_URL= \ No newline at end of file From 714d7979dee0beeb3b8c9409a65f4253af0f904d Mon Sep 17 00:00:00 2001 From: jpnsantoss Date: Wed, 7 Feb 2024 15:42:25 +0000 Subject: [PATCH 3/5] Revert "added .env.example" This reverts commit 36183eda0b71b4941c2b7f1f2b13560812e46b77. --- .env.example | 6 ------ 1 file changed, 6 deletions(-) delete mode 100644 .env.example diff --git a/.env.example b/.env.example deleted file mode 100644 index c4f59d90..00000000 --- a/.env.example +++ /dev/null @@ -1,6 +0,0 @@ -REACT_APP_PROD=0 -REACT_APP_RELEASE_DATE=2023-01-27 -PORT=3100 -REACT_APP_SEMESTER= -REACT_APP_SITE_TITLE= -REACT_APP_BACKEND_URL= \ No newline at end of file From 2def73a9ebf9dd3aa2e3d138a8b1cf17ad22f1b2 Mon Sep 17 00:00:00 2001 From: jpnsantoss Date: Wed, 7 Feb 2024 15:44:59 +0000 Subject: [PATCH 4/5] Revert "preview config" This reverts commit 6d9430f1b5e6f9e4eaf3dc610159e1ffa137e753. --- .env.example | 6 ++++++ src/api/backend.ts | 29 ++++++++--------------------- src/config/preview.json | 19 ------------------- src/utils/utils.ts | 39 +++++++++++++++++++++++++++++---------- 4 files changed, 43 insertions(+), 50 deletions(-) create mode 100644 .env.example delete mode 100644 src/config/preview.json diff --git a/.env.example b/.env.example new file mode 100644 index 00000000..c4f59d90 --- /dev/null +++ b/.env.example @@ -0,0 +1,6 @@ +REACT_APP_PROD=0 +REACT_APP_RELEASE_DATE=2023-01-27 +PORT=3100 +REACT_APP_SEMESTER= +REACT_APP_SITE_TITLE= +REACT_APP_BACKEND_URL= \ No newline at end of file diff --git a/src/api/backend.ts b/src/api/backend.ts index a5b41fa6..a1d611cc 100644 --- a/src/api/backend.ts +++ b/src/api/backend.ts @@ -1,24 +1,11 @@ -import { CheckedCourse, Major } from '../@types'; -import { extraCoursesData } from '../utils/data'; -import { config, dev_config, getSemester, preview_config } from '../utils/utils'; - -const prod_val = Number(process.env.REACT_APP_PROD) -let BE_CONFIG - -switch (prod_val) { - case 1: - BE_CONFIG = config - break - case 2: - BE_CONFIG = preview_config - break - default: - BE_CONFIG = dev_config -} +import { CheckedCourse, Major } from '../@types' +import { extraCoursesData } from '../utils/data' +import { getSemester, config, dev_config } from '../utils/utils' + -const BACKEND_URL = - process.env.REACT_APP_BACKEND_URL || - `${BE_CONFIG.api.protocol}://${BE_CONFIG.api.host}:${BE_CONFIG.api.port}${BE_CONFIG.api.pathPrefix}` +const prod_val = process.env.REACT_APP_PROD +const BE_CONFIG = Number(prod_val) ? config : dev_config +const BACKEND_URL = process.env.REACT_APP_BACKEND_URL || `${BE_CONFIG.api.protocol}://${BE_CONFIG.api.host}:${BE_CONFIG.api.port}${BE_CONFIG.api.pathPrefix}` const SEMESTER = process.env.REACT_APP_SEMESTER || getSemester() /** @@ -127,7 +114,7 @@ const api = { getCoursesSchedules, getMajorCoursesSchedules, getExtraCourses, - getInfo, + getInfo } export default api diff --git a/src/config/preview.json b/src/config/preview.json deleted file mode 100644 index 0a2e5033..00000000 --- a/src/config/preview.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "pathPrefix": "/", - "paths": { - "about": "about", - "profile": "profile", - "planner": "planner", - "exchange": "exchange", - "faqs": "faqs", - "notfound": "*", - "home": "home" - }, - "api": { - "port": 443, - "protocol": "https", - "host": "ni.fe.up.pt", - "pathPrefix": "/tts/api", - "year": 2023 - } -} diff --git a/src/utils/utils.ts b/src/utils/utils.ts index 684955aa..21ad2099 100644 --- a/src/utils/utils.ts +++ b/src/utils/utils.ts @@ -1,9 +1,8 @@ -import { clsx, type ClassValue } from "clsx"; -import { twMerge } from "tailwind-merge"; -import { CourseOption, CourseSchedule, Lesson } from '../@types'; -import dev_config from '../config/local.json'; -import preview_config from '../config/preview.json'; -import config from '../config/prod.json'; +import config from '../config/prod.json' +import dev_config from '../config/local.json' +import { CourseOption, CourseSchedule, Lesson } from '../@types' +import { type ClassValue, clsx } from "clsx" +import { twMerge } from "tailwind-merge" const minHour = 8 const maxHour = 23 const dayNames = ['Dom', 'Seg', 'Ter', 'Qua', 'Qui', 'Sex', 'Sab'] @@ -205,7 +204,27 @@ const removeDuplicatesFromCourseOption = (courses: CourseOption[]): CourseOption } export { - cn, config, convertHour, convertWeekday, - convertWeekdayLong, dayNames, dev_config, getClassTypeClassName, getCourseTeachers, getDisplayDate, getLessonBoxStyles, getLessonBoxTime, getLessonTypeLongName, getPath, getScheduleOptionDisplayText, getSchoolYear, getSemester, maxHour, minHour, monthNames, preview_config, removeDuplicatesFromCourseOption, schedulesConflict, timesCollide -}; - + config, + dev_config, + getPath, + minHour, + maxHour, + dayNames, + monthNames, + getDisplayDate, + getSemester, + getSchoolYear, + convertWeekday, + convertWeekdayLong, + convertHour, + timesCollide, + schedulesConflict, + getScheduleOptionDisplayText, + getLessonBoxTime, + getLessonBoxStyles, + getClassTypeClassName, + getLessonTypeLongName, + getCourseTeachers, + cn, + removeDuplicatesFromCourseOption +} From 3bd177130890ae4aa1a97aee0dc57ded412dc1fd Mon Sep 17 00:00:00 2001 From: jpnsantoss Date: Wed, 7 Feb 2024 15:46:50 +0000 Subject: [PATCH 5/5] revert changes + netlify spa --- netlify.toml | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 netlify.toml diff --git a/netlify.toml b/netlify.toml new file mode 100644 index 00000000..6a3dd09c --- /dev/null +++ b/netlify.toml @@ -0,0 +1,4 @@ +[[redirects]] +from = "/*" +to = "/index.html" +status = 200