owltide/components/DiffFieldEntityId.vue
Hornwitser 1d2edf7535 Add dialog showing diff of changes to save
Add a save dialog at the bottom of the screen that is present whenever
there are unsaved changes.  This dialog provides a diff between the
client and server state so that the user can easily confirm the changes
they are about to make are the correct changes before applying them to
the server.
2025-06-30 15:43:15 +02:00

43 lines
1 KiB
Vue

<template>
<DiffEntry
v-if='state !== "modified" || after !== before'
:title
:entries
/>
</template>
<script lang="ts" setup>
import type { ApiEntity } from '~/shared/types/api';
import type { Id } from '~/shared/types/common';
import type { ClientEntity } from '~/utils/client-entity';
const props = defineProps<{
title: string,
before: Id | undefined,
after: Id | undefined,
entities: ClientMap<ClientEntity<ApiEntity> & { name?: string }>,
state: "deleted" | "created" | "modified",
}>();
function getName(id?: Id) {
if (id === undefined)
return undefined;
const entity = props.entities.get(id);
if (entity?.name !== undefined)
return entity.name;
return String(id);
}
const entries = computed(() => {
const result: ["removed" | "added", string][] = [];
const beforeName = getName(props.before);
if (props.state !== "created" && beforeName) {
result.push(["removed", beforeName]);
}
const afterName = getName(props.after);
if (props.state !== "deleted" && afterName) {
result.push(["added", afterName]);
}
return result;
})
</script>