Repository navigation
Expand file tree
/
Copy pathquoted-commit.tsx
More file actions
120 lines (115 loc) · 4.26 KB
/
Copy pathquoted-commit.tsx
File metadata and controls
120 lines (115 loc) · 4.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
import { Link } from '@inertiajs/react';
import CommitController from '@/actions/App/Http/Controllers/CommitController';
import CommitLinkPreviewController from '@/actions/App/Http/Controllers/CommitLinkPreviewController';
import { AuthorAvatar } from '@/components/author-avatar';
import { CommitBodyExcerpt } from '@/components/commit-body';
import { CommitImages } from '@/components/commit-images';
import { CommitPoll } from '@/components/commit-poll';
import { CommitStatusBadge } from '@/components/commit-status-badge';
import { LinkPreview } from '@/components/link-preview';
import { LinkTopicFooter } from '@/components/link-topic-footer';
import { useNow } from '@/hooks/use-now';
import {
cn,
formatFullDateTime,
formatRelativeTime,
isDeleted,
} from '@/lib/utils';
import type { DeletedCommit, QuotedCommit as QuotedCommitData } from '@/types';
export function QuotedCommit({
commit,
isPreview = false,
label = 'Quoting',
}: {
commit: QuotedCommitData | DeletedCommit | null;
isPreview?: boolean;
label?: string;
}) {
const now = useNow();
if (commit === null || isDeleted(commit)) {
return (
<p
className="mt-2 flex items-baseline gap-1.5 rounded-lg border border-dashed px-3 py-2 text-sm text-muted-foreground"
data-test="quoted-commit-tombstone"
>
<span className="font-mono text-xs">
{commit === null ? '[unavailable]' : '[deleted]'}
</span>
{commit === null
? "This commit isn't available."
: 'This commit was deleted.'}
</p>
);
}
const className = 'mt-2 block rounded-lg border px-3 py-2';
const content = (
<>
<span className="flex min-w-0 items-center gap-1.5 text-sm">
<span className="sr-only">{label}</span>
<AuthorAvatar author={commit.author} className="size-5" />
<span className="truncate font-semibold">
{commit.author.name}
</span>
<span className="truncate font-mono text-xs text-muted-foreground">
@{commit.author.handle}
</span>
<span aria-hidden className="text-muted-foreground">
·
</span>
<time
dateTime={commit.created_at}
title={formatFullDateTime(commit.created_at)}
className="shrink-0 font-mono text-xs text-muted-foreground"
>
{formatRelativeTime(commit.created_at, now)}
</time>
<CommitStatusBadge commit={commit} size="small" isStatic />
</span>
<CommitBodyExcerpt
segments={commit.body_segments}
previewSegments={commit.preview_segments}
className="mt-1 max-h-60"
/>
{commit.images && <CommitImages images={commit.images} />}
{commit.poll && (
<CommitPoll commit={commit} poll={commit.poll} isStatic />
)}
{commit.link_preview && (
<LinkPreview
refreshUrl={CommitLinkPreviewController.show.url(commit.id)}
preview={commit.link_preview}
isStatic
source={{ commitId: commit.id }}
footer={
commit.link_topic && (
<LinkTopicFooter
topic={commit.link_topic}
isStatic
/>
)
}
/>
)}
</>
);
if (isPreview) {
return (
<div className={className} data-test="quoted-commit">
{content}
</div>
);
}
return (
<Link
prefetch
href={CommitController.show({ profile: commit.author, commit })}
className={cn(
className,
'transition-colors hover:bg-accent focus-visible:bg-accent',
)}
data-test="quoted-commit"
>
{content}
</Link>
);
}