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

View File

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

View File

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