Skip to content

Commit

Permalink
Add active subjects as suggestions when creating a time entry.
Browse files Browse the repository at this point in the history
  • Loading branch information
manud99 committed Oct 16, 2023
1 parent edafcb2 commit 3667c71
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 16 deletions.
1 change: 1 addition & 0 deletions src/components/SelectField.vue
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ function onInputUpdate(event: Event) {
'focus:outline-none focus:ring-2 ring-blue-700',
]"
title="Auswahl löschen"
type="button"
@click="emit('update:value', '')"
>
<IconCross :size="16" />
Expand Down
52 changes: 52 additions & 0 deletions src/components/SelectSubjectField.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<script lang="ts" setup>
import { computed, onMounted } from "vue";
import SelectField, { Option } from "./SelectField.vue";
import SubjectTag from "../blocks/SubjectTag.vue";
import { getSubjects, subjects } from "../utils/subjects";
import { Subject } from "../@types/models";
const props = defineProps<{
value: string;
name: string;
label: string;
}>();
const emit = defineEmits<{
(e: "update:value", value: string): void;
}>();
onMounted(() => {
getSubjects();
});
const subjectOptions = computed(() => {
return subjects.value.map((subject): Option => ({ label: subject.name, value: subject.name }));
});
const activeSubjects = computed(() => {
return subjects.value.filter((subject) => subject.isActive);
});
function selectSubject(subject: Subject) {
emit("update:value", subject.name);
}
</script>

<template>
<div class="flex flex-wrap gap-4 mb-2">
<SubjectTag
v-for="subject in activeSubjects"
class="cursor-pointer"
:subject="subject"
@click="selectSubject(subject)"
/>
</div>
<SelectField
:value="value"
@update:value="emit('update:value', $event)"
:options="subjectOptions"
name="subject"
label="Fach auswählen"
clearable
/>
</template>
18 changes: 2 additions & 16 deletions src/modals/EditTimeEntryModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import Modal from "../components/Modal.vue";
import FormGroup from "../components/FormGroup.vue";
import InputField from "../components/InputField.vue";
import DatePicker from "../components/DatePicker.vue";
import SelectField, { Option } from "../components/SelectField.vue";
import SelectSubjectField from "../components/SelectSubjectField.vue";
import TimeField from "../components/TimeField.vue";
import { getSubject, getSubjects, subjects } from "../utils/subjects";
import { timeEntries } from "../utils/timeEntries";
Expand Down Expand Up @@ -98,14 +98,6 @@ watch([date, start, end], () => {
dateEnd.value = new CustomDate(dateObj);
});
onMounted(() => {
getSubjects();
});
const subjectOptions = computed(() => {
return subjects.value.map((subject): Option => ({ label: subject.name, value: subject.name }));
});
const newEntry = computed(() => !timeEntry.value);
async function submitTimeEntry() {
Expand Down Expand Up @@ -162,13 +154,7 @@ async function submitTimeEntry() {
<InputField v-model:value="description" name="description" label="Beschreibung" autofocus />
</FormGroup>
<FormGroup label="Fach" name="subject" :errors="validationErrors">
<SelectField
v-model:value="subject"
:options="subjectOptions"
name="subject"
label="Fach auswählen"
clearable
/>
<SelectSubjectField v-model:value="subject" name="subject" label="Fach" />
</FormGroup>
</Modal>
</template>

0 comments on commit 3667c71

Please sign in to comment.