🚸 Improve UX in timetable editor

This commit is contained in:
2023-06-20 15:25:16 +02:00
parent 76b7946b13
commit 1bfd156a03
4 changed files with 16 additions and 7 deletions

View File

@ -2,7 +2,7 @@
import { getSubstitutionColor } from "@/util"; import { getSubstitutionColor } from "@/util";
import { times } from "@/store"; import { times } from "@/store";
import { ref, watch } from "vue"; import { ref, watch } from "vue";
import { TrashIcon } from "lucide-vue-next"; import { MinusIcon } from "lucide-vue-next";
const props = defineProps(["lesson", "index", "edit", "buttons"]); const props = defineProps(["lesson", "index", "edit", "buttons"]);
const emit = defineEmits(["change", "delete"]); const emit = defineEmits(["change", "delete"]);
@ -84,6 +84,7 @@ function getTime(index) {
spellcheck="false" spellcheck="false"
data-ph="Subject" data-ph="Subject"
ref="subjectElement" ref="subjectElement"
@keydown.enter.prevent
@input="update" @input="update"
> >
{{ lesson.subject }} {{ lesson.subject }}
@ -102,6 +103,7 @@ function getTime(index) {
spellcheck="false" spellcheck="false"
data-ph="Teacher" data-ph="Teacher"
ref="teacherElement" ref="teacherElement"
@keydown.enter.prevent
@input="update" @input="update"
> >
{{ lesson.teacher }}</span {{ lesson.teacher }}</span
@ -118,6 +120,7 @@ function getTime(index) {
spellcheck="false" spellcheck="false"
data-ph="Room" data-ph="Room"
ref="roomElement" ref="roomElement"
@keydown.enter.prevent
@input="update" @input="update"
>{{ lesson.room }}</span >{{ lesson.room }}</span
></span ></span
@ -133,7 +136,7 @@ function getTime(index) {
<span>{{ getTime(index).end }}</span> <span>{{ getTime(index).end }}</span>
</div> </div>
<div class="buttons" v-if="edit && buttons"> <div class="buttons" v-if="edit && buttons">
<TrashIcon @click="$emit('delete')" /> <MinusIcon @click="$emit('delete')" />
</div> </div>
</div> </div>
</template> </template>
@ -190,6 +193,9 @@ function getTime(index) {
cursor: pointer; cursor: pointer;
} }
[contenteditable="true"]:focus {
padding: 0px 5px;
}
[contenteditable="true"]:empty:before { [contenteditable="true"]:empty:before {
content: attr(data-ph); content: attr(data-ph);
opacity: 0.4; opacity: 0.4;

View File

@ -6,7 +6,7 @@ import {
ArrowDownIcon, ArrowDownIcon,
SettingsIcon, SettingsIcon,
TrashIcon, TrashIcon,
PlusIcon, ListPlusIcon,
} from "lucide-vue-next"; } from "lucide-vue-next";
const props = defineProps(["lesson", "index", "edit"]); const props = defineProps(["lesson", "index", "edit"]);
@ -43,19 +43,20 @@ function lessonChanged(index, data) {
function lessonDeleted(index) { function lessonDeleted(index) {
let newLesson = structuredClone(toRaw(props.lesson)); let newLesson = structuredClone(toRaw(props.lesson));
newLesson.splice(index, 1); newLesson.splice(index, 1);
if (newLesson.length == 1) delete newLesson[0].group;
if (newLesson.length == 0) emit("delete"); if (newLesson.length == 0) emit("delete");
else emit("change", newLesson); else emit("change", newLesson);
} }
</script> </script>
<template> <template>
<div class="lessonList"> <div class="lessonList" :key="lesson.length">
<div class="buttons" v-if="edit"> <div class="buttons" v-if="edit">
<ArrowUpIcon @click="$emit('move', 'up')" /> <ArrowUpIcon @click="$emit('move', 'up')" />
<ArrowDownIcon @click="$emit('move', 'down')" /> <ArrowDownIcon @click="$emit('move', 'down')" />
<SettingsIcon @click="advancedOptions = !advancedOptions" /> <SettingsIcon @click="advancedOptions = !advancedOptions" />
<TrashIcon @click="$emit('delete')" /> <TrashIcon @click="$emit('delete')" />
<PlusIcon @click="appendOption" /> <ListPlusIcon @click="appendOption" />
</div> </div>
<LessonCard <LessonCard
v-for="(option, groupIndex) in lesson" v-for="(option, groupIndex) in lesson"
@ -92,7 +93,8 @@ function lessonDeleted(index) {
opacity: 0.7; opacity: 0.7;
cursor: pointer; cursor: pointer;
display: flex; display: flex;
gap: 3px; gap: 5px;
padding: 3px 0px;
} }
input { input {

View File

@ -224,7 +224,7 @@ export const possibleTimetableGroups = computed(() => {
// found in the current timetable // found in the current timetable
for (const day of timetable.value.data) { for (const day of timetable.value.data) {
for (const lesson of day) { for (const lesson of day) {
if (Array.isArray(lesson)) { if (Array.isArray(lesson) && lesson.length > 1) {
for (const group of lesson) { for (const group of lesson) {
if (group.group && !foundTimetableGroups.includes(group.group)) { if (group.group && !foundTimetableGroups.includes(group.group)) {
foundTimetableGroups.push(group.group); foundTimetableGroups.push(group.group);

View File

@ -33,6 +33,7 @@ function importTimetable(event) {
if (!data.data) throw "Invalid data"; if (!data.data) throw "Invalid data";
localTimetables.value.push(data); localTimetables.value.push(data);
} catch (e) { } catch (e) {
console.log(e.stack);
alert("Import failed! Check your timetable file!"); alert("Import failed! Check your timetable file!");
} }
}; };