Skip to content

Commit b029e5d

Browse files
committed
refactor: simplify navigation in PersonDetails and EventDetails components
1 parent a8db04e commit b029e5d

2 files changed

Lines changed: 14 additions & 42 deletions

File tree

src/features/event/EventDetails.tsx

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, { useMemo, useState, useEffect } from "react";
2-
import { Link, useNavigate } from "react-router";
2+
import { Link } from "react-router";
33
import {
44
BookmarkIcon as BookmarkOutline,
55
ArrowLeftIcon,
@@ -26,11 +26,9 @@ export default function EventDetails({
2626
conference: HTConference;
2727
people: HTPerson[];
2828
}) {
29-
const nav = useNavigate();
3029
const zone = event.timeZone;
3130
const locale = undefined;
3231
const confCode = conference.code;
33-
const backLink = `/schedule?conf=${confCode}`;
3432

3533
const [bookmark, setBookmark] = useState<boolean>(() =>
3634
loadConfBookmarks(confCode).has(event.id)
@@ -47,11 +45,6 @@ export default function EventDetails({
4745
[event.color]
4846
);
4947

50-
const handleBack = () => {
51-
if (backLink) nav(backLink);
52-
else nav(-1);
53-
};
54-
5548
const handleShare = async () => {
5649
const url = `/event?conf=${confCode}&event=${event.id}`;
5750
try {
@@ -111,13 +104,13 @@ export default function EventDetails({
111104
>
112105
{/* Header actions */}
113106
<div className="mb-6 flex items-start justify-between gap-3">
114-
<button
115-
onClick={handleBack}
116-
className="inline-flex items-center gap-2 rounded-lg border border-gray-700/70 bg-gray-900/20 px-3 py-2 text-sm transition-colors duration-200 hover:bg-gray-900 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-indigo-500 focus-visible:ring-offset-2 focus-visible:ring-offset-gray-900"
107+
<Link
108+
to={`/schedule?conf=${encodeURIComponent(confCode)}`}
109+
className="inline-flex items-center gap-2 rounded-lg border border-gray-700 px-3 py-2 text-sm text-gray-200 hover:bg-gray-900 focus:outline-none focus:ring-2 focus:ring-indigo-500"
117110
>
118-
<ArrowLeftIcon className="h-5 w-5" />
119-
<span className="hidden sm:inline">Back</span>
120-
</button>
111+
<ArrowLeftIcon className="h-5 w-5" aria-hidden="true" />
112+
<span className="sr-only md:not-sr-only">Schedule</span>
113+
</Link>
121114

122115
<div className="flex items-center gap-2">
123116
<button

src/features/person/PersonDetails.tsx

Lines changed: 7 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,7 @@ import {
66
MapPinIcon,
77
CalendarDaysIcon,
88
} from "@heroicons/react/24/outline";
9-
import type { HTEvent, HTPerson } from "@/types/db";
10-
11-
/** Types (match your data) */
12-
export type PersonLink = {
13-
title: string;
14-
url: string;
15-
sort_order?: number | null;
16-
};
17-
export type PersonEvent = {
18-
id: number | string;
19-
title: string;
20-
begin: string | number | Date;
21-
end: string | number | Date;
22-
location?: { name?: string | null } | string | null;
23-
content_id: number | string;
24-
color?: string | null;
25-
};
26-
export type Affiliation = {
27-
organization?: string | null;
28-
title?: string | null;
29-
};
9+
import type { HTConference, HTEvent, HTPerson } from "@/types/db";
3010

3111
/** ---------- utilities ---------- */
3212

@@ -75,12 +55,11 @@ function nonEmpty<T>(x: T | null | undefined): x is T {
7555
/** ---------- component ---------- */
7656

7757
export default function PersonDetails({
78-
confCode,
58+
conference,
7959
person,
8060
events,
81-
timeZone, // optional: pass conference TZ like "America/Los_Angeles"
8261
}: {
83-
confCode: string;
62+
conference: HTConference;
8463
person: HTPerson;
8564
events: HTEvent[];
8665
timeZone?: string;
@@ -131,11 +110,11 @@ export default function PersonDetails({
131110

132111
{/* Back to People */}
133112
<Link
134-
to={`/people?conf=${encodeURIComponent(confCode)}`}
113+
to={`/people?conf=${encodeURIComponent(conference.code)}`}
135114
className="inline-flex items-center gap-2 rounded-lg border border-gray-700 px-3 py-2 text-sm text-gray-200 hover:bg-gray-900 focus:outline-none focus:ring-2 focus:ring-indigo-500"
136115
>
137116
<ArrowLeftIcon className="h-5 w-5" aria-hidden="true" />
138-
<span className="sr-only md:not-sr-only">Back</span>
117+
<span className="sr-only md:not-sr-only">People</span>
139118
</Link>
140119
</div>
141120

@@ -206,13 +185,13 @@ export default function PersonDetails({
206185
</h2>
207186
<ul role="list" className="space-y-4">
208187
{sortedEvents.map((e) => {
209-
const when = fmtTimeRange(e.begin, e.end, timeZone);
188+
const when = fmtTimeRange(e.begin, e.end, conference.timezone);
210189
const where = getLocationName(e.location);
211190
const id = String(e.id);
212191
return (
213192
<li key={`${id}-${e.title}`}>
214193
<Link
215-
to={`/event?conf=${encodeURIComponent(confCode)}&event=${encodeURIComponent(
194+
to={`/event?conf=${encodeURIComponent(conference.code)}&event=${encodeURIComponent(
216195
id
217196
)}`}
218197
className="group block rounded-xl border border-gray-700 bg-gray-700/60 transition hover:bg-gray-600/60 focus:outline-none focus:ring-2 focus:ring-indigo-500"

0 commit comments

Comments
 (0)