fix editing ande remove events in listview

This commit is contained in:
Tim Gröger 2023-05-03 00:09:21 +02:00
parent 7ea5a8fac3
commit b5d43bb1de
3 changed files with 14 additions and 16 deletions

View File

@ -138,6 +138,7 @@ export default defineComponent({
},
emits: {
done: (val: boolean) => typeof val === 'boolean',
'update:modelValue': (val?: FG.Event) => typeof val === 'object',
},
setup(props, { emit }) {
const store = useEventStore();
@ -208,7 +209,8 @@ export default defineComponent({
async function save(is_template = false) {
event.value.is_template = is_template;
try {
await store.addEvent(event.value);
const _event = await store.addEvent(event.value);
emit('update:modelValue', _event);
if (props.modelValue === undefined && recurrent.value && !event.value.is_template) {
let count = 0;

View File

@ -28,7 +28,7 @@
<q-separator />
<q-item-label header>{{ asDate(index) }}</q-item-label>
<q-item v-for="(event, idx) in events" :key="idx">
<event-slot :model-value="event" />
<event-slot v-model="events[idx]" @edit-event="edit" @remove-event="remove" />
</q-item>
</template>
</q-list>
@ -88,6 +88,10 @@ export default defineComponent({
function editDone(changed: boolean) {
//if (changed) void loadAgendas();
const idx = events.value.findIndex((event) => event.id === editor.value?.id);
if (idx >= 0) {
events.value[idx] = editor.value as FG.Event;
}
editor.value = undefined;
}
@ -117,17 +121,11 @@ export default defineComponent({
async function remove(id: number) {
if (await store.removeEvent(id)) {
// Successfull removed
for (const idx in agendas.value) {
const i = agendas.value[idx].findIndex((event) => event.id === id);
if (i !== -1) {
agendas.value[idx].splice(i, 1);
break;
const idx = events.value.findIndex((event) => event.id === id);
if (idx !== -1) {
events.value.splice(idx, 1);
}
}
} else {
// Not found, this means our eventa are outdated
}
}
function asMonth(value: string) {

View File

@ -150,15 +150,13 @@ export const useEventStore = defineStore({
if (event?.id === undefined) {
const { data } = await api.post<FG.Event>('/events', event);
if (data.is_template) this.templates.push(data);
fixEvent(data);
return data;
} else {
if (typeof event.type === 'object') event.type = event.type.id;
const { data } = await api.put<FG.Event>(
`/events/${event.id}`,
// Object.assign(event, { jobs: undefined })
event
);
const { data } = await api.put<FG.Event>(`/events/${event.id}`, event);
if (data.is_template) this.templates.push(data);
fixEvent(data);
return data;
}
},