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:
@@ -3,7 +3,7 @@ import { enhance } from '$app/forms';
|
|||||||
import { m } from '$lib/paraglide/messages.js';
|
import { m } from '$lib/paraglide/messages.js';
|
||||||
import RelationshipChip from '$lib/components/RelationshipChip.svelte';
|
import RelationshipChip from '$lib/components/RelationshipChip.svelte';
|
||||||
import AddRelationshipForm from '$lib/components/AddRelationshipForm.svelte';
|
import AddRelationshipForm from '$lib/components/AddRelationshipForm.svelte';
|
||||||
import { inferredRelationshipLabel } from '$lib/relationshipLabels';
|
import { chipLabel, otherName, inferredRelationshipLabel } from '$lib/relationshipLabels';
|
||||||
import type { components } from '$lib/generated/api';
|
import type { components } from '$lib/generated/api';
|
||||||
|
|
||||||
type RelationshipDTO = components['schemas']['RelationshipDTO'];
|
type RelationshipDTO = components['schemas']['RelationshipDTO'];
|
||||||
@@ -53,34 +53,6 @@ function relationTypeOrder(t: RelationType | undefined): number {
|
|||||||
return order[t ?? 'OTHER'] ?? 99;
|
return order[t ?? 'OTHER'] ?? 99;
|
||||||
}
|
}
|
||||||
|
|
||||||
function chipLabel(rel: RelationshipDTO): string {
|
|
||||||
const viewpointIsSubject = rel.personId === personId;
|
|
||||||
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 === personId ? rel.relatedPersonDisplayName : rel.personDisplayName;
|
|
||||||
}
|
|
||||||
|
|
||||||
function yearRange(rel: RelationshipDTO): string {
|
function yearRange(rel: RelationshipDTO): string {
|
||||||
const from = rel.fromYear;
|
const from = rel.fromYear;
|
||||||
const to = rel.toYear;
|
const to = rel.toYear;
|
||||||
@@ -155,8 +127,8 @@ function yearRange(rel: RelationshipDTO): string {
|
|||||||
<ul class="mb-2 divide-y divide-line">
|
<ul class="mb-2 divide-y divide-line">
|
||||||
{#each sortedDirect as rel (rel.id)}
|
{#each sortedDirect as rel (rel.id)}
|
||||||
<RelationshipChip
|
<RelationshipChip
|
||||||
chipLabel={chipLabel(rel)}
|
chipLabel={chipLabel(rel, personId)}
|
||||||
otherName={otherName(rel)}
|
otherName={otherName(rel, personId)}
|
||||||
yearRange={yearRange(rel)}
|
yearRange={yearRange(rel)}
|
||||||
canWrite={canWrite}
|
canWrite={canWrite}
|
||||||
relId={rel.id}
|
relId={rel.id}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
import { onMount } from 'svelte';
|
import { onMount } from 'svelte';
|
||||||
import { invalidateAll } from '$app/navigation';
|
import { invalidateAll } from '$app/navigation';
|
||||||
import { m } from '$lib/paraglide/messages.js';
|
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 PersonTypeahead from '$lib/components/PersonTypeahead.svelte';
|
||||||
import type { components } from '$lib/generated/api';
|
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) {
|
function handleEscape(event: KeyboardEvent) {
|
||||||
if (event.key === 'Escape') onClose();
|
if (event.key === 'Escape') onClose();
|
||||||
}
|
}
|
||||||
@@ -194,10 +166,10 @@ const topDerived = $derived(
|
|||||||
<span
|
<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"
|
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>
|
||||||
<span class="min-w-0 flex-1 truncate font-serif text-xs text-ink">
|
<span class="min-w-0 flex-1 truncate font-serif text-xs text-ink">
|
||||||
{otherName(rel)}
|
{otherName(rel, node.id)}
|
||||||
</span>
|
</span>
|
||||||
</li>
|
</li>
|
||||||
{/each}
|
{/each}
|
||||||
|
|||||||
Reference in New Issue
Block a user