fix(notes): type emit calls in NoteConflictModal

Vue's defineEmits generates per-event overloads, so emit(action) with
a union of literal types failed to type-check. Split the single
choose() helper into one handler per action.
This commit is contained in:
Julien Calixte
2026-05-25 21:27:48 +02:00
parent 54c52feeba
commit 299493854e

View File

@@ -4,10 +4,10 @@ import { onMounted, ref, watch } from "vue"
const props = defineProps<{ open: boolean }>() const props = defineProps<{ open: boolean }>()
const emit = defineEmits<{ const emit = defineEmits<{
(e: "discard"): void discard: []
(e: "overwrite"): void overwrite: []
(e: "cancel"): void cancel: []
(e: "update:open", value: boolean): void "update:open": [value: boolean]
}>() }>()
const dialogRef = ref<HTMLDialogElement | null>(null) const dialogRef = ref<HTMLDialogElement | null>(null)
@@ -17,8 +17,16 @@ const close = () => {
emit("update:open", false) emit("update:open", false)
} }
const choose = (action: "discard" | "overwrite" | "cancel") => { const onDiscard = () => {
emit(action) emit("discard")
close()
}
const onOverwrite = () => {
emit("overwrite")
close()
}
const onCancel = () => {
emit("cancel")
close() close()
} }
@@ -42,7 +50,7 @@ onMounted(() => {
ref="dialogRef" ref="dialogRef"
class="modal" class="modal"
@close="emit('update:open', false)" @close="emit('update:open', false)"
@cancel.prevent="choose('cancel')" @cancel.prevent="onCancel()"
> >
<div class="modal-box"> <div class="modal-box">
<h3 class="text-lg font-bold">GitHub has a newer version of this note</h3> <h3 class="text-lg font-bold">GitHub has a newer version of this note</h3>
@@ -55,28 +63,28 @@ onMounted(() => {
<button <button
type="button" type="button"
class="btn btn-ghost" class="btn btn-ghost"
@click="choose('cancel')" @click="onCancel()"
> >
Cancel Cancel
</button> </button>
<button <button
type="button" type="button"
class="btn btn-warning" class="btn btn-warning"
@click="choose('overwrite')" @click="onOverwrite()"
> >
Save anyway (overwrite) Save anyway (overwrite)
</button> </button>
<button <button
type="button" type="button"
class="btn btn-primary" class="btn btn-primary"
@click="choose('discard')" @click="onDiscard()"
> >
Discard my edits, pull latest Discard my edits, pull latest
</button> </button>
</div> </div>
</div> </div>
<form method="dialog" class="modal-backdrop"> <form method="dialog" class="modal-backdrop">
<button type="submit" @click="choose('cancel')">close</button> <button type="submit" @click="onCancel()">close</button>
</form> </form>
</dialog> </dialog>
</template> </template>