🐛 Fix bugs in timetable editor
- Turn off autocorrect / spellcheck - Prevent some browsers from jumping to the start of the text field - Correctly handle lesson lengths
This commit is contained in:
@ -1,23 +1,32 @@
|
|||||||
<script setup>
|
<script setup>
|
||||||
import { getSubstitutionColor } from "@/util";
|
import { getSubstitutionColor } from "@/util";
|
||||||
import { times } from "@/store";
|
import { times } from "@/store";
|
||||||
import { ref } from "vue";
|
import { ref, watch } from "vue";
|
||||||
import { TrashIcon } from "lucide-vue-next";
|
import { TrashIcon } 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"]);
|
||||||
|
|
||||||
|
// Only make the card reactive if not in edit mode
|
||||||
|
// to prevent some browsers to jump to the start
|
||||||
|
// of the text field on change
|
||||||
|
const lesson = ref(props.lesson);
|
||||||
|
watch(
|
||||||
|
() => props.lesson,
|
||||||
|
(value) => {
|
||||||
|
if (!props.edit) lesson.value = value;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
const subjectElement = ref();
|
const subjectElement = ref();
|
||||||
const teacherElement = ref();
|
const teacherElement = ref();
|
||||||
const roomElement = ref();
|
const roomElement = ref();
|
||||||
const lessonLength = ref(props.lesson.length || 1);
|
|
||||||
|
|
||||||
function update() {
|
function update() {
|
||||||
emit("change", {
|
emit("change", {
|
||||||
subject: subjectElement.value.innerText,
|
subject: subjectElement.value.innerText,
|
||||||
teacher: teacherElement.value.innerText,
|
teacher: teacherElement.value.innerText,
|
||||||
room: roomElement.value.innerText,
|
room: roomElement.value.innerText,
|
||||||
length: lessonLength.value,
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -71,6 +80,8 @@ function getTime(index) {
|
|||||||
class="subject"
|
class="subject"
|
||||||
v-else
|
v-else
|
||||||
:contenteditable="edit"
|
:contenteditable="edit"
|
||||||
|
autocorrect="false"
|
||||||
|
spellcheck="false"
|
||||||
data-ph="Subject"
|
data-ph="Subject"
|
||||||
ref="subjectElement"
|
ref="subjectElement"
|
||||||
@input="update"
|
@input="update"
|
||||||
@ -87,6 +98,8 @@ function getTime(index) {
|
|||||||
class="info"
|
class="info"
|
||||||
v-else
|
v-else
|
||||||
:contenteditable="edit"
|
:contenteditable="edit"
|
||||||
|
autocorrect="false"
|
||||||
|
spellcheck="false"
|
||||||
data-ph="Teacher"
|
data-ph="Teacher"
|
||||||
ref="teacherElement"
|
ref="teacherElement"
|
||||||
@input="update"
|
@input="update"
|
||||||
@ -101,6 +114,8 @@ function getTime(index) {
|
|||||||
>,
|
>,
|
||||||
<span
|
<span
|
||||||
:contenteditable="edit"
|
:contenteditable="edit"
|
||||||
|
autocorrect="false"
|
||||||
|
spellcheck="false"
|
||||||
data-ph="Room"
|
data-ph="Room"
|
||||||
ref="roomElement"
|
ref="roomElement"
|
||||||
@input="update"
|
@input="update"
|
||||||
|
@ -10,11 +10,11 @@ import {
|
|||||||
} from "lucide-vue-next";
|
} from "lucide-vue-next";
|
||||||
|
|
||||||
const props = defineProps(["lesson", "index", "edit"]);
|
const props = defineProps(["lesson", "index", "edit"]);
|
||||||
const emit = defineEmits(["change", "move"]);
|
const emit = defineEmits(["change", "move", "delete"]);
|
||||||
|
|
||||||
const advancedOptions = ref(false);
|
const advancedOptions = ref(false);
|
||||||
|
|
||||||
const lessonLength = ref(1);
|
const lessonLength = ref(props.lesson[0].length);
|
||||||
function updateLength() {
|
function updateLength() {
|
||||||
let newLesson = structuredClone(toRaw(props.lesson));
|
let newLesson = structuredClone(toRaw(props.lesson));
|
||||||
for (let entry of newLesson) {
|
for (let entry of newLesson) {
|
||||||
@ -33,6 +33,7 @@ function appendOption() {
|
|||||||
function lessonChanged(index, data) {
|
function lessonChanged(index, data) {
|
||||||
let newLesson = structuredClone(toRaw(props.lesson));
|
let newLesson = structuredClone(toRaw(props.lesson));
|
||||||
newLesson[index] = data;
|
newLesson[index] = data;
|
||||||
|
newLesson[index].length = lessonLength.value;
|
||||||
if (newLesson.length > 1)
|
if (newLesson.length > 1)
|
||||||
newLesson[index].group = `${data.subject}: ${data.teacher}`;
|
newLesson[index].group = `${data.subject}: ${data.teacher}`;
|
||||||
else delete newLesson[index].group;
|
else delete newLesson[index].group;
|
||||||
|
@ -47,6 +47,9 @@ function arrayMove(arr, fromIndex, toIndex) {
|
|||||||
arr.splice(fromIndex, 1);
|
arr.splice(fromIndex, 1);
|
||||||
arr.splice(toIndex, 0, element);
|
arr.splice(toIndex, 0, element);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Increment this variable to rerender all lesson lists
|
||||||
|
const forceUpdate = ref(0);
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
@ -70,7 +73,7 @@ function arrayMove(arr, fromIndex, toIndex) {
|
|||||||
>
|
>
|
||||||
<swiper-slide :key="day" v-for="day in 5">
|
<swiper-slide :key="day" v-for="day in 5">
|
||||||
<ScrollableContainer>
|
<ScrollableContainer>
|
||||||
<div class="list">
|
<div class="list" :key="forceUpdate">
|
||||||
<div
|
<div
|
||||||
class="lesson"
|
class="lesson"
|
||||||
v-for="(lesson, index) in timetableClone.data[day - 1]"
|
v-for="(lesson, index) in timetableClone.data[day - 1]"
|
||||||
@ -82,7 +85,12 @@ function arrayMove(arr, fromIndex, toIndex) {
|
|||||||
:lesson="lesson"
|
:lesson="lesson"
|
||||||
:edit="true"
|
:edit="true"
|
||||||
@change="(e) => (timetableClone.data[day - 1][index] = e)"
|
@change="(e) => (timetableClone.data[day - 1][index] = e)"
|
||||||
@delete="timetableClone.data[day - 1].splice(index, 1)"
|
@delete="
|
||||||
|
() => {
|
||||||
|
timetableClone.data[day - 1].splice(index, 1);
|
||||||
|
forceUpdate++;
|
||||||
|
}
|
||||||
|
"
|
||||||
@move="
|
@move="
|
||||||
(direction) => {
|
(direction) => {
|
||||||
if (direction == 'up' && index > 0) {
|
if (direction == 'up' && index > 0) {
|
||||||
@ -101,6 +109,7 @@ function arrayMove(arr, fromIndex, toIndex) {
|
|||||||
index + 1
|
index + 1
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
forceUpdate++;
|
||||||
}
|
}
|
||||||
"
|
"
|
||||||
/>
|
/>
|
||||||
|
Reference in New Issue
Block a user