From 1879acc9d42b8c1f63f51e6efb3b20c898c2cf0b Mon Sep 17 00:00:00 2001 From: majusss Date: Sat, 16 Dec 2023 21:44:03 +0100 Subject: [PATCH] k.s.chj. --- README.md | 28 ------------ package.json | 15 ++++-- pnpm-lock.yaml | 57 ++++++++++++++++++----- src/pages/api/timetable/getTimetable.ts | 61 ------------------------- src/pages/api/timetable/list.ts | 58 ----------------------- src/pages/zastepstwa.tsx | 18 ++++---- 6 files changed, 64 insertions(+), 173 deletions(-) delete mode 100644 src/pages/api/timetable/getTimetable.ts delete mode 100644 src/pages/api/timetable/list.ts diff --git a/README.md b/README.md index 0f78f77..e25117f 100644 --- a/README.md +++ b/README.md @@ -26,26 +26,6 @@ The phone mode is inspired by the school's timetable ## API Reference -#### Get lists (Selects) - -```http - GET /api/timetable/list -``` - -| Parameters (Optional) | Description | -| :--------------------------------- | :-------------------------------------- | -| `?select=classes\|teachers\|rooms` | Returns only classes, teachers or rooms | - -#### Get timetable and other data - -```http - GET /api/timetable/getTimetable -``` - -| Parameter (Default: o1) | Description | -| :---------------------- | :---------------------------------------------------------- | -| `?id=id` | Returns the timetable of a Branch with the specified **id** | - #### Get empty classes ```http @@ -68,14 +48,6 @@ The phone mode is inspired by the school's timetable | `?search=teacher\|branch` | Search substitutions for branch or for a teacher | | `?query=index` | What api will search in substitution | -#### What is **id** and how do I find it? - -| Id prefix | Description | Value | -| :-------- | :--------------- | :----------------------------------------------- | -| `o` | Branch / Classes | `value from /api/timetable/list?select=classes` | -| `n` | Teacher | `value from /api/timetable/list?select=teachers` | -| `s` | Room | `value from /api/timetable/list?select=rooms` | - ## Links [![portfolio](https://img.shields.io/badge/GitHub-rvyk-100000?style=for-the-badge&logo=github&logoColor=white)](https://github.com/rvyk/) diff --git a/package.json b/package.json index 6663627..872dfbb 100644 --- a/package.json +++ b/package.json @@ -13,15 +13,20 @@ "dependencies": { "@headlessui/react": "^1.7.17", "@heroicons/react": "^2.0.18", - "@types/node": "^20.9.5", + "@types/node": "^20.10.4", "@types/react": "18.2.38", - "@wulkanowy/timetable-parser": "https://github.com/majusss/timetable-parser-js.git", + "@wulkanowy/timetable-parser": "github:majusss/timetable-parser-js", "autoprefixer": "^10.4.16", "axios": "^1.6.2", "cheerio": "1.0.0-rc.12", "eslint": "^8.56.0", +<<<<<<< Updated upstream "eslint-config-next": "^14.0.3", "flowbite": "^2.2.0", +======= + "eslint-config-next": "^14.0.4", + "flowbite": "^2.2.1", +>>>>>>> Stashed changes "lodash": "^4.17.21", "mobile-detect": "^1.4.5", "next": "14.0.4", @@ -29,18 +34,18 @@ "next-themes": "^0.2.1", "node-cache": "^5.1.2", "node-fetch": "^3.3.2", - "postcss": "^8.4.31", + "postcss": "^8.4.32", "react": "^18.2.0", "react-dom": "^18.2.0", "react-snowfall": "^1.2.1", - "react-tooltip": "^5.24.0", + "react-tooltip": "^5.25.0", "sharp": "^0.33.0", "tailwindcss": "^3.3.6", "tua-body-scroll-lock": "^1.4.0", "webpack": "^5.89.0" }, "devDependencies": { - "cypress": "^13.6.0", + "cypress": "^13.6.1", "cypress-dotenv": "^2.0.0", "dotenv": "^16.3.1", "start-server-and-test": "^2.0.3", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 62d7242..bdc9f57 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -12,13 +12,13 @@ dependencies: specifier: ^2.0.18 version: 2.0.18(react@18.2.0) '@types/node': - specifier: ^20.9.5 + specifier: ^20.10.4 version: 20.10.4 '@types/react': specifier: 18.2.38 version: 18.2.38 '@wulkanowy/timetable-parser': - specifier: https://github.com/majusss/timetable-parser-js.git + specifier: github:majusss/timetable-parser-js version: github.com/majusss/timetable-parser-js/1c1c421935155a3beedba127bd05fe0eee6e0b20 autoprefixer: specifier: ^10.4.16 @@ -33,10 +33,15 @@ dependencies: specifier: ^8.56.0 version: 8.56.0 eslint-config-next: +<<<<<<< Updated upstream specifier: ^14.0.3 version: 14.0.4(eslint@8.56.0)(typescript@5.3.3) +======= + specifier: ^14.0.4 + version: 14.0.4(eslint@8.56.0)(typescript@5.3.2) +>>>>>>> Stashed changes flowbite: - specifier: ^2.2.0 + specifier: ^2.2.1 version: 2.2.1 lodash: specifier: ^4.17.21 @@ -60,7 +65,7 @@ dependencies: specifier: ^3.3.2 version: 3.3.2 postcss: - specifier: ^8.4.31 + specifier: ^8.4.32 version: 8.4.32 react: specifier: ^18.2.0 @@ -72,7 +77,7 @@ dependencies: specifier: ^1.2.1 version: 1.2.1(react-dom@18.2.0)(react@18.2.0) react-tooltip: - specifier: ^5.24.0 + specifier: ^5.25.0 version: 5.25.0(react-dom@18.2.0)(react@18.2.0) sharp: specifier: ^0.33.0 @@ -89,7 +94,7 @@ dependencies: devDependencies: cypress: - specifier: ^13.6.0 + specifier: ^13.6.1 version: 13.6.1 cypress-dotenv: specifier: ^2.0.0 @@ -1263,7 +1268,7 @@ packages: resolution: {integrity: sha512-zHd0eUrf5GZoOWVCXp6koAKQTfZV07eit6bGPmJgnZdnSAvvZee6zniW2XMF7Cmc4ISOOnPy3QaSiIJGJkVEDQ==} engines: {node: '>=6.9.0'} dependencies: - regenerator-runtime: 0.14.0 + regenerator-runtime: 0.14.1 dev: false /@babel/template@7.22.15: @@ -1976,7 +1981,11 @@ packages: dev: true optional: true +<<<<<<< Updated upstream /@typescript-eslint/parser@6.14.0(eslint@8.56.0)(typescript@5.3.3): +======= + /@typescript-eslint/parser@6.14.0(eslint@8.56.0)(typescript@5.3.2): +>>>>>>> Stashed changes resolution: {integrity: sha512-QjToC14CKacd4Pa7JK4GeB/vHmWFJckec49FR4hmIRf97+KXole0T97xxu9IFiPxVQ1DBWrQ5wreLwAGwWAVQA==} engines: {node: ^16.0.0 || >=18.0.0} peerDependencies: @@ -1992,7 +2001,11 @@ packages: '@typescript-eslint/visitor-keys': 6.14.0 debug: 4.3.4(supports-color@8.1.1) eslint: 8.56.0 +<<<<<<< Updated upstream typescript: 5.3.3 +======= + typescript: 5.3.2 +>>>>>>> Stashed changes transitivePeerDependencies: - supports-color dev: false @@ -2555,7 +2568,7 @@ packages: hasBin: true dependencies: caniuse-lite: 1.0.30001570 - electron-to-chromium: 1.4.613 + electron-to-chromium: 1.4.614 node-releases: 2.0.14 update-browserslist-db: 1.0.13(browserslist@4.22.2) dev: false @@ -3118,8 +3131,8 @@ packages: jake: 10.8.7 dev: false - /electron-to-chromium@1.4.613: - resolution: {integrity: sha512-r4x5+FowKG6q+/Wj0W9nidx7QO31BJwmR2uEo+Qh3YLGQ8SbBAFuDFpTxzly/I2gsbrFwBuIjrMp423L3O5U3w==} + /electron-to-chromium@1.4.614: + resolution: {integrity: sha512-X4ze/9Sc3QWs6h92yerwqv7aB/uU8vCjZcrMjA8N9R1pjMFRe44dLsck5FzLilOYvcXuDn93B+bpGYyufc70gQ==} dev: false /emoji-regex@8.0.0: @@ -3268,7 +3281,11 @@ packages: engines: {node: '>=10'} dev: false +<<<<<<< Updated upstream /eslint-config-next@14.0.4(eslint@8.56.0)(typescript@5.3.3): +======= + /eslint-config-next@14.0.4(eslint@8.56.0)(typescript@5.3.2): +>>>>>>> Stashed changes resolution: {integrity: sha512-9/xbOHEQOmQtqvQ1UsTQZpnA7SlDMBtuKJ//S4JnoyK3oGLhILKXdBgu/UO7lQo/2xOykQULS1qQ6p2+EpHgAQ==} peerDependencies: eslint: ^7.23.0 || ^8.0.0 @@ -3279,7 +3296,11 @@ packages: dependencies: '@next/eslint-plugin-next': 14.0.4 '@rushstack/eslint-patch': 1.6.1 +<<<<<<< Updated upstream '@typescript-eslint/parser': 6.14.0(eslint@8.56.0)(typescript@5.3.3) +======= + '@typescript-eslint/parser': 6.14.0(eslint@8.56.0)(typescript@5.3.2) +>>>>>>> Stashed changes eslint: 8.56.0 eslint-import-resolver-node: 0.3.9 eslint-import-resolver-typescript: 3.6.1(@typescript-eslint/parser@6.14.0)(eslint-import-resolver-node@0.3.9)(eslint-plugin-import@2.29.1)(eslint@8.56.0) @@ -3287,7 +3308,11 @@ packages: eslint-plugin-jsx-a11y: 6.8.0(eslint@8.56.0) eslint-plugin-react: 7.33.2(eslint@8.56.0) eslint-plugin-react-hooks: 4.6.0(eslint@8.56.0) +<<<<<<< Updated upstream typescript: 5.3.3 +======= + typescript: 5.3.2 +>>>>>>> Stashed changes transitivePeerDependencies: - eslint-import-resolver-webpack - supports-color @@ -3347,7 +3372,11 @@ packages: eslint-import-resolver-webpack: optional: true dependencies: +<<<<<<< Updated upstream '@typescript-eslint/parser': 6.14.0(eslint@8.56.0)(typescript@5.3.3) +======= + '@typescript-eslint/parser': 6.14.0(eslint@8.56.0)(typescript@5.3.2) +>>>>>>> Stashed changes debug: 3.2.7(supports-color@8.1.1) eslint: 8.56.0 eslint-import-resolver-node: 0.3.9 @@ -3366,7 +3395,11 @@ packages: '@typescript-eslint/parser': optional: true dependencies: +<<<<<<< Updated upstream '@typescript-eslint/parser': 6.14.0(eslint@8.56.0)(typescript@5.3.3) +======= + '@typescript-eslint/parser': 6.14.0(eslint@8.56.0)(typescript@5.3.2) +>>>>>>> Stashed changes array-includes: 3.1.7 array.prototype.findlastindex: 1.2.3 array.prototype.flat: 1.3.2 @@ -5398,8 +5431,8 @@ packages: resolution: {integrity: sha512-zrceR/XhGYU/d/opr2EKO7aRHUeiBI8qjtfHqADTwZd6Szfy16la6kqD0MIUs5z5hx6AaKa+PixpPrR289+I0A==} dev: false - /regenerator-runtime@0.14.0: - resolution: {integrity: sha512-srw17NI0TUWHuGa5CFGGmhfNIeja30WMBfbslPNhf6JrqQlLN5gcrvig1oqPxiVaXb0oW0XRKtH6Nngs5lKCIA==} + /regenerator-runtime@0.14.1: + resolution: {integrity: sha512-dYnhHh0nJoMfnkZs6GmmhFknAGRrLznOu5nc9ML+EJxGvrx6H7teuevqVqCuPcPK//3eDrrjQhehXVx9cnkGdw==} dev: false /regenerator-transform@0.15.2: diff --git a/src/pages/api/timetable/getTimetable.ts b/src/pages/api/timetable/getTimetable.ts deleted file mode 100644 index a3dcad7..0000000 --- a/src/pages/api/timetable/getTimetable.ts +++ /dev/null @@ -1,61 +0,0 @@ -import fetchTimetable from "@/utils/fetchTimetable"; -import NodeCache from "node-cache"; -import { NextApiRequest, NextApiResponse } from "next"; -import { timetableApiType } from "@/types/api"; - -const cache = new NodeCache({ stdTTL: 5400 }); - -export default async function handler( - req: NextApiRequest, - res: NextApiResponse -) { - try { - let id = req?.query?.id?.toString(); - - if (!id) { - id = "o1"; - } - - const cachedData: timetableApiType = cache.get(id); - if (cachedData) { - return res.status(200).send(cachedData); - } - - const { data: timetableList, ok, err } = await fetchTimetable(id); - - if (!ok) { - switch (err.response.status) { - case 404: - return res.status(404).send({ - success: false, - msg: `No data found with id (${id})`, - }); - default: - return res.status(500).send({ - success: false, - msg: `Timetable returned status other than 200 (${err.response.status})`, - }); - } - } - - const timeTableObj: timetableApiType = { - title: timetableList.getTitle(), - days: timetableList.getDayNames(), - generatedDate: timetableList.getGeneratedDate(), - validDate: timetableList.getVersionInfo(), - lessons: timetableList.getDays(), - hours: timetableList.getHours(), - }; - - cache.set(id, timeTableObj); - - res.status(200).send(timeTableObj); - } catch (error) { - console.log(error); - res.status(500).send({ - success: false, - msg: "An error occurred", - err: error.message, - }); - } -} diff --git a/src/pages/api/timetable/list.ts b/src/pages/api/timetable/list.ts deleted file mode 100644 index 8995cc1..0000000 --- a/src/pages/api/timetable/list.ts +++ /dev/null @@ -1,58 +0,0 @@ -import fetchTimetableList from "@/utils/fetchTimetableList"; -import { NextApiRequest, NextApiResponse } from "next"; -import NodeCache from "node-cache"; - -const cache = new NodeCache({ stdTTL: 5400 }); - -export default async function handler( - req: NextApiRequest, - res: NextApiResponse -) { - try { - const cacheKey: string = req?.query?.select.toString() || "default"; - - const cachedData = cache.get(cacheKey); - if (cachedData) { - return res.status(200).send(cachedData); - } - - const { data, ok, err } = await fetchTimetableList(); - if (!ok) { - return res.status(500).send({ - success: false, - msg: `Timetable returned status other than 200 (${err.response.status})`, - }); - } - - const { classes, teachers, rooms } = data; - - let responseObj = { success: true, classes, teachers, rooms }; - switch (req.query.select) { - case "classes": - responseObj.classes = classes; - break; - case "teachers": - responseObj.teachers = teachers; - break; - case "rooms": - responseObj.rooms = rooms; - break; - default: - responseObj.classes = classes; - responseObj.teachers = teachers; - responseObj.rooms = rooms; - break; - } - - cache.set(cacheKey, responseObj); - - res.status(200).send(responseObj); - } catch (error) { - console.log(error); - res.status(500).send({ - success: false, - msg: "An error occurred", - err: error.message, - }); - } -} diff --git a/src/pages/zastepstwa.tsx b/src/pages/zastepstwa.tsx index eff6500..7b4efd1 100644 --- a/src/pages/zastepstwa.tsx +++ b/src/pages/zastepstwa.tsx @@ -13,13 +13,13 @@ import Snow from "@/components/SnowEasteregg"; import { GetStaticProps } from "next"; import { load } from "cheerio"; -export default function Home({ ...props }) { - const [checkedTeachers, setCheckedTeachers] = useState([]); - const [checkedBranches, setCheckedBranches] = useState([]); - const handleCheckboxChange = (checkedItems) => { +export default function Home({ ...props }: any) { + const [checkedTeachers, setCheckedTeachers] = useState([]); + const [checkedBranches, setCheckedBranches] = useState([]); + const handleCheckboxChange = (checkedItems: any[]) => { setCheckedTeachers(checkedItems); }; - const handleCheckboxChangeBranch = (checkedItems) => { + const handleCheckboxChangeBranch = (checkedItems: any[]) => { setCheckedBranches(checkedItems); }; @@ -76,7 +76,7 @@ export default function Home({ ...props }) { ); } -export const getStaticProps: GetStaticProps = async (context) => { +export const getStaticProps: GetStaticProps = async () => { try { const response = await axios.get( "http://kristofc.webd.pro/plan/InformacjeOZastepstwach.html" @@ -86,11 +86,11 @@ export const getStaticProps: GetStaticProps = async (context) => { const time = $("h2").text().trim(); const tables: tables[] = []; - $("table").each((index, table) => { + $("table").each((_index, table) => { const rows = $(table).find("tr"); const zastepstwa: substitutions[] = []; - rows.slice(1).each((i, row) => { + rows.slice(1).each((_i, row) => { const columns = $(row).find("td"); const [ lesson, @@ -100,7 +100,7 @@ export const getStaticProps: GetStaticProps = async (context) => { classValue, caseValue, message, - ] = columns.map((index, column) => $(column).text().trim()).get(); + ] = columns.map((_index, column) => $(column).text().trim()).get(); if (lesson) { zastepstwa.push({