Preserve focused person across tree/people/detail navigation
The Tree view, People (Family) view, and person detail page each tracked the "current person" independently, so moving between them reset you to the home person. The detail page's "← Back to tree" link also pointed at the People view (not the Tree) and carried no person, so it always landed on the default person. Make the focused person a URL-encoded concept that travels across views: - Tree and People views read ?focus=<id> on load and mirror the focused person back into the URL via router.replace (no history spam), so leaving and returning keeps you centered where you were. Bookmarks/shared links also resolve to the right person. - "Open person" links carry ?from=tree | ?from=people. - The detail page's back link is now origin-aware: "← Back to Tree" → /tree?focus=<id> or "← Back to People" → /?focus=<id>, returning you in place instead of to the home person. - Add a "View in tree →" link on the detail page — the previously missing direct jump from a person to the tree re-rooted on them. - person→person relationship links (and create-relative redirect) pass `from` through so click-chains keep their anchor. Also gitignore *.tsbuildinfo (Next build artifact). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Signed-off-by: Justin Paul <justin@jpaul.me>
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
"use client";
|
||||
|
||||
import Link from "next/link";
|
||||
import { useParams, useRouter } from "next/navigation";
|
||||
import { useParams, useRouter, useSearchParams } from "next/navigation";
|
||||
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
||||
|
||||
import { api } from "@/lib/api/client";
|
||||
@@ -104,8 +104,19 @@ function parseDateValue(v: string | null | undefined) {
|
||||
export default function PersonDetailPage() {
|
||||
const router = useRouter();
|
||||
const params = useParams<{ id: string; personId: string }>();
|
||||
const searchParams = useSearchParams();
|
||||
const treeId = params.id;
|
||||
const personId = params.personId;
|
||||
// Where we were opened from, so "back" returns there (centered on this
|
||||
// person) instead of always dumping onto the People view's home person.
|
||||
const from = searchParams.get("from") === "people" ? "people" : "tree";
|
||||
const backHref =
|
||||
from === "people"
|
||||
? `/trees/${treeId}?focus=${personId}`
|
||||
: `/trees/${treeId}/tree?focus=${personId}`;
|
||||
const backLabel = from === "people" ? "← Back to People" : "← Back to Tree";
|
||||
// Carry the origin through person→person links so the chain keeps its anchor.
|
||||
const personHref = (id: string) => `/trees/${treeId}/persons/${id}?from=${from}`;
|
||||
|
||||
const [person, setPerson] = useState<Person | null>(null);
|
||||
const [people, setPeople] = useState<Person[]>([]);
|
||||
@@ -385,7 +396,7 @@ export default function PersonDetailPage() {
|
||||
});
|
||||
if (!data) return;
|
||||
await linkRelative(data.id);
|
||||
router.push(`/trees/${treeId}/persons/${data.id}`);
|
||||
router.push(personHref(data.id));
|
||||
}
|
||||
async function removeRel(id: string) {
|
||||
await api.DELETE("/api/v1/trees/{tree_id}/relationships/{relationship_id}", {
|
||||
@@ -624,7 +635,7 @@ export default function PersonDetailPage() {
|
||||
<ul className="mt-1 space-y-1">
|
||||
{items.map((r) => (
|
||||
<li key={r.id} className="flex items-center justify-between text-sm">
|
||||
<Link href={`/trees/${treeId}/persons/${otherId(r)}`} className="hover:underline">
|
||||
<Link href={personHref(otherId(r))} className="hover:underline">
|
||||
{nameOf(otherId(r))}
|
||||
{r.qualifier ? <span className="text-[var(--muted)]"> · {r.qualifier}</span> : null}
|
||||
</Link>
|
||||
@@ -643,9 +654,17 @@ export default function PersonDetailPage() {
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<Link href={`/trees/${treeId}`} className="text-sm text-[var(--muted)] hover:underline">
|
||||
← Back to tree
|
||||
</Link>
|
||||
<div className="flex items-center justify-between gap-3">
|
||||
<Link href={backHref} className="text-sm text-[var(--muted)] hover:underline">
|
||||
{backLabel}
|
||||
</Link>
|
||||
<Link
|
||||
href={`/trees/${treeId}/tree?focus=${personId}`}
|
||||
className="text-sm text-bronze hover:underline"
|
||||
>
|
||||
View in tree →
|
||||
</Link>
|
||||
</div>
|
||||
|
||||
{editingPerson ? (
|
||||
<form
|
||||
|
||||
Reference in New Issue
Block a user