refactor(stammbaum): use shared chipLabel/otherName from relationshipLabels in both components
Addresses @felix blocker: removes the verbatim duplicate switch+2-line helper from StammbaumCard.svelte and StammbaumSidePanel.svelte; both now import from the shared $lib/relationshipLabels helper. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
import { onMount } from 'svelte';
|
||||
import { invalidateAll } from '$app/navigation';
|
||||
import { m } from '$lib/paraglide/messages.js';
|
||||
import { inferredRelationshipLabel } from '$lib/relationshipLabels';
|
||||
import { chipLabel, otherName, inferredRelationshipLabel } from '$lib/relationshipLabels';
|
||||
import PersonTypeahead from '$lib/components/PersonTypeahead.svelte';
|
||||
import type { components } from '$lib/generated/api';
|
||||
|
||||
@@ -120,34 +120,6 @@ async function submitAdd(event: Event) {
|
||||
}
|
||||
}
|
||||
|
||||
function chipLabel(rel: RelationshipDTO): string {
|
||||
const viewpointIsSubject = rel.personId === node.id;
|
||||
switch (rel.relationType) {
|
||||
case 'PARENT_OF':
|
||||
return viewpointIsSubject ? m.relation_parent_of() : m.relation_child_of();
|
||||
case 'SPOUSE_OF':
|
||||
return m.relation_spouse_of();
|
||||
case 'SIBLING_OF':
|
||||
return m.relation_sibling_of();
|
||||
case 'FRIEND':
|
||||
return m.relation_friend();
|
||||
case 'COLLEAGUE':
|
||||
return m.relation_colleague();
|
||||
case 'EMPLOYER':
|
||||
return m.relation_employer();
|
||||
case 'DOCTOR':
|
||||
return m.relation_doctor();
|
||||
case 'NEIGHBOR':
|
||||
return m.relation_neighbor();
|
||||
default:
|
||||
return m.relation_other();
|
||||
}
|
||||
}
|
||||
|
||||
function otherName(rel: RelationshipDTO): string {
|
||||
return rel.personId === node.id ? rel.relatedPersonDisplayName : rel.personDisplayName;
|
||||
}
|
||||
|
||||
function handleEscape(event: KeyboardEvent) {
|
||||
if (event.key === 'Escape') onClose();
|
||||
}
|
||||
@@ -194,10 +166,10 @@ const topDerived = $derived(
|
||||
<span
|
||||
class="inline-flex shrink-0 items-center rounded-full border border-accent/40 bg-accent/15 px-2 py-0.5 font-sans text-xs font-bold tracking-widest text-ink uppercase"
|
||||
>
|
||||
{chipLabel(rel)}
|
||||
{chipLabel(rel, node.id)}
|
||||
</span>
|
||||
<span class="min-w-0 flex-1 truncate font-serif text-xs text-ink">
|
||||
{otherName(rel)}
|
||||
{otherName(rel, node.id)}
|
||||
</span>
|
||||
</li>
|
||||
{/each}
|
||||
|
||||
Reference in New Issue
Block a user