@openpeepshq/rn-components 0.6.1 → 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 (34) hide show
  1. package/package.json +7 -6
  2. package/src/components/conversations/ConversationMessageBubble.tsx +11 -1
  3. package/src/components/custom/navigation/side-menu.tsx +2 -1
  4. package/src/components/icons/index.ts +8 -0
  5. package/src/components/index.ts +1 -0
  6. package/src/components/navigation/helpers.ts +3 -0
  7. package/src/components/navigation/main-navigator.tsx +4 -0
  8. package/src/components/navigation/nativeRouter.tsx +11 -0
  9. package/src/components/navigation/tab-navigator.tsx +13 -3
  10. package/src/components/navigation/types/main.ts +6 -0
  11. package/src/components/navigation/types/tabs.ts +2 -0
  12. package/src/components/post/CompactReplyParent.tsx +22 -0
  13. package/src/components/post/FeedPostContent.tsx +4 -0
  14. package/src/components/post/NewResourceButton.tsx +57 -0
  15. package/src/components/post/PostDetail.tsx +3 -0
  16. package/src/components/post/index.ts +1 -0
  17. package/src/components/post/pieces/PostMenu.tsx +15 -9
  18. package/src/components/post/post-form/PostTypeSwitcher.tsx +19 -1
  19. package/src/components/post/post-form/ResourceForm.tsx +221 -0
  20. package/src/components/post/post-form/index.ts +1 -0
  21. package/src/components/post/types/index.ts +1 -0
  22. package/src/components/post/types/resource/FullResource.tsx +177 -0
  23. package/src/components/resources/ResourceCard.tsx +289 -0
  24. package/src/components/resources/ResourceLibrary.tsx +369 -0
  25. package/src/components/resources/index.ts +4 -0
  26. package/src/global.css +42 -42
  27. package/src/pages/groups/Show.tsx +19 -1
  28. package/src/pages/index.ts +3 -0
  29. package/src/pages/resources/Edit.tsx +72 -0
  30. package/src/pages/resources/Index.tsx +25 -0
  31. package/src/pages/resources/New.tsx +55 -0
  32. package/src/theme/defaults.ts +21 -105
  33. package/src/theme/utils.ts +15 -9
  34. package/tailwind.config.js +31 -29
@@ -0,0 +1,221 @@
1
+ import React, { useRef, useState } from 'react';
2
+ import { Pressable, View } from 'react-native';
3
+ import { useTranslation } from 'react-i18next';
4
+ import type {
5
+ AudienceSetting,
6
+ MediaAttachment,
7
+ PostCreationData,
8
+ ResourceKind,
9
+ ResourcePost,
10
+ } from '@openpeepshq/common';
11
+ import { RESOURCE_KINDS, normalizeResourceTags } from '@openpeepshq/common/lib';
12
+ import { applyAudienceSetting, useCurrentProfile } from '@openpeepshq/react';
13
+ import { BottomSheetModal } from '@gorhom/bottom-sheet';
14
+ import {
15
+ AudioPickerSheet,
16
+ DocumentPickerSheet,
17
+ ImagePickerSheet,
18
+ VideoPickerSheet,
19
+ type DocumentPickerSheetHandle,
20
+ } from '../../custom';
21
+ import { Input } from '../../ui/input';
22
+ import { ThemedText } from '../../ui/themed-text';
23
+ import { ComposeAttachments } from './ComposeAttachments';
24
+ import { OpenpeepsMarkdownInput } from './OpenpeepsMarkdownInput';
25
+ import { VisibilitySelector } from './VisibilitySelector';
26
+
27
+ export interface ResourceFormProps {
28
+ postData: PostCreationData;
29
+ onChange: (data: PostCreationData) => void;
30
+ isEdit?: boolean;
31
+ }
32
+
33
+ export const ResourceForm = ({
34
+ postData,
35
+ onChange,
36
+ isEdit = false,
37
+ }: ResourceFormProps) => {
38
+ const { t } = useTranslation();
39
+ const me = useCurrentProfile();
40
+ const resource = postData.data as ResourcePost;
41
+ const [tagDraft, setTagDraft] = useState('');
42
+ const imageRef = useRef<BottomSheetModal>(null);
43
+ const videoRef = useRef<BottomSheetModal>(null);
44
+ const audioRef = useRef<BottomSheetModal>(null);
45
+ const documentRef = useRef<DocumentPickerSheetHandle>(null);
46
+
47
+ const patchResource = (patch: Partial<ResourcePost>) =>
48
+ onChange({ ...postData, data: { ...resource, ...patch } });
49
+
50
+ const setAudience = (settings: AudienceSetting) =>
51
+ onChange(applyAudienceSetting(postData, settings, me));
52
+
53
+ const addAttachments = (attachments: MediaAttachment[]) => {
54
+ patchResource({
55
+ attachments: [...(resource.attachments ?? []), ...attachments],
56
+ });
57
+ };
58
+
59
+ const addTag = () => {
60
+ patchResource({
61
+ tags: normalizeResourceTags([
62
+ ...(resource.tags ?? []),
63
+ ...tagDraft.split(/[,\s]+/),
64
+ ]),
65
+ });
66
+ setTagDraft('');
67
+ };
68
+
69
+ const openMedia = () => {
70
+ if (resource.resourceKind === 'gallery') imageRef.current?.present();
71
+ else if (resource.resourceKind === 'video') videoRef.current?.present();
72
+ else if (resource.resourceKind === 'audio') audioRef.current?.present();
73
+ else if (resource.resourceKind === 'file') void documentRef.current?.open();
74
+ };
75
+
76
+ return (
77
+ <View>
78
+ <View className="mt-4 gap-y-4 px-3">
79
+ <ThemedText className="text-sm font-medium">
80
+ {t('resources.form.name')}
81
+ </ThemedText>
82
+ <Input
83
+ value={resource.title}
84
+ onChangeText={(title) => patchResource({ title })}
85
+ />
86
+
87
+ <ThemedText className="text-sm font-medium">
88
+ {t('resources.form.kind')}
89
+ </ThemedText>
90
+ <View className="flex-row flex-wrap gap-2">
91
+ {RESOURCE_KINDS.map((kind) => (
92
+ <Pressable
93
+ key={kind}
94
+ onPress={() =>
95
+ patchResource({ resourceKind: kind as ResourceKind })
96
+ }
97
+ className={`rounded-full px-3 py-1 ${
98
+ resource.resourceKind === kind ? 'bg-primary' : 'bg-muted'
99
+ }`}
100
+ >
101
+ <ThemedText
102
+ className={
103
+ resource.resourceKind === kind
104
+ ? 'text-xs text-primary-foreground'
105
+ : 'text-xs text-muted-foreground'
106
+ }
107
+ >
108
+ {t(`resources.kinds.${kind}`)}
109
+ </ThemedText>
110
+ </Pressable>
111
+ ))}
112
+ </View>
113
+
114
+ {resource.resourceKind === 'link' ? (
115
+ <>
116
+ <ThemedText className="text-sm font-medium">
117
+ {t('resources.form.url')}
118
+ </ThemedText>
119
+ <Input
120
+ value={resource.url ?? ''}
121
+ onChangeText={(url) => patchResource({ url })}
122
+ autoCapitalize="none"
123
+ />
124
+ </>
125
+ ) : (
126
+ <>
127
+ <Pressable
128
+ onPress={openMedia}
129
+ className="items-center rounded-md border border-input px-3 py-2"
130
+ >
131
+ <ThemedText>{t('resources.form.addMedia')}</ThemedText>
132
+ </Pressable>
133
+ <ComposeAttachments
134
+ attachments={resource.attachments ?? []}
135
+ removeAttachment={(index) =>
136
+ patchResource({
137
+ attachments: (resource.attachments ?? []).filter(
138
+ (_, i) => i !== index
139
+ ),
140
+ })
141
+ }
142
+ updateAttachment={(index, attachment) =>
143
+ patchResource({
144
+ attachments: (resource.attachments ?? []).map((item, i) =>
145
+ i === index ? attachment : item
146
+ ),
147
+ })
148
+ }
149
+ />
150
+ </>
151
+ )}
152
+
153
+ <OpenpeepsMarkdownInput
154
+ rows={8}
155
+ maxLength={4000}
156
+ value={resource.content ?? ''}
157
+ onChange={(content) => patchResource({ content })}
158
+ placeholder={t('resources.form.descriptionPlaceholder')}
159
+ />
160
+
161
+ <ThemedText className="text-sm font-medium">
162
+ {t('resources.form.tags')}
163
+ </ThemedText>
164
+ <Input
165
+ value={tagDraft}
166
+ onChangeText={setTagDraft}
167
+ onSubmitEditing={addTag}
168
+ placeholder={t('resources.form.tagsPlaceholder')}
169
+ />
170
+ <View className="flex-row flex-wrap gap-1">
171
+ {normalizeResourceTags(resource.tags).map((tag) => (
172
+ <Pressable
173
+ key={tag}
174
+ onPress={() =>
175
+ patchResource({
176
+ tags: (resource.tags ?? []).filter(
177
+ (value) => value.toLowerCase() !== tag
178
+ ),
179
+ })
180
+ }
181
+ >
182
+ <ThemedText className="rounded-full bg-muted px-2 py-0.5 text-xs">
183
+ #{tag}
184
+ </ThemedText>
185
+ </Pressable>
186
+ ))}
187
+ </View>
188
+
189
+ <ThemedText className="text-sm font-medium">
190
+ {t('resources.form.hierarchy')}
191
+ </ThemedText>
192
+ <Input
193
+ value={(resource.categoryPath ?? []).join(' / ')}
194
+ onChangeText={(value) =>
195
+ patchResource({
196
+ categoryPath: value
197
+ .split('/')
198
+ .map((segment) => segment.trim())
199
+ .filter(Boolean),
200
+ })
201
+ }
202
+ placeholder={t('resources.form.addLevel')}
203
+ />
204
+
205
+ <ThemedText className="text-sm font-medium">
206
+ {t('resources.form.visibility')}
207
+ </ThemedText>
208
+ <VisibilitySelector
209
+ audienceSetting={postData}
210
+ onChange={setAudience}
211
+ disabled={isEdit}
212
+ showDirect
213
+ />
214
+ </View>
215
+ <ImagePickerSheet ref={imageRef} onSelect={addAttachments} />
216
+ <VideoPickerSheet ref={videoRef} onSelect={addAttachments} />
217
+ <AudioPickerSheet ref={audioRef} onSelect={addAttachments} />
218
+ <DocumentPickerSheet ref={documentRef} onSelect={addAttachments} />
219
+ </View>
220
+ );
221
+ };
@@ -1,4 +1,5 @@
1
1
  export * from './ArticleForm';
2
+ export * from './ResourceForm';
2
3
  export * from './ArticlePreviewSheet';
3
4
  export * from './AttachmentCard';
4
5
  export * from './ComposeAttachments';
@@ -6,3 +6,4 @@ export * from './note';
6
6
  export * from './Note';
7
7
  export * from './poll';
8
8
  export * from './Poll';
9
+ export * from './resource/FullResource';
@@ -0,0 +1,177 @@
1
+ import React, { useState } from 'react';
2
+ import { View, Linking, Pressable } from 'react-native';
3
+ import { useNavigation } from '@react-navigation/native';
4
+ import { useTranslation } from 'react-i18next';
5
+ import type { PublicPost } from '@openpeepshq/common';
6
+ import { attachmentMediaKind } from '@openpeepshq/common/lib';
7
+ import { FullPostLayout } from '../../FullPostLayout';
8
+ import { PostInfoHeader } from '../../pieces/PostInfoHeader';
9
+ import { PostMarkdown } from '../../Markdown';
10
+ import { ResourceCard } from '../../../resources/ResourceCard';
11
+ import { GalleryModal } from '../../pieces/GalleryModal';
12
+ import { VideoPlayer } from '../../pieces/VideoPlayer';
13
+ import { AudioAttachment } from '../../pieces/AudioAttachment';
14
+ import {
15
+ DownloadIcon,
16
+ ExternalLinkIcon,
17
+ ImageIcon,
18
+ PlayIcon,
19
+ } from '../../../icons';
20
+
21
+ export interface FullResourceProps {
22
+ post: PublicPost;
23
+ }
24
+
25
+ export const FullResource = ({ post }: FullResourceProps) => {
26
+ const { t } = useTranslation();
27
+ const navigation = useNavigation();
28
+ const deleteCallback = () => navigation.goBack();
29
+ const resource = post.data?.type === 'resource' ? post.data : null;
30
+ const [galleryIndex, setGalleryIndex] = useState<number | null>(null);
31
+ const [playerVisible, setPlayerVisible] = useState(false);
32
+
33
+ if (!resource) return null;
34
+
35
+ const handlePreviewClick = () => {
36
+ switch (resource.resourceKind) {
37
+ case 'video':
38
+ case 'audio':
39
+ setPlayerVisible(true);
40
+ break;
41
+ case 'gallery':
42
+ setGalleryIndex(0);
43
+ break;
44
+ case 'file': {
45
+ const att = resource.attachments?.find(
46
+ (a) => attachmentMediaKind(a) === 'file'
47
+ );
48
+ if (att?.url) Linking.openURL(att.url);
49
+ break;
50
+ }
51
+ case 'link':
52
+ if (resource.url) Linking.openURL(resource.url);
53
+ break;
54
+ default:
55
+ break;
56
+ }
57
+ };
58
+
59
+ const previewLabel = () => {
60
+ switch (resource.resourceKind) {
61
+ case 'video':
62
+ return t('resources.actions.watch', {
63
+ defaultValue: 'Play video',
64
+ });
65
+ case 'audio':
66
+ return t('resources.actions.listen', {
67
+ defaultValue: 'Play audio',
68
+ });
69
+ case 'gallery':
70
+ return t('resources.actions.view', {
71
+ defaultValue: 'View images',
72
+ });
73
+ case 'file':
74
+ return t('resources.actions.download', {
75
+ defaultValue: 'Download',
76
+ });
77
+ case 'link':
78
+ return t('resources.actions.openLink', {
79
+ defaultValue: 'Open link',
80
+ });
81
+ default:
82
+ return '';
83
+ }
84
+ };
85
+
86
+ const previewIcon = () => {
87
+ switch (resource.resourceKind) {
88
+ case 'video':
89
+ case 'audio':
90
+ return <PlayIcon size={48} className="text-white" />;
91
+ case 'gallery':
92
+ return <ImageIcon size={48} className="text-white" />;
93
+ case 'file':
94
+ return <DownloadIcon size={48} className="text-white" />;
95
+ case 'link':
96
+ return <ExternalLinkIcon size={48} className="text-white" />;
97
+ default:
98
+ return null;
99
+ }
100
+ };
101
+
102
+ const renderMedia = () => {
103
+ if (resource.resourceKind === 'video' && playerVisible) {
104
+ const videoAtt = resource.attachments?.find(
105
+ (a) => attachmentMediaKind(a) === 'video'
106
+ );
107
+ if (videoAtt) {
108
+ return (
109
+ <ResourceCard
110
+ post={post}
111
+ preview={<VideoPlayer attachment={videoAtt} />}
112
+ />
113
+ );
114
+ }
115
+ }
116
+
117
+ if (resource.resourceKind === 'audio' && playerVisible) {
118
+ const audioAtt = resource.attachments?.find(
119
+ (a) => attachmentMediaKind(a) === 'audio'
120
+ );
121
+ if (audioAtt?.url) {
122
+ return (
123
+ <ResourceCard
124
+ post={post}
125
+ preview={
126
+ <AudioAttachment
127
+ src={audioAtt.url}
128
+ label={audioAtt.filename ?? audioAtt.description}
129
+ size={audioAtt.meta?.size}
130
+ />
131
+ }
132
+ />
133
+ );
134
+ }
135
+ }
136
+
137
+ // All kinds: ResourceCard with click overlay
138
+ return (
139
+ <View className="relative">
140
+ <ResourceCard post={post} />
141
+ <View
142
+ className="absolute top-0 left-0 right-0 h-48 items-center justify-center"
143
+ pointerEvents="box-none"
144
+ >
145
+ <View
146
+ className="flex size-20 items-center justify-center rounded-full bg-black/60"
147
+ pointerEvents="auto"
148
+ >
149
+ <Pressable
150
+ onPress={handlePreviewClick}
151
+ accessibilityLabel={previewLabel()}
152
+ >
153
+ {previewIcon()}
154
+ </Pressable>
155
+ </View>
156
+ </View>
157
+ </View>
158
+ );
159
+ };
160
+
161
+ return (
162
+ <FullPostLayout post={post} deleteCallback={deleteCallback}>
163
+ <View className="w-full gap-y-3">
164
+ <PostInfoHeader post={post} showMenu deleteCallback={deleteCallback} />
165
+ {renderMedia()}
166
+ {galleryIndex !== null ? (
167
+ <GalleryModal
168
+ attachments={resource.attachments ?? []}
169
+ initialIndex={galleryIndex}
170
+ onClose={() => setGalleryIndex(null)}
171
+ />
172
+ ) : null}
173
+ {resource?.content ? <PostMarkdown source={resource.content} /> : null}
174
+ </View>
175
+ </FullPostLayout>
176
+ );
177
+ };
@@ -0,0 +1,289 @@
1
+ import React, { useMemo, useState } from 'react';
2
+ import type { ReactNode } from 'react';
3
+ import { Pressable, View } from 'react-native';
4
+ import { useTranslation } from 'react-i18next';
5
+ import type {
6
+ MediaAttachmentData,
7
+ PublicPost,
8
+ ResourceKind,
9
+ } from '@openpeepshq/common/types';
10
+ import {
11
+ attachmentMediaKind,
12
+ formatSize,
13
+ normalizeResourceTags,
14
+ truncateMarkdown,
15
+ } from '@openpeepshq/common/lib';
16
+ import { useOpenpeeps } from '@openpeepshq/react';
17
+ import { CachedImage } from '../custom/common';
18
+ import { ThemedText } from '../ui/themed-text';
19
+ import { VideoPlayOverlay } from '../post/VideoPlayOverlay';
20
+ import {
21
+ BookmarkPlusIcon,
22
+ BookmarkMinusIcon,
23
+ LinkIcon,
24
+ ImageOffIcon,
25
+ } from '../icons';
26
+
27
+ export interface ResourceCardProps {
28
+ post: PublicPost;
29
+ layout?: 'card' | 'list';
30
+ preview?: ReactNode;
31
+ }
32
+
33
+ const visualAttachments = (attachments: MediaAttachmentData[]) =>
34
+ attachments.filter((att) => attachmentMediaKind(att) !== 'audio');
35
+
36
+ const primaryActionLabel = (
37
+ kind: ResourceKind,
38
+ t: (key: string, opts?: { defaultValue?: string; count?: number }) => string
39
+ ) => {
40
+ switch (kind) {
41
+ case 'video':
42
+ return t('resources.actions.watch', { defaultValue: 'Watch' });
43
+ case 'file':
44
+ return t('resources.actions.download', { defaultValue: 'Download' });
45
+ case 'audio':
46
+ return t('resources.actions.listen', { defaultValue: 'Listen' });
47
+ case 'gallery':
48
+ return t('resources.actions.view', { defaultValue: 'View images' });
49
+ default:
50
+ return null;
51
+ }
52
+ };
53
+
54
+ export const ResourceCard = ({
55
+ post,
56
+ layout = 'card',
57
+ preview,
58
+ }: ResourceCardProps) => {
59
+ const { t } = useTranslation();
60
+ const { openpeepsApi } = useOpenpeeps();
61
+ const { data: currentProfile } = openpeepsApi.useCurrentProfile();
62
+ const bookmarkedIdsQuery = openpeepsApi.useCurrentProfileBookmarkedIds();
63
+ const isBookmarked = bookmarkedIdsQuery.data?.includes(post.id) ?? false;
64
+ const bookmarkPost = openpeepsApi.bookmarkPostAction({ id: post.id });
65
+ const unbookmarkPost = openpeepsApi.unbookmarkPostAction({ id: post.id });
66
+ const [erroredUrls, setErroredUrls] = useState<Set<string>>(new Set());
67
+
68
+ const resource = post.data?.type === 'resource' ? post.data : null;
69
+ const visuals = useMemo(
70
+ () => (resource ? visualAttachments(resource.attachments ?? []) : []),
71
+ [resource]
72
+ );
73
+ const isGallery =
74
+ !!resource && resource.resourceKind === 'gallery' && visuals.length > 1;
75
+ const tiles = isGallery ? visuals.slice(0, 4) : visuals.slice(0, 1);
76
+ const extra = isGallery ? Math.max(0, visuals.length - 4) : 0;
77
+ const excerpt = resource ? truncateMarkdown(resource.content, 2, 240) : null;
78
+ const tags = resource ? normalizeResourceTags(resource.tags) : [];
79
+ const actionLabel = resource
80
+ ? primaryActionLabel(resource.resourceKind, (key, opts) => t(key, opts))
81
+ : null;
82
+ const thumbnail = visuals[0];
83
+ const thumbSrc = thumbnail ? (thumbnail.previewUrl ?? thumbnail.url) : null;
84
+
85
+ const metaText = useMemo(() => {
86
+ if (!resource) return null;
87
+ if (resource.resourceKind === 'gallery' && visuals.length > 1) {
88
+ return t('resources.meta.imagesCount', {
89
+ count: visuals.length,
90
+ });
91
+ }
92
+ const fileAtt = (resource.attachments ?? []).find(
93
+ (att: MediaAttachmentData) =>
94
+ attachmentMediaKind(att) === 'file' ||
95
+ attachmentMediaKind(att) === 'video' ||
96
+ attachmentMediaKind(att) === 'audio'
97
+ );
98
+ const size = fileAtt?.meta?.size;
99
+ if (size) return formatSize(size);
100
+ return null;
101
+ }, [resource, visuals, t]);
102
+
103
+ if (!resource) return null;
104
+
105
+ const toggleBookmark = () => {
106
+ if (!currentProfile) return;
107
+ if (isBookmarked) {
108
+ unbookmarkPost(undefined);
109
+ } else {
110
+ bookmarkPost(undefined);
111
+ }
112
+ };
113
+
114
+ const renderBookmarkButton = () => (
115
+ <Pressable
116
+ onPress={toggleBookmark}
117
+ disabled={!currentProfile}
118
+ className="opacity-70"
119
+ >
120
+ {isBookmarked ? (
121
+ <BookmarkMinusIcon size={20} className="text-primary" />
122
+ ) : (
123
+ <BookmarkPlusIcon size={20} className="text-muted-foreground" />
124
+ )}
125
+ </Pressable>
126
+ );
127
+
128
+ const renderThumbnail = () => {
129
+ if (thumbSrc) {
130
+ return (
131
+ <CachedImage url={thumbSrc} className="h-12 w-12" resizeMode="cover" />
132
+ );
133
+ }
134
+ if (resource.resourceKind === 'link' && resource.url) {
135
+ return (
136
+ <View className="h-12 w-12 items-center justify-center rounded-md bg-muted">
137
+ <LinkIcon size={20} className="text-muted-foreground" />
138
+ </View>
139
+ );
140
+ }
141
+ return null;
142
+ };
143
+
144
+ if (layout === 'list') {
145
+ return (
146
+ <View className="w-full flex-row items-center justify-between px-4 py-3">
147
+ {renderThumbnail()}
148
+ <View className="min-w-0 flex-1">
149
+ <ThemedText className="text-lg font-semibold">
150
+ {resource.title}
151
+ </ThemedText>
152
+ {resource.categoryPath?.length ? (
153
+ <ThemedText className="text-xs text-muted-foreground">
154
+ {resource.categoryPath.join(' / ')}
155
+ </ThemedText>
156
+ ) : null}
157
+ {excerpt ? (
158
+ <ThemedText className="text-sm text-muted-foreground">
159
+ {excerpt}
160
+ </ThemedText>
161
+ ) : null}
162
+ {metaText ? (
163
+ <ThemedText className="text-xs text-muted-foreground">
164
+ {metaText}
165
+ </ThemedText>
166
+ ) : null}
167
+ </View>
168
+ <View className="flex-row items-center gap-2">
169
+ {resource.resourceKind !== 'link' && actionLabel ? (
170
+ actionLabel === 'Download' &&
171
+ resource.attachments?.find(
172
+ (att) => attachmentMediaKind(att) === 'file'
173
+ )?.url ? (
174
+ <ThemedText className="text-primary text-xs font-medium">
175
+ {actionLabel}
176
+ </ThemedText>
177
+ ) : (
178
+ <ThemedText className="text-muted-foreground text-xs">
179
+ {actionLabel}
180
+ </ThemedText>
181
+ )
182
+ ) : null}
183
+ {renderBookmarkButton()}
184
+ </View>
185
+ </View>
186
+ );
187
+ }
188
+
189
+ return (
190
+ <View className="w-full gap-y-2">
191
+ <View className="relative">
192
+ {preview ? (
193
+ preview
194
+ ) : tiles.length ? (
195
+ <View className={tiles.length > 1 ? 'h-48 flex-row flex-wrap' : ''}>
196
+ {tiles.map((att, index) => {
197
+ const src = att.previewUrl ?? att.url;
198
+ const last = index === tiles.length - 1 && extra > 0;
199
+ const hasErrored = erroredUrls.has(src ?? '');
200
+ return (
201
+ <View
202
+ key={`${att.url ?? index}-${index}`}
203
+ className={
204
+ tiles.length > 1 ? 'h-1/2 w-1/2 overflow-hidden p-px' : ''
205
+ }
206
+ >
207
+ {src && !hasErrored ? (
208
+ <View className="relative">
209
+ <CachedImage
210
+ url={src}
211
+ className={
212
+ tiles.length > 1 ? 'h-full w-full' : 'h-48 w-full'
213
+ }
214
+ resizeMode="cover"
215
+ onError={() =>
216
+ setErroredUrls((prev) => {
217
+ const n = new Set(prev);
218
+ n.add(src ?? '');
219
+ return n;
220
+ })
221
+ }
222
+ />
223
+ {attachmentMediaKind(att) === 'video' ? (
224
+ <VideoPlayOverlay video />
225
+ ) : null}
226
+ {last ? (
227
+ <View className="absolute inset-0 items-center justify-center bg-black/60">
228
+ <ThemedText className="text-lg font-semibold text-white">
229
+ +{extra}
230
+ </ThemedText>
231
+ </View>
232
+ ) : null}
233
+ </View>
234
+ ) : (
235
+ <View className="bg-muted flex h-full w-full items-center justify-center">
236
+ <ImageOffIcon
237
+ size={24}
238
+ className="text-muted-foreground/50"
239
+ />
240
+ </View>
241
+ )}
242
+ </View>
243
+ );
244
+ })}
245
+ </View>
246
+ ) : resource.resourceKind === 'link' && resource.url ? (
247
+ <View className="h-48 w-full items-center justify-center rounded-md bg-muted">
248
+ <LinkIcon size={32} className="text-muted-foreground/50" />
249
+ </View>
250
+ ) : null}
251
+ <View className="absolute top-2 right-2">{renderBookmarkButton()}</View>
252
+ </View>
253
+
254
+ <ThemedText className="text-lg font-semibold">
255
+ {resource.title}
256
+ </ThemedText>
257
+ {resource.categoryPath?.length ? (
258
+ <ThemedText className="text-xs text-muted-foreground">
259
+ {resource.categoryPath.join(' / ')}
260
+ </ThemedText>
261
+ ) : null}
262
+ {excerpt ? (
263
+ <ThemedText className="text-sm text-muted-foreground">
264
+ {excerpt}
265
+ </ThemedText>
266
+ ) : null}
267
+ {metaText ? (
268
+ <ThemedText className="text-xs text-muted-foreground">
269
+ {metaText}
270
+ </ThemedText>
271
+ ) : null}
272
+ {tags.length ? (
273
+ <View className="flex-row flex-wrap gap-1">
274
+ {tags.map((value) => (
275
+ <ThemedText
276
+ key={value}
277
+ className="rounded-full bg-muted px-2 py-0.5 text-xs text-muted-foreground"
278
+ >
279
+ #{value}
280
+ </ThemedText>
281
+ ))}
282
+ </View>
283
+ ) : null}
284
+ <ThemedText className="text-xs uppercase text-muted-foreground">
285
+ {t(`resources.kinds.${resource.resourceKind}`)}
286
+ </ThemedText>
287
+ </View>
288
+ );
289
+ };