From 3ddf325c030ce0960890513c7002953c14e79e9d Mon Sep 17 00:00:00 2001 From: Francesco Baldino Date: Mon, 16 Oct 2023 10:34:51 +0200 Subject: [PATCH] prototipo eventi custom --- package.json | 3 +- pnpm-lock.yaml | 8 ++++ src/components/SettingsBar.jsx | 10 +++++ src/components/Toolbar.jsx | 8 ++-- src/components/view/Courses.jsx | 34 ++++++++++----- src/components/view/Schedule.jsx | 16 +++---- src/main.jsx | 64 +++++++++++++++++++++------- src/styles/main.scss | 23 ++++++++++- src/utils.jsx | 71 +++++++++++++++++++++++++++----- 9 files changed, 184 insertions(+), 53 deletions(-) diff --git a/package.json b/package.json index fb5bcca..a9917c4 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,8 @@ "lodash-es": "^4.17.21", "preact": "^10.10.6", "sass": "^1.54.8", - "vite": "^3.0.9" + "vite": "^3.0.9", + "yaml": "^2.3.2" }, "devDependencies": { "@babel/core": "^7.18.13", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 43b5c75..d082d0b 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -23,6 +23,9 @@ dependencies: vite: specifier: ^3.0.9 version: 3.0.9(sass@1.54.8) + yaml: + specifier: ^2.3.2 + version: 2.3.2 devDependencies: '@babel/core': @@ -937,3 +940,8 @@ packages: sass: 1.54.8 optionalDependencies: fsevents: 2.3.2 + + /yaml@2.3.2: + resolution: {integrity: sha512-N/lyzTPaJasoDmfV7YTrYCI0G/3ivm/9wdG0aHuheKowWQwGTsK0Eoiw6utmzAnI6pkJa0DUVygvp3spqqEKXg==} + engines: {node: '>= 14'} + dev: false diff --git a/src/components/SettingsBar.jsx b/src/components/SettingsBar.jsx index b4ad60e..6b415e1 100644 --- a/src/components/SettingsBar.jsx +++ b/src/components/SettingsBar.jsx @@ -15,6 +15,16 @@ export const SettingsBar = ({ theme, setTheme, date, setDate }) => { name={theme === 'dark' ? 'dark_mode' : 'light_mode'} /> + diff --git a/src/components/Toolbar.jsx b/src/components/Toolbar.jsx index 278897a..7f4f931 100644 --- a/src/components/Toolbar.jsx +++ b/src/components/Toolbar.jsx @@ -36,6 +36,7 @@ export const Toolbar = ({ { value: 'anno-3', label: 'III' }, { value: 'magistrale', label: 'Magistrale' }, { value: 'tutti', label: 'Tutti' }, + { value: 'custom', label: 'Custom' }, ]} value={source} setValue={setSource} @@ -51,9 +52,10 @@ export const Toolbar = ({ setValue={setSource} /> - -
- +
+
+ +
diff --git a/src/components/view/Courses.jsx b/src/components/view/Courses.jsx index ecd921b..0fbd78b 100644 --- a/src/components/view/Courses.jsx +++ b/src/components/view/Courses.jsx @@ -2,7 +2,7 @@ import { format } from 'date-fns' import _ from 'lodash' import { useEffect, useRef, useState } from 'preact/hooks' -import { prettyCourseName, WEEK_DAYS } from '../../utils.jsx' +import { parseCustomEvents, prettyCourseName, WEEK_DAYS } from '../../utils.jsx' import { Icon } from '../Icon.jsx' export const Courses = ({ @@ -10,13 +10,18 @@ export const Courses = ({ timetables, selection, setSelection, - hideOtherCourses, + custom, + isRestrictedList, }) => { - const events = timetables[source] + const events = isRestrictedList ? timetables['tutti'] : timetables[source] const selectionSet = new Set(selection) - const visibleEvents = hideOtherCourses - ? events.filter(e => selectionSet.has(e.id)) + console.log(events) + + const visibleEvents = isRestrictedList + ? events + .filter(e => selectionSet.has(e.id)) + .concat(parseCustomEvents(custom)) : events const eventsByCourse = _.groupBy(_.sortBy(visibleEvents, 'id'), 'id') @@ -53,7 +58,7 @@ export const Courses = ({ return (
- {hideOtherCourses && selection.length === 0 && ( + {isRestrictedList && selection.length === 0 && (

Non hai ancora selezionato nessun corso.

@@ -67,11 +72,16 @@ export const Courses = ({

{ + if (isRestrictedList) return if (!selectionSet.has(id)) setSelection([...selection, id]) else @@ -89,9 +99,11 @@ export const Courses = ({
{courseEvents.map(course => (
- {WEEK_DAYS[course.start.getDay()]}{' '} - {format(course.start, 'H:mm')}– - {format(course.end, 'H:mm')}{' '} + {WEEK_DAYS[course.day]} {course.start / 60}: + {String(course.start % 60).padStart(2, '0')} + – + {course.end / 60}: + {String(course.end % 60).padStart(2, '0')}{' '} {course.aule.join(', ')}
))} diff --git a/src/components/view/Schedule.jsx b/src/components/view/Schedule.jsx index 22eddc4..6830bba 100644 --- a/src/components/view/Schedule.jsx +++ b/src/components/view/Schedule.jsx @@ -1,7 +1,9 @@ import { useEffect, useRef, useState } from 'preact/hooks' -import _ from 'lodash' +import _, { parseInt } from 'lodash' import { differenceInMinutes, startOfDay } from 'date-fns' +import { parse } from 'yaml' +import { parseCustomEvents } from '../../utils.jsx' import { WEEK_DAYS_SHORT, @@ -210,7 +212,7 @@ const ScheduleCard = ({ ) } -export const Schedule = ({ timetables, selection }) => { +export const Schedule = ({ timetables, selection, custom }) => { const [hasSeenTranspose, setHasSeenTranspose] = usePersistentState( 'transpose_info', 'false' @@ -232,14 +234,8 @@ export const Schedule = ({ timetables, selection }) => { const allEvents = timetables['tutti'] const selectionSet = new Set(selection) - const events = allEvents - .filter(e => selectionSet.has(e.id)) - .map(e => ({ - ...e, - day: e.start.getDay(), - start: differenceInMinutes(e.start, startOfDay(e.start)), - end: differenceInMinutes(e.end, startOfDay(e.start)), - })) + const events = allEvents.filter(e => selectionSet.has(e.id)) + parseCustomEvents(custom).forEach(event => events.push(event)) const weekStart = Math.min(...events.map(e => e.start), 9 * 60) / 30 const weekEnd = Math.max(...events.map(e => e.end), 18 * 60) / 30 diff --git a/src/main.jsx b/src/main.jsx index c9c2667..3b9dd5f 100644 --- a/src/main.jsx +++ b/src/main.jsx @@ -1,6 +1,7 @@ import _ from 'lodash' import { render } from 'preact' import { useEffect, useState } from 'preact/hooks' +import { differenceInMinutes, startOfDay } from 'date-fns' // import { ToolOverlay } from './components/ToolOverlay.jsx' // @@ -18,12 +19,7 @@ import { Icon } from './components/Icon.jsx' import { Popup } from './components/Popup.jsx' import { Toolbar } from './components/Toolbar.jsx' import { OptionBar } from './components/OptionBar.jsx' -import { - prettyAulaName, - prettyProfName, - clearOldPersistentStates, - usePersistentState, -} from './utils.jsx' +import { prettyAulaName, prettyProfName, usePersistentState } from './utils.jsx' import { SettingsBar } from './components/SettingsBar.jsx' // Che fanno queste due righe? @@ -67,11 +63,14 @@ function specialEventPatches(eventi) { function formatEvents(timetable) { return timetable.map(({ nome, dataInizio, dataFine, docenti, aule }) => { + const start = new Date(dataInizio) + const end = new Date(dataFine) return { id: nome, name: _.split(nome, '-', 1)[0].trim(), - start: new Date(dataInizio), - end: new Date(dataFine), + day: start.getDay(), + start: differenceInMinutes(start, startOfDay(start)), + end: differenceInMinutes(end, startOfDay(start)), docenti: docenti.map(({ nome, cognome }) => prettyProfName(nome, cognome) ), @@ -142,19 +141,50 @@ async function loadCalendari(date) { } } -const View = ({ view, selection, setSelection, timetables }) => { +const View = ({ + view, + selection, + setSelection, + timetables, + custom, + setCustom, +}) => { if (view === 'orario') { - return + return ( + + ) } else if (view === 'lista') { return ( ) + } else if (view === 'custom') { + return ( +
+