@openpeepshq/react 0.6.0 → 0.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (95) hide show
  1. package/dist/components/index.d.ts +1 -0
  2. package/dist/components/index.js +1 -0
  3. package/dist/components/post/CompactReplyParent.js +8 -0
  4. package/dist/components/post/FeedPostContent.js +3 -0
  5. package/dist/components/post/NewResourceButton.d.ts +8 -0
  6. package/dist/components/post/NewResourceButton.js +36 -0
  7. package/dist/components/post/PostDetail.js +3 -0
  8. package/dist/components/post/index.d.ts +5 -0
  9. package/dist/components/post/index.js +3 -0
  10. package/dist/components/post/pieces/PostMenu.js +4 -0
  11. package/dist/components/post/post-form/PostTypeSwitcher.js +12 -2
  12. package/dist/components/post/post-form/ResourceForm.d.ts +7 -0
  13. package/dist/components/post/post-form/ResourceForm.js +68 -0
  14. package/dist/components/post/types/event/FullEvent.js +3 -1
  15. package/dist/components/post/types/resource/FullResource.d.ts +5 -0
  16. package/dist/components/post/types/resource/FullResource.js +99 -0
  17. package/dist/components/resources/CategoryPathPicker.d.ts +7 -0
  18. package/dist/components/resources/CategoryPathPicker.js +26 -0
  19. package/dist/components/resources/ResourceCard.d.ts +8 -0
  20. package/dist/components/resources/ResourceCard.js +121 -0
  21. package/dist/components/resources/ResourceLibrary.d.ts +4 -0
  22. package/dist/components/resources/ResourceLibrary.js +106 -0
  23. package/dist/components/resources/index.d.ts +6 -0
  24. package/dist/components/resources/index.js +3 -0
  25. package/dist/contexts/openpeeps/hooks/admin.d.ts +1064 -38
  26. package/dist/contexts/openpeeps/hooks/jams.d.ts +1064 -38
  27. package/dist/contexts/openpeeps/hooks/posts.d.ts +4508 -39936
  28. package/dist/hooks/events/useEventComposer.d.ts +1184 -44
  29. package/dist/hooks/events/useEventsCalendar.d.ts +2113 -61
  30. package/dist/hooks/index.d.ts +2 -0
  31. package/dist/hooks/index.js +2 -0
  32. package/dist/hooks/jams/useCreateNewJamForm.d.ts +39 -1
  33. package/dist/hooks/jams/useJamDetails.d.ts +1064 -38
  34. package/dist/hooks/jams/useJamRoom.d.ts +2113 -61
  35. package/dist/hooks/posts/useArticleComposer.d.ts +1184 -44
  36. package/dist/hooks/posts/useFeedPostPresentation.d.ts +2113 -61
  37. package/dist/hooks/posts/usePostDetailTitle.d.ts +1064 -38
  38. package/dist/hooks/posts/useResourceComposer.d.ts +12019 -0
  39. package/dist/hooks/posts/useResourceComposer.js +139 -0
  40. package/dist/hooks/resources/useResourceLibrary.d.ts +21880 -0
  41. package/dist/hooks/resources/useResourceLibrary.js +130 -0
  42. package/dist/hooks/settings/useNotificationPreferences.d.ts +1 -1
  43. package/dist/navigation/menuItems.js +5 -0
  44. package/dist/navigation/targets.d.ts +4 -0
  45. package/dist/pages/admin/analytics/Content.js +2 -1
  46. package/dist/pages/admin/analytics/Overview.js +15 -3
  47. package/dist/pages/groups/Show.js +7 -3
  48. package/dist/pages/index.d.ts +3 -0
  49. package/dist/pages/index.js +3 -0
  50. package/dist/pages/resources/Edit.d.ts +1 -0
  51. package/dist/pages/resources/Edit.js +26 -0
  52. package/dist/pages/resources/Index.d.ts +1 -0
  53. package/dist/pages/resources/Index.js +29 -0
  54. package/dist/pages/resources/New.d.ts +1 -0
  55. package/dist/pages/resources/New.js +15 -0
  56. package/dist/react-native.d.ts +1 -1
  57. package/dist/react-native.js +1 -1
  58. package/dist/stores/index.d.ts +1 -1
  59. package/dist/stores/index.js +1 -1
  60. package/dist/stores/newPosts.d.ts +79 -2
  61. package/dist/stores/newPosts.js +26 -2
  62. package/dist/stores/types.d.ts +2 -0
  63. package/package.json +6 -6
  64. package/src/components/index.ts +1 -0
  65. package/src/components/post/CompactReplyParent.tsx +8 -0
  66. package/src/components/post/FeedPostContent.tsx +3 -0
  67. package/src/components/post/NewResourceButton.tsx +75 -0
  68. package/src/components/post/PostDetail.tsx +3 -0
  69. package/src/components/post/index.ts +5 -0
  70. package/src/components/post/pieces/PostMenu.tsx +4 -0
  71. package/src/components/post/post-form/PostTypeSwitcher.tsx +19 -1
  72. package/src/components/post/post-form/ResourceForm.tsx +237 -0
  73. package/src/components/post/types/event/FullEvent.tsx +11 -3
  74. package/src/components/post/types/resource/FullResource.tsx +173 -0
  75. package/src/components/resources/CategoryPathPicker.tsx +95 -0
  76. package/src/components/resources/ResourceCard.tsx +335 -0
  77. package/src/components/resources/ResourceLibrary.tsx +374 -0
  78. package/src/components/resources/index.ts +6 -0
  79. package/src/contexts/openpeeps/hooks/posts.ts +11 -2
  80. package/src/hooks/index.ts +2 -0
  81. package/src/hooks/posts/useResourceComposer.ts +165 -0
  82. package/src/hooks/resources/useResourceLibrary.ts +156 -0
  83. package/src/navigation/menuItems.ts +6 -0
  84. package/src/navigation/targets.ts +1 -0
  85. package/src/pages/admin/analytics/Content.tsx +2 -1
  86. package/src/pages/admin/analytics/Overview.tsx +15 -3
  87. package/src/pages/groups/Show.tsx +30 -1
  88. package/src/pages/index.ts +3 -0
  89. package/src/pages/resources/Edit.tsx +73 -0
  90. package/src/pages/resources/Index.tsx +45 -0
  91. package/src/pages/resources/New.tsx +53 -0
  92. package/src/react-native.ts +1 -0
  93. package/src/stores/index.ts +1 -0
  94. package/src/stores/newPosts.ts +33 -2
  95. package/src/stores/types.ts +2 -0
@@ -0,0 +1,173 @@
1
+ import { Download, ExternalLink, Image as ImageIcon, Play } from 'lucide-react';
2
+ import { useState } from 'react';
3
+ import type { PublicPost } from '@openpeepshq/common/types';
4
+ import { attachmentMediaKind } from '@openpeepshq/common/lib';
5
+ import { useT } from '../../../../i18n';
6
+ import { FullPostLayout } from '../../FullPostLayout';
7
+ import { PostInfoHeader } from '../../pieces/PostInfoHeader';
8
+ import { PostMarkdown } from '../../Markdown';
9
+ import { ResourceCard } from '../../../resources/ResourceCard';
10
+ import { VideoPlayer } from '../../pieces/VideoPlayer';
11
+ import { AudioAttachment } from '../../pieces/AudioAttachment';
12
+ import { GalleryModal } from '../../pieces/GalleryModal';
13
+
14
+ export interface FullResourceProps {
15
+ post: PublicPost;
16
+ }
17
+
18
+ export const FullResource = ({ post }: FullResourceProps) => {
19
+ const t = useT();
20
+ const resource = post.data?.type === 'resource' ? post.data : null;
21
+ const [galleryIndex, setGalleryIndex] = useState<number | null>(null);
22
+ const [playerVisible, setPlayerVisible] = useState(false);
23
+
24
+ if (!resource) return null;
25
+
26
+ const handlePreviewClick = () => {
27
+ switch (resource.resourceKind) {
28
+ case 'video':
29
+ case 'audio':
30
+ setPlayerVisible(true);
31
+ break;
32
+ case 'gallery':
33
+ setGalleryIndex(0);
34
+ break;
35
+ case 'file': {
36
+ const att = resource.attachments?.find(
37
+ (a) => attachmentMediaKind(a) === 'file',
38
+ );
39
+ if (att?.url) window.open(att.url, '_blank');
40
+ break;
41
+ }
42
+ case 'link':
43
+ if (resource.url) window.open(resource.url, '_blank');
44
+ break;
45
+ default:
46
+ break;
47
+ }
48
+ };
49
+
50
+ const previewIcon = () => {
51
+ switch (resource.resourceKind) {
52
+ case 'video':
53
+ case 'audio':
54
+ return <Play className="size-12 text-white" />;
55
+ case 'gallery':
56
+ return <ImageIcon className="size-12 text-white" />;
57
+ case 'file':
58
+ return <Download className="size-12 text-white" />;
59
+ case 'link':
60
+ return <ExternalLink className="size-12 text-white" />;
61
+ default:
62
+ return null;
63
+ }
64
+ };
65
+
66
+ const previewLabel = () => {
67
+ switch (resource.resourceKind) {
68
+ case 'video':
69
+ return t('resources.actions.watch', { defaultValue: 'Play video' });
70
+ case 'audio':
71
+ return t('resources.actions.listen', {
72
+ defaultValue: 'Play audio',
73
+ });
74
+ case 'gallery':
75
+ return t('resources.actions.view', {
76
+ defaultValue: 'View images',
77
+ });
78
+ case 'file':
79
+ return t('resources.actions.download', {
80
+ defaultValue: 'Download',
81
+ });
82
+ case 'link':
83
+ return t('resources.actions.openLink', {
84
+ defaultValue: 'Open link',
85
+ });
86
+ default:
87
+ return '';
88
+ }
89
+ };
90
+
91
+ const renderMedia = () => {
92
+ if (resource.resourceKind === 'video' && playerVisible) {
93
+ const videoAtt = resource.attachments?.find(
94
+ (a) => attachmentMediaKind(a) === 'video',
95
+ );
96
+ if (videoAtt) {
97
+ return (
98
+ <ResourceCard
99
+ post={post}
100
+ preview={
101
+ <VideoPlayer
102
+ attachment={videoAtt}
103
+ className="max-h-[600px] w-full"
104
+ />
105
+ }
106
+ />
107
+ );
108
+ }
109
+ }
110
+
111
+ if (resource.resourceKind === 'audio' && playerVisible) {
112
+ const audioAtt = resource.attachments?.find(
113
+ (a) => attachmentMediaKind(a) === 'audio',
114
+ );
115
+ if (audioAtt?.url) {
116
+ return (
117
+ <ResourceCard
118
+ post={post}
119
+ preview={
120
+ <AudioAttachment
121
+ src={audioAtt.url}
122
+ label={audioAtt.filename ?? audioAtt.description}
123
+ size={audioAtt.meta?.size}
124
+ />
125
+ }
126
+ />
127
+ );
128
+ }
129
+ }
130
+
131
+ // All kinds: ResourceCard with click overlay
132
+ return (
133
+ <div className="relative">
134
+ <ResourceCard post={post} />
135
+ <div className="pointer-events-none absolute left-0 right-0 top-0 flex h-48 items-center justify-center">
136
+ <div
137
+ className="pointer-events-auto flex size-20 cursor-pointer items-center justify-center rounded-full bg-black/60 text-white"
138
+ onClick={handlePreviewClick}
139
+ role="button"
140
+ aria-label={previewLabel()}
141
+ >
142
+ {previewIcon()}
143
+ </div>
144
+ </div>
145
+ </div>
146
+ );
147
+ };
148
+
149
+ return (
150
+ <FullPostLayout post={post} deleteCallback={() => window.history.back()}>
151
+ <article className="bg-background border-border relative min-w-0 border-b p-4">
152
+ <PostInfoHeader
153
+ post={post}
154
+ showMenu
155
+ deleteCallback={() => window.history.back()}
156
+ />
157
+ <div className="flex w-full min-w-0 flex-col gap-3">
158
+ {renderMedia()}
159
+ {galleryIndex !== null ? (
160
+ <GalleryModal
161
+ attachments={resource.attachments ?? []}
162
+ initialIndex={galleryIndex}
163
+ onClose={() => setGalleryIndex(null)}
164
+ />
165
+ ) : null}
166
+ {resource?.content ? (
167
+ <PostMarkdown source={resource.content} />
168
+ ) : null}
169
+ </div>
170
+ </article>
171
+ </FullPostLayout>
172
+ );
173
+ };
@@ -0,0 +1,95 @@
1
+ import { useState } from 'react';
2
+ import type { CategoryNode } from '@openpeepshq/common/lib';
3
+ import { Button, Input } from '@openpeepshq/react-ui';
4
+ import { useT } from '../../i18n';
5
+
6
+ export interface CategoryPathPickerProps {
7
+ path: string[];
8
+ tree: CategoryNode[];
9
+ onChange: (path: string[]) => void;
10
+ }
11
+
12
+ const NodeList = ({
13
+ nodes,
14
+ selected,
15
+ onSelect,
16
+ }: {
17
+ nodes: CategoryNode[];
18
+ selected: string[];
19
+ onSelect: (path: string[]) => void;
20
+ }) => (
21
+ <ul className="border-border ml-3 border-l pl-3">
22
+ {nodes.map((node) => {
23
+ const active =
24
+ selected.length === node.path.length &&
25
+ node.path.every((segment, index) => selected[index] === segment);
26
+ return (
27
+ <li key={node.path.join('/')} className="py-0.5">
28
+ <button
29
+ type="button"
30
+ className={`text-sm ${active ? 'text-foreground font-semibold' : 'text-muted-foreground hover:text-foreground'}`}
31
+ onClick={() => onSelect(node.path)}
32
+ >
33
+ {node.name}
34
+ </button>
35
+ {node.children.length ? (
36
+ <NodeList
37
+ nodes={node.children}
38
+ selected={selected}
39
+ onSelect={onSelect}
40
+ />
41
+ ) : null}
42
+ </li>
43
+ );
44
+ })}
45
+ </ul>
46
+ );
47
+
48
+ export const CategoryPathPicker = ({
49
+ path,
50
+ tree,
51
+ onChange,
52
+ }: CategoryPathPickerProps) => {
53
+ const t = useT();
54
+ const [level, setLevel] = useState('');
55
+
56
+ return (
57
+ <div className="space-y-2">
58
+ <p className="text-muted-foreground text-sm">
59
+ {path.length
60
+ ? path.join(' / ')
61
+ : t('resources.form.uncategorized', {
62
+ defaultValue: 'Uncategorized',
63
+ })}
64
+ </p>
65
+ {tree.length ? (
66
+ <NodeList nodes={tree} selected={path} onSelect={onChange} />
67
+ ) : null}
68
+ <div className="flex gap-2">
69
+ <Input
70
+ value={level}
71
+ onChange={(event) => setLevel(event.target.value)}
72
+ placeholder={t('resources.form.addLevel', {
73
+ defaultValue: 'Add a folder',
74
+ })}
75
+ />
76
+ <Button
77
+ variant="outline"
78
+ action={() => {
79
+ const name = level.trim();
80
+ if (!name) return;
81
+ onChange([...path, name]);
82
+ setLevel('');
83
+ }}
84
+ >
85
+ {t('resources.form.addLevelAction', { defaultValue: 'Add' })}
86
+ </Button>
87
+ {path.length ? (
88
+ <Button variant="ghost" action={() => onChange([])}>
89
+ {t('resources.form.clearPath', { defaultValue: 'Clear' })}
90
+ </Button>
91
+ ) : null}
92
+ </div>
93
+ </div>
94
+ );
95
+ };
@@ -0,0 +1,335 @@
1
+ import { useMemo, useState } from 'react';
2
+ import type { ReactNode } from 'react';
3
+ import {
4
+ BookmarkCheck,
5
+ BookmarkPlus,
6
+ Link as LinkIcon,
7
+ ImageOff,
8
+ } from 'lucide-react';
9
+ import type {
10
+ MediaAttachmentData,
11
+ PublicPost,
12
+ ResourceKind,
13
+ } from '@openpeepshq/common/types';
14
+ import {
15
+ attachmentMediaKind,
16
+ normalizeResourceTags,
17
+ truncateMarkdown,
18
+ formatSize,
19
+ } from '@openpeepshq/common/lib';
20
+ import { useT } from '../../i18n';
21
+ import { useOpenpeeps } from '../../contexts/openpeeps';
22
+ import { useCurrentProfile } from '../layout/IdentityContext';
23
+ import { VideoPlayOverlay } from '../post/VideoPlayOverlay';
24
+
25
+ export interface ResourceCardProps {
26
+ post: PublicPost;
27
+ layout?: 'card' | 'list';
28
+ preview?: ReactNode;
29
+ }
30
+
31
+ const visualAttachments = (attachments: MediaAttachmentData[]) =>
32
+ attachments.filter((att) => attachmentMediaKind(att) !== 'audio');
33
+
34
+ const previewSrc = (att: MediaAttachmentData) => att.previewUrl ?? att.url;
35
+
36
+ /** Thumbnail size shared between list and card previews. */
37
+ const THUMB_CLASS = 'h-12 w-12 object-cover';
38
+ const CARD_IMG_CLASS = 'h-48 w-full object-cover';
39
+
40
+ const primaryActionLabel = (kind: ResourceKind, t: ReturnType<typeof useT>) => {
41
+ switch (kind) {
42
+ case 'video':
43
+ return t('resources.actions.watch', { defaultValue: 'Watch' });
44
+ case 'file':
45
+ return t('resources.actions.download', { defaultValue: 'Download' });
46
+ case 'audio':
47
+ return t('resources.actions.listen', { defaultValue: 'Listen' });
48
+ case 'gallery':
49
+ return t('resources.actions.view', { defaultValue: 'View images' });
50
+ default:
51
+ return null;
52
+ }
53
+ };
54
+
55
+ const MediaPreview = ({
56
+ src,
57
+ alt,
58
+ className,
59
+ isVideo,
60
+ isLast,
61
+ extra,
62
+ }: {
63
+ src: string | null;
64
+ alt: string;
65
+ className: string;
66
+ isVideo: boolean;
67
+ isLast: boolean;
68
+ extra: number;
69
+ }) => {
70
+ const [errored, setErrored] = useState(false);
71
+
72
+ if (!src) {
73
+ return (
74
+ <div className="bg-surface flex h-full w-full items-center justify-center overflow-hidden">
75
+ <ImageOff className="text-muted-foreground/50 size-6" />
76
+ </div>
77
+ );
78
+ }
79
+
80
+ if (errored) {
81
+ return (
82
+ <div className="bg-surface flex h-full w-full items-center justify-center overflow-hidden">
83
+ <ImageOff className="text-muted-foreground/50 size-6" />
84
+ </div>
85
+ );
86
+ }
87
+
88
+ return (
89
+ <>
90
+ {/* eslint-disable-next-line jsx-a11y/img-has-alt -- handled by alt attribute */}
91
+ <img
92
+ src={src}
93
+ alt={alt}
94
+ className={className}
95
+ onError={() => setErrored(true)}
96
+ />
97
+ {isVideo ? <VideoPlayOverlay video /> : null}
98
+ {isLast && extra > 0 ? (
99
+ <div className="absolute inset-0 flex items-center justify-center bg-black/60 text-lg font-semibold text-white">
100
+ +{extra}
101
+ </div>
102
+ ) : null}
103
+ </>
104
+ );
105
+ };
106
+
107
+ export const ResourceCard = ({
108
+ post,
109
+ layout = 'card',
110
+ preview,
111
+ }: ResourceCardProps) => {
112
+ const t = useT();
113
+ const { openpeepsApi } = useOpenpeeps();
114
+ const me = useCurrentProfile();
115
+ if (post.data?.type !== 'resource') return null;
116
+ const resource = post.data;
117
+ const attachments = resource.attachments ?? [];
118
+ const visuals = visualAttachments(attachments);
119
+ const excerpt = truncateMarkdown(resource.content, 2, 240);
120
+ const tags = normalizeResourceTags(resource.tags);
121
+ const isGallery = resource.resourceKind === 'gallery' && visuals.length > 1;
122
+ const tiles = isGallery ? visuals.slice(0, 4) : visuals.slice(0, 1);
123
+ const extra = isGallery ? Math.max(0, visuals.length - 4) : 0;
124
+ const actionLabel = primaryActionLabel(resource.resourceKind, t);
125
+ const thumbnail = visuals[0];
126
+ const thumbSrc = thumbnail ? previewSrc(thumbnail) : null;
127
+
128
+ const metaText = useMemo(() => {
129
+ if (resource.resourceKind === 'gallery' && visuals.length > 1) {
130
+ return t('resources.meta.imagesCount', {
131
+ defaultValue: '{{count}} images',
132
+ count: visuals.length,
133
+ });
134
+ }
135
+ const fileAtt = attachments.find(
136
+ (att) =>
137
+ attachmentMediaKind(att) === 'file' ||
138
+ attachmentMediaKind(att) === 'video' ||
139
+ attachmentMediaKind(att) === 'audio',
140
+ );
141
+ const size = fileAtt?.meta?.size;
142
+ if (size) return formatSize(size);
143
+ return null;
144
+ }, [resource.resourceKind, visuals, attachments, t]);
145
+
146
+ const bookmarkedIdsQuery = openpeepsApi.useCurrentProfileBookmarkedIds();
147
+ const isBookmarked = bookmarkedIdsQuery.data?.includes(post.id) ?? false;
148
+ const bookmarkPost = openpeepsApi.bookmarkPostAction({ id: post.id });
149
+ const unbookmarkPost = openpeepsApi.unbookmarkPostAction({ id: post.id });
150
+
151
+ const toggleBookmark = () => {
152
+ if (!me) return;
153
+ if (isBookmarked) {
154
+ unbookmarkPost(undefined);
155
+ } else {
156
+ bookmarkPost(undefined);
157
+ }
158
+ };
159
+
160
+ const downloadUrl =
161
+ resource.resourceKind === 'file'
162
+ ? attachments.find((att) => attachmentMediaKind(att) === 'file')?.url
163
+ : null;
164
+
165
+ const renderBookmarkButton = (className: string) => (
166
+ <button
167
+ type="button"
168
+ onClick={(e) => {
169
+ e.preventDefault();
170
+ e.stopPropagation();
171
+ toggleBookmark();
172
+ }}
173
+ disabled={!me}
174
+ className={className}
175
+ title={
176
+ isBookmarked
177
+ ? t('resources.actions.saved', { defaultValue: 'Saved' })
178
+ : t('resources.actions.save', { defaultValue: 'Save' })
179
+ }
180
+ >
181
+ {isBookmarked ? (
182
+ <BookmarkCheck className="text-primary size-4" />
183
+ ) : (
184
+ <BookmarkPlus className="size-4" />
185
+ )}
186
+ </button>
187
+ );
188
+
189
+ const renderThumbnail = () => {
190
+ if (thumbSrc) {
191
+ return (
192
+ <img
193
+ src={thumbSrc}
194
+ alt={thumbnail?.description ?? resource.title}
195
+ className={THUMB_CLASS}
196
+ onError={(e) => {
197
+ (e.target as HTMLImageElement).style.display = 'none';
198
+ }}
199
+ />
200
+ );
201
+ }
202
+ if (resource.resourceKind === 'link' && resource.url) {
203
+ return (
204
+ <div className="bg-muted flex h-12 w-12 items-center justify-center rounded-md">
205
+ <LinkIcon className="text-muted-foreground size-5" />
206
+ </div>
207
+ );
208
+ }
209
+ return null;
210
+ };
211
+
212
+ if (layout === 'list') {
213
+ return (
214
+ <div className="flex w-full min-w-0 items-center gap-3 px-4 py-3">
215
+ {renderThumbnail()}
216
+ <div className="min-w-0 flex-1">
217
+ <h3 className="text-lg font-semibold">{resource.title}</h3>
218
+ {resource.categoryPath?.length ? (
219
+ <p className="text-muted-foreground text-xs">
220
+ {resource.categoryPath.join(' / ')}
221
+ </p>
222
+ ) : null}
223
+ {excerpt ? (
224
+ <p className="text-muted-foreground text-sm">{excerpt}</p>
225
+ ) : null}
226
+ {metaText ? (
227
+ <p className="text-muted-foreground text-xs">{metaText}</p>
228
+ ) : null}
229
+ </div>
230
+ <div className="flex items-center gap-2">
231
+ {resource.resourceKind === 'link' &&
232
+ resource.url ? null : actionLabel ? (
233
+ resource.resourceKind === 'file' && downloadUrl ? (
234
+ <a
235
+ href={downloadUrl}
236
+ download
237
+ onClick={(e) => e.stopPropagation()}
238
+ className="text-primary text-xs font-medium"
239
+ >
240
+ {actionLabel}
241
+ </a>
242
+ ) : (
243
+ <span className="text-muted-foreground text-xs">
244
+ {actionLabel}
245
+ </span>
246
+ )
247
+ ) : null}
248
+ {renderBookmarkButton(
249
+ 'text-muted-foreground hover:text-foreground disabled:opacity-50',
250
+ )}
251
+ </div>
252
+ </div>
253
+ );
254
+ }
255
+
256
+ return (
257
+ <div className="flex w-full min-w-0 flex-col gap-2">
258
+ <div className="relative">
259
+ {preview ? (
260
+ preview
261
+ ) : tiles.length ? (
262
+ <div
263
+ className={`overflow-hidden rounded-md ${
264
+ tiles.length > 1
265
+ ? 'grid h-48 grid-cols-2 grid-rows-2 gap-1'
266
+ : 'h-48 w-full'
267
+ }`}
268
+ >
269
+ {tiles.map((att, index) => {
270
+ const src = previewSrc(att);
271
+ const last = index === tiles.length - 1 && extra > 0;
272
+ const kind = attachmentMediaKind(att);
273
+ return (
274
+ <div
275
+ key={`${att.url ?? index}-${index}`}
276
+ className="bg-surface relative h-full w-full overflow-hidden"
277
+ >
278
+ <MediaPreview
279
+ src={src}
280
+ alt={att.description ?? resource.title}
281
+ className={
282
+ tiles.length > 1
283
+ ? 'h-full w-full object-cover'
284
+ : CARD_IMG_CLASS
285
+ }
286
+ isVideo={kind === 'video'}
287
+ isLast={last}
288
+ extra={extra}
289
+ />
290
+ </div>
291
+ );
292
+ })}
293
+ </div>
294
+ ) : resource.resourceKind === 'link' && resource.url ? (
295
+ <div className="bg-muted flex h-48 w-full items-center justify-center rounded-md">
296
+ <LinkIcon className="text-muted-foreground/50 size-8" />
297
+ </div>
298
+ ) : null}
299
+ {renderBookmarkButton(
300
+ 'bg-background text-muted-foreground hover:text-foreground absolute right-2 top-2 rounded-full p-1 opacity-70 hover:opacity-100 disabled:opacity-50',
301
+ )}
302
+ </div>
303
+
304
+ <h3 className="text-lg font-semibold">{resource.title}</h3>
305
+ {resource.categoryPath?.length ? (
306
+ <p className="text-muted-foreground text-xs">
307
+ {resource.categoryPath.join(' / ')}
308
+ </p>
309
+ ) : null}
310
+ {excerpt ? (
311
+ <p className="text-muted-foreground text-sm">{excerpt}</p>
312
+ ) : null}
313
+ {metaText ? (
314
+ <p className="text-muted-foreground text-xs">{metaText}</p>
315
+ ) : null}
316
+ {tags.length ? (
317
+ <div className="flex flex-wrap gap-1">
318
+ {tags.map((value) => (
319
+ <span
320
+ key={value}
321
+ className="bg-muted text-muted-foreground rounded-full px-2 py-0.5 text-xs"
322
+ >
323
+ #{value}
324
+ </span>
325
+ ))}
326
+ </div>
327
+ ) : null}
328
+ <p className="text-muted-foreground text-xs uppercase">
329
+ {t(`resources.kinds.${resource.resourceKind}`, {
330
+ defaultValue: resource.resourceKind,
331
+ })}
332
+ </p>
333
+ </div>
334
+ );
335
+ };