Skip to content

Commit ab461e0

Browse files
fix(web): guard clipboard, size the status span, finish <time> sweep
navigator.clipboard is undefined outside secure contexts and reading .writeText off it throws synchronously, before a .catch() could run, so the failure toast never fired there. One copyWithToast helper guards it and replaces the two duplicated promise chains on ProjectDetail. ProfileEdit's always-mounted status span reserved mt-1 even while empty; the margin now applies only when it has text. Three relative timestamps were still title-only: HelpWantedCard's "posted", PersonDetail's "joined" and its recent-update dates. They get the same <time dateTime title> treatment as the rest of the sweep. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RdRwHvDupRLV8GuJpYKzEr
1 parent 0628779 commit ab461e0

4 files changed

Lines changed: 55 additions & 20 deletions

File tree

‎apps/web/src/components/HelpWantedCard.tsx‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { PersonAvatar } from '@/components/PersonAvatar';
66
import { MarkdownView } from '@/components/MarkdownView';
77
import { ExpressInterestModal } from '@/components/modals/ExpressInterestModal';
88
import { useAuth } from '@/hooks/useAuth';
9-
import { formatRelativeTime } from '@/lib/time';
9+
import { formatAbsoluteDate, formatRelativeTime } from '@/lib/time';
1010
import type { HelpWantedRoleResponse } from '@/lib/api';
1111

1212
interface HelpWantedCardProps {
@@ -64,7 +64,12 @@ export function HelpWantedCard({ role, showProjectLink = true }: HelpWantedCardP
6464
<span>·</span>
6565
</>
6666
)}
67-
<span>posted {formatRelativeTime(role.createdAt)}</span>
67+
<span>
68+
posted{' '}
69+
<time dateTime={role.createdAt} title={formatAbsoluteDate(role.createdAt)}>
70+
{formatRelativeTime(role.createdAt)}
71+
</time>
72+
</span>
6873
</div>
6974

7075
{isSignedIn ? (

‎apps/web/src/screens/PersonDetail.tsx‎

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { TagChip } from '@/components/TagChip';
1919
import { PersonAvatar } from '@/components/PersonAvatar';
2020
import { useAuth } from '@/hooks/useAuth';
2121
import { api, ApiError } from '@/lib/api';
22-
import { formatMonthYear, formatRelativeTime } from '@/lib/time';
22+
import { formatAbsoluteDate, formatMonthYear, formatRelativeTime } from '@/lib/time';
2323

2424
export function PersonDetail() {
2525
const params = useParams();
@@ -181,7 +181,10 @@ export function PersonDetail() {
181181
)}
182182
</div>
183183
<span className="text-xs text-muted-foreground shrink-0">
184-
joined {formatRelativeTime(m.joinedAt)}
184+
joined{' '}
185+
<time dateTime={m.joinedAt} title={formatAbsoluteDate(m.joinedAt)}>
186+
{formatRelativeTime(m.joinedAt)}
187+
</time>
185188
</span>
186189
</li>
187190
))}
@@ -202,9 +205,13 @@ export function PersonDetail() {
202205
>
203206
{u.project.title} · Update #{u.number}
204207
</Link>
205-
<span className="text-xs text-muted-foreground">
208+
<time
209+
dateTime={u.createdAt}
210+
title={formatAbsoluteDate(u.createdAt)}
211+
className="text-xs text-muted-foreground"
212+
>
206213
{formatRelativeTime(u.createdAt)}
207-
</span>
214+
</time>
208215
</div>
209216
<div className="line-clamp-3 text-sm">
210217
<MarkdownView html={u.bodyHtml} />

‎apps/web/src/screens/ProfileEdit.tsx‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,13 @@ export function ProfileEdit() {
211211
className="block"
212212
/>
213213
{/* role="status" so the upload's progress is announced rather
214-
than only appearing next to the file input. */}
215-
<span role="status" className="block mt-1 text-xs text-muted-foreground">
214+
than only appearing next to the file input. The span stays
215+
mounted so the live region exists before its text changes;
216+
the margin applies only while it has something to show. */}
217+
<span
218+
role="status"
219+
className={avatarUploading ? 'block mt-1 text-xs text-muted-foreground' : 'block'}
220+
>
216221
{avatarUploading ? 'Uploading…' : ''}
217222
</span>
218223
</div>

‎apps/web/src/screens/ProjectDetail.tsx‎

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,24 @@ import { useAuth } from '@/hooks/useAuth';
3535
import { api, ApiError, type HelpWantedRoleResponse } from '@/lib/api';
3636
import { formatRelativeTime, formatAbsoluteDate } from '@/lib/time';
3737

38+
/**
39+
* Clipboard write with a toast either way. `navigator.clipboard` is
40+
* undefined outside secure contexts (plain-http dev hosts, some webviews),
41+
* and reading `.writeText` off it throws synchronously — before any
42+
* `.catch()` could see it — so the guard sits outside the promise chain.
43+
*/
44+
function copyWithToast(text: string, ok: string, fail: string) {
45+
const clipboard: Clipboard | undefined = navigator.clipboard;
46+
if (!clipboard) {
47+
toast.error(fail);
48+
return;
49+
}
50+
void clipboard
51+
.writeText(text)
52+
.then(() => toast.success(ok))
53+
.catch(() => toast.error(fail));
54+
}
55+
3856
interface ProjectDetailProps {
3957
anchor?: 'update' | 'buzz';
4058
}
@@ -560,12 +578,13 @@ export function ProjectDetail({ anchor }: ProjectDetailProps = {}) {
560578
action confirmations. */}
561579
<Button
562580
variant="outline"
563-
onClick={() => {
564-
void navigator.clipboard
565-
.writeText(`https://codeforphilly.org/projects/${slug}`)
566-
.then(() => toast.success('Link copied'))
567-
.catch(() => toast.error("Couldn't copy the link"));
568-
}}
581+
onClick={() =>
582+
copyWithToast(
583+
`https://codeforphilly.org/projects/${slug}`,
584+
'Link copied',
585+
"Couldn't copy the link",
586+
)
587+
}
569588
>
570589
Copy link
571590
</Button>
@@ -575,12 +594,11 @@ export function ProjectDetail({ anchor }: ProjectDetailProps = {}) {
575594
// Copy a pre-formatted Slack message. Spec calls this
576595
// out as either system-share or copy; copy works in every
577596
// browser context without a Web Share API gate.
578-
void navigator.clipboard
579-
.writeText(
580-
`Check out ${project.title} on Code for Philly: https://codeforphilly.org/projects/${slug}`,
581-
)
582-
.then(() => toast.success('Slack message copied'))
583-
.catch(() => toast.error("Couldn't copy the message"));
597+
copyWithToast(
598+
`Check out ${project.title} on Code for Philly: https://codeforphilly.org/projects/${slug}`,
599+
'Slack message copied',
600+
"Couldn't copy the message",
601+
);
584602
}}
585603
>
586604
Share to Slack

0 commit comments

Comments
 (0)