Skip to content

Commit f58f7b6

Browse files
Merge pull request #10 from enricobattocchi/fix/sync-document-title
fix: sync browser tab title when editing timeline name
2 parents 1932e9b + 7d2f220 commit f58f7b6

2 files changed

Lines changed: 13 additions & 9 deletions

File tree

src/components/Chooser/Chooser.tsx

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import type { Event, MarkerData, SegmentData } from "@/lib/types";
77
import { useSettings } from "@/hooks/useSettings";
88
import { useExport } from "@/hooks/useExport";
99
import { computeTimeline } from "@/lib/timeline-math";
10-
import { buildShareablePath } from "@/lib/custom-event-url";
10+
import { buildShareablePath, buildUrl } from "@/lib/custom-event-url";
1111
import EventAutocomplete from "./EventAutocomplete";
1212
import Timeline from "@/components/Timeline/Timeline";
1313
import EditableTitle from "@/components/EditableTitle";
@@ -23,14 +23,6 @@ interface ChooserProps {
2323
serverHideNow?: boolean;
2424
}
2525

26-
function buildUrl(path: string, title: string, hideNow: boolean): string {
27-
const params = new URLSearchParams();
28-
if (title) params.set("t", title);
29-
if (hideNow) params.set("now", "0");
30-
const qs = params.toString();
31-
return qs ? `${path}?${qs}` : path;
32-
}
33-
3426
export default function Chooser({
3527
selectedEvents,
3628
serverTimeline,
@@ -78,6 +70,7 @@ export default function Chooser({
7870
setTitle(newTitle);
7971
const path = selected.length > 0 ? `${localePath}${buildShareablePath(selected)}` : `${localePath}/`;
8072
window.history.replaceState(null, "", buildUrl(path, newTitle, hideNow));
73+
document.title = newTitle ? `${newTitle} | wiki:closerintime` : "wiki:closerintime";
8174
},
8275
[selected, hideNow, localePath]
8376
);

src/lib/custom-event-url.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,14 @@ export function buildShareablePath(events: Event[]): string {
1212
.sort();
1313
return "/" + segments.join("/");
1414
}
15+
16+
/**
17+
* Append optional query parameters (title, hideNow) to a path.
18+
*/
19+
export function buildUrl(path: string, title: string, hideNow: boolean): string {
20+
const params = new URLSearchParams();
21+
if (title) params.set("t", title);
22+
if (hideNow) params.set("now", "0");
23+
const qs = params.toString();
24+
return qs ? `${path}?${qs}` : path;
25+
}

0 commit comments

Comments
 (0)