diff --git a/package-lock.json b/package-lock.json index f2bf1e4a..9d4c1dd7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -111,6 +111,7 @@ "react-instantsearch-nextjs": "^0.2.4", "react-leaflet": "^4.2.1", "react-resizable-panels": "^2.0.11", + "react-swipeable": "^7.0.1", "react-transition-group": "^4.4.5", "recharts": "^2.12.7", "rxdb": "^15.11.1", @@ -15097,6 +15098,15 @@ } } }, + "node_modules/react-swipeable": { + "version": "7.0.1", + "resolved": "https://registry.npmjs.org/react-swipeable/-/react-swipeable-7.0.1.tgz", + "integrity": "sha512-RKB17JdQzvECfnVj9yDZsiYn3vH0eyva/ZbrCZXZR0qp66PBRhtg4F9yJcJTWYT5Adadi+x4NoG53BxKHwIYLQ==", + "license": "MIT", + "peerDependencies": { + "react": "^16.8.3 || ^17 || ^18" + } + }, "node_modules/react-transition-group": { "version": "4.4.5", "license": "BSD-3-Clause", diff --git a/package.json b/package.json index f9090a7e..0a1fde61 100644 --- a/package.json +++ b/package.json @@ -114,8 +114,8 @@ "qrcode.react": "^3.1.0", "query-string": "^8.1.0", "react": "18.3.1", - "react-color": "^2.19.3", "react-barcode": "^1.5.3", + "react-color": "^2.19.3", "react-cookie": "^7.1.0", "react-day-picker": "^8.10.1", "react-dom": "18.3.1", @@ -125,6 +125,7 @@ "react-instantsearch-nextjs": "^0.2.4", "react-leaflet": "^4.2.1", "react-resizable-panels": "^2.0.11", + "react-swipeable": "^7.0.1", "react-transition-group": "^4.4.5", "recharts": "^2.12.7", "rxdb": "^15.11.1", diff --git a/src/app/[lang]/(mods-pages)/timetable/page.tsx b/src/app/[lang]/(mods-pages)/timetable/page.tsx index b02be5ac..e6ec0fec 100644 --- a/src/app/[lang]/(mods-pages)/timetable/page.tsx +++ b/src/app/[lang]/(mods-pages)/timetable/page.tsx @@ -8,6 +8,8 @@ import { createTimetableFromCourses } from "@/helpers/timetable"; import { MinimalCourse } from "@/types/courses"; import { renderTimetableSlot } from "@/helpers/timetable_course"; import TimetableSidebar from "@/components/Timetable/TimetableSidebar"; +import { useSwipeable } from "react-swipeable"; +import { semesterInfo } from "@/const/semester"; const TimetablePage: NextPage = () => { const { getSemesterCourses, semester, setSemester, colorMap } = @@ -19,13 +21,32 @@ const TimetablePage: NextPage = () => { colorMap, ); + const handlers = useSwipeable({ + onSwipedLeft: (eventData) => { + const currentSemesterIndex = semesterInfo.findIndex( + (semObj) => semObj.id === semester, + ); + if (currentSemesterIndex < semesterInfo.length - 1) { + setSemester(semesterInfo[currentSemesterIndex + 1].id); + } + }, + onSwipedRight: (eventData) => { + const currentSemesterIndex = semesterInfo.findIndex( + (semObj) => semObj.id === semester, + ); + if (currentSemesterIndex > 0) { + setSemester(semesterInfo[currentSemesterIndex - 1].id); + } + }, + }); + return (