Skip to content

Commit c6ac00e

Browse files
authored
Merge pull request #92 from bfritscher/fix-search-delete-refresh
feat: enhance search result item deletion with event emission and error handling fix #91
2 parents 1258005 + 84cc6e9 commit c6ac00e

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

src/components/search/SearchInstantSearch.vue

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,10 @@
5353
<ais-pagination class="q-mb-md" />
5454
<ais-hits>
5555
<template v-if="currentCollection" #item="{ item }">
56-
<search-result-item :item="item"></search-result-item>
56+
<search-result-item
57+
:item="item"
58+
@deleted="instantSearchInstance.refresh()"
59+
></search-result-item>
5760
</template>
5861
</ais-hits>
5962
<ais-pagination class="q-my-md" />

src/components/search/SearchResultItem.vue

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ import SearchResultItemNestedDisplay from './SearchResultItemNestedDisplay.vue';
4747
const props = defineProps<{
4848
item?: Record<string, any>;
4949
}>();
50+
const emit = defineEmits<(e: 'deleted', id: string) => void>();
5051
5152
const store = useNodeStore();
5253
const $q = useQuasar();
@@ -83,7 +84,17 @@ const deleteDocumentById = (id: string) => {
8384
cancel: true,
8485
persistent: true,
8586
}).onOk(() => {
86-
void store.deleteDocumentById(id);
87+
store
88+
.deleteDocumentById(id)
89+
?.then(() => {
90+
emit('deleted', id);
91+
})
92+
.catch((error: Error) => {
93+
$q.notify({
94+
type: 'negative',
95+
message: `Error deleting document: ${error.message}`,
96+
});
97+
});
8798
});
8899
};
89100
</script>

src/stores/node.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -476,12 +476,11 @@ export const useNodeStore = defineStore('node', {
476476
await this.api?.deleteOverride(this.currentCollection.name, id);
477477
void this.getOverrides(this.currentCollection.name);
478478
},
479-
async deleteDocumentById(id: string) {
479+
deleteDocumentById(id: string) {
480480
if (!this.currentCollection) {
481481
throw new Error('No collection selected');
482482
}
483-
void (await this.api?.deleteDocumentById(this.currentCollection.name, id));
484-
// TODO refresh
483+
return this.api?.deleteDocumentById(this.currentCollection.name, id);
485484
},
486485
search(payload: SearchParams) {
487486
return (this.api as Api)?.search(

0 commit comments

Comments
 (0)