diff --git a/src/lib/components/timetable/TimetableCell.svelte b/src/lib/components/timetable/TimetableCell.svelte new file mode 100644 index 0000000..4f4831e --- /dev/null +++ b/src/lib/components/timetable/TimetableCell.svelte @@ -0,0 +1,45 @@ + + + + { + $timetable[day][lessonIndex] = detail; + }} + on:enter={async () => { + const isOnlyNull = getLastLessons($timetable).every((x) => x === null); + const hasLessons = countMaxLessons($timetable) > 0; + if (!(isOnlyNull && hasLessons)) { + timetable.update(addRow); + await asyncRequestAnimationFrame(); + } + + const nextEle = elements[`${lessonIndex + 1}-${dayIndex}`]; + if (!nextEle) return; + + nextEle.focus(); + }} + bind:element={elements[`${lessonIndex}-${dayIndex}`]} + /> + diff --git a/src/lib/components/timetable/TimetableRow.svelte b/src/lib/components/timetable/TimetableRow.svelte new file mode 100644 index 0000000..12a77e0 --- /dev/null +++ b/src/lib/components/timetable/TimetableRow.svelte @@ -0,0 +1,22 @@ + + +{#each WEEKDAYS as _, ind} + {@const day = WEEKDAYS[(ind + $weekStartsOn) % 7]} + {@const show = $showWeekend ? true : !(day === 'sat' || day === 'sun')} + + {#if show} + + {/if} +{/each} diff --git a/src/routes/settings/timetable/+page.svelte b/src/routes/settings/timetable/+page.svelte index 25d6010..9aca343 100644 --- a/src/routes/settings/timetable/+page.svelte +++ b/src/routes/settings/timetable/+page.svelte @@ -6,7 +6,6 @@ removeNthLesson, cleanUpTimeTable } from '$lib/components/settings/timetable/utils'; - import TextInput from '$lib/components/input/Text.svelte'; import QuickAction from '$lib/components/buttons/QuickAction.svelte'; import Store from '$lib/components/utils/Store.svelte'; import { i } from '$lib/i18n/store'; @@ -22,7 +21,7 @@ import { WEEKDAYS } from '$lib/components/settings/timetable/weekdays'; import BoolSetting from '$lib/components/settings/BoolSetting.svelte'; import { settingsHeader } from '$lib/stores'; - import { asyncRequestAnimationFrame } from '$lib/utils/dom'; + import TimetableRow from '$lib/components/timetable/TimetableRow.svelte'; const timetable = svocal('settings.timetable'); const weekStartsOn = svocal('settings.weekStartsOn'); @@ -34,8 +33,6 @@ timetable.update(cleanUpTimeTable); }); - const currentWeekday = WEEKDAYS[new Date().getDay()]; - settingsHeader.set(i('settings.timetable.title')); let elements: Record = {}; @@ -102,42 +99,7 @@ /> - {#each WEEKDAYS as _, ind} - {@const day = WEEKDAYS[(ind + $weekStartsOn) % 7]} - {@const isToday = currentWeekday === day} - {@const show = $showWeekend ? true : !(day === 'sat' || day === 'sun')} - - {#if show} - - { - $timetable[day][lessonIndex] = detail; - }} - on:enter={async () => { - const isOnlyNull = getLastLessons($timetable).every((x) => x === null); - const hasLessons = countMaxLessons($timetable) > 0; - if (!(isOnlyNull && hasLessons)) { - timetable.update(addRow); - await asyncRequestAnimationFrame(); - } - - const nextEle = elements[`${lessonIndex + 1}-${ind}`]; - if (!nextEle) return; - - nextEle.focus(); - }} - bind:element={elements[`${lessonIndex}-${ind}`]} - /> - - {/if} - {/each} + {/each} @@ -147,9 +109,7 @@ icon={Plus} disabled={getLastLessons($timetable).every((x) => x === null) && countMaxLessons($timetable) > 0} - on:click={() => { - timetable.update(addRow); - }} + on:click={() => timetable.update(addRow)} />