@openpeepshq/rn-components 0.6.1 → 0.6.3
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.
- package/package.json +7 -6
- package/src/components/conversations/ConversationMessageBubble.tsx +11 -1
- package/src/components/custom/navigation/side-menu.tsx +2 -1
- package/src/components/icons/index.ts +8 -0
- package/src/components/index.ts +1 -0
- package/src/components/layout/PlusButton.tsx +4 -2
- package/src/components/layout/pageChrome.tsx +2 -0
- package/src/components/navigation/helpers.ts +3 -0
- package/src/components/navigation/main-navigator.tsx +4 -0
- package/src/components/navigation/nativeRouter.tsx +11 -0
- package/src/components/navigation/tab-navigator.tsx +13 -3
- package/src/components/navigation/types/main.ts +6 -0
- package/src/components/navigation/types/tabs.ts +2 -0
- package/src/components/post/CompactReplyParent.tsx +22 -0
- package/src/components/post/FeedPostContent.tsx +4 -0
- package/src/components/post/NewResourceButton.tsx +57 -0
- package/src/components/post/PostDetail.tsx +3 -0
- package/src/components/post/index.ts +1 -0
- package/src/components/post/pieces/PostMenu.tsx +15 -9
- package/src/components/post/post-form/PostTypeSwitcher.tsx +19 -1
- package/src/components/post/post-form/ResourceForm.tsx +241 -0
- package/src/components/post/post-form/index.ts +1 -0
- package/src/components/post/types/index.ts +1 -0
- package/src/components/post/types/resource/FullResource.tsx +177 -0
- package/src/components/resources/ResourceCard.tsx +289 -0
- package/src/components/resources/ResourceLibrary.tsx +371 -0
- package/src/components/resources/index.ts +4 -0
- package/src/global.css +42 -42
- package/src/pages/conversations/Index.tsx +12 -59
- package/src/pages/groups/Show.tsx +19 -1
- package/src/pages/index.ts +3 -0
- package/src/pages/resources/Edit.tsx +72 -0
- package/src/pages/resources/Index.tsx +25 -0
- package/src/pages/resources/New.tsx +55 -0
- package/src/theme/defaults.ts +21 -105
- package/src/theme/utils.ts +15 -9
- package/tailwind.config.js +33 -30
|
@@ -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
|
+
};
|
|
@@ -0,0 +1,371 @@
|
|
|
1
|
+
import React, { useMemo, useState } from 'react';
|
|
2
|
+
import { Pressable, View, ScrollView } from 'react-native';
|
|
3
|
+
import { useTranslation } from 'react-i18next';
|
|
4
|
+
import type { ResourceKind } from '@openpeepshq/common/types';
|
|
5
|
+
import { RESOURCE_KINDS } from '@openpeepshq/common/lib';
|
|
6
|
+
import type { CategoryNode } from '@openpeepshq/common/lib';
|
|
7
|
+
import { useResourceLibrary } from '@openpeepshq/react';
|
|
8
|
+
import { Input } from '../ui/input';
|
|
9
|
+
import { LoadingSpinner } from '../ui/loading-spinner';
|
|
10
|
+
import { ThemedText } from '../ui/themed-text';
|
|
11
|
+
import {
|
|
12
|
+
LayoutGridIcon,
|
|
13
|
+
LayoutListIcon,
|
|
14
|
+
BookmarkIcon,
|
|
15
|
+
ChevronDownIcon,
|
|
16
|
+
ChevronRightIcon,
|
|
17
|
+
} from '../icons';
|
|
18
|
+
import { ResourceCard } from './ResourceCard';
|
|
19
|
+
|
|
20
|
+
export interface ResourceLibraryProps {
|
|
21
|
+
groupId?: string;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const COLLECTION_LIMIT = 5;
|
|
25
|
+
|
|
26
|
+
const Tree = ({
|
|
27
|
+
nodes,
|
|
28
|
+
selected,
|
|
29
|
+
onSelect,
|
|
30
|
+
counts,
|
|
31
|
+
expanded,
|
|
32
|
+
onToggle,
|
|
33
|
+
}: {
|
|
34
|
+
nodes: CategoryNode[];
|
|
35
|
+
selected: string[];
|
|
36
|
+
onSelect: (path: string[]) => void;
|
|
37
|
+
counts: Map<string, number>;
|
|
38
|
+
expanded: Set<string>;
|
|
39
|
+
onToggle: (nodeKey: string) => void;
|
|
40
|
+
}) => (
|
|
41
|
+
<View className="gap-y-1">
|
|
42
|
+
{nodes.map((node) => {
|
|
43
|
+
const nodeKey = node.path.join('/');
|
|
44
|
+
const nodeCount = counts.get(nodeKey) ?? 0;
|
|
45
|
+
const isExpanded = expanded.has(nodeKey);
|
|
46
|
+
const isSelected = selected.join('/') === nodeKey;
|
|
47
|
+
const hasChildren = node.children.length > 0;
|
|
48
|
+
return (
|
|
49
|
+
<View key={nodeKey}>
|
|
50
|
+
<View className="flex-row items-center gap-1">
|
|
51
|
+
<Pressable
|
|
52
|
+
onPress={hasChildren ? () => onToggle(nodeKey) : undefined}
|
|
53
|
+
className={hasChildren ? '' : 'invisible'}
|
|
54
|
+
>
|
|
55
|
+
<ChevronRightIcon
|
|
56
|
+
size={16}
|
|
57
|
+
className={`text-muted-foreground transition-transform ${
|
|
58
|
+
isExpanded ? 'rotate-90' : ''
|
|
59
|
+
}`}
|
|
60
|
+
/>
|
|
61
|
+
</Pressable>
|
|
62
|
+
<Pressable onPress={() => onSelect(node.path)}>
|
|
63
|
+
<ThemedText
|
|
64
|
+
className={`text-sm ${
|
|
65
|
+
isSelected
|
|
66
|
+
? 'font-semibold text-foreground'
|
|
67
|
+
: 'text-muted-foreground'
|
|
68
|
+
}`}
|
|
69
|
+
>
|
|
70
|
+
{node.name}{' '}
|
|
71
|
+
<ThemedText className="text-xs opacity-60">
|
|
72
|
+
({nodeCount})
|
|
73
|
+
</ThemedText>
|
|
74
|
+
</ThemedText>
|
|
75
|
+
</Pressable>
|
|
76
|
+
</View>
|
|
77
|
+
{hasChildren && isExpanded ? (
|
|
78
|
+
<View className="ml-4">
|
|
79
|
+
<Tree
|
|
80
|
+
nodes={node.children}
|
|
81
|
+
selected={selected}
|
|
82
|
+
onSelect={onSelect}
|
|
83
|
+
counts={counts}
|
|
84
|
+
expanded={expanded}
|
|
85
|
+
onToggle={onToggle}
|
|
86
|
+
/>
|
|
87
|
+
</View>
|
|
88
|
+
) : null}
|
|
89
|
+
</View>
|
|
90
|
+
);
|
|
91
|
+
})}
|
|
92
|
+
</View>
|
|
93
|
+
);
|
|
94
|
+
|
|
95
|
+
export const ResourceLibrary = ({ groupId }: ResourceLibraryProps) => {
|
|
96
|
+
const { t } = useTranslation();
|
|
97
|
+
const library = useResourceLibrary(groupId);
|
|
98
|
+
const [expanded, setExpanded] = useState<Set<string>>(new Set());
|
|
99
|
+
|
|
100
|
+
const toggleNode = (nodeKey: string) => {
|
|
101
|
+
setExpanded((prev) => {
|
|
102
|
+
const next = new Set(prev);
|
|
103
|
+
if (next.has(nodeKey)) next.delete(nodeKey);
|
|
104
|
+
else next.add(nodeKey);
|
|
105
|
+
return next;
|
|
106
|
+
});
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
const collectionCounts = useMemo(() => {
|
|
110
|
+
const counts = new Map<string, number>();
|
|
111
|
+
let rootCount = 0;
|
|
112
|
+
for (const post of library.posts) {
|
|
113
|
+
if (post.data?.type !== 'resource') continue;
|
|
114
|
+
const path = post.data.categoryPath;
|
|
115
|
+
if (!path?.length) continue;
|
|
116
|
+
rootCount++;
|
|
117
|
+
for (let i = 1; i <= path.length; i++) {
|
|
118
|
+
const key = path.slice(0, i).join('/');
|
|
119
|
+
counts.set(key, (counts.get(key) ?? 0) + 1);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
counts.set('', rootCount);
|
|
123
|
+
return counts;
|
|
124
|
+
}, [library.posts]);
|
|
125
|
+
|
|
126
|
+
const treeNodes = useMemo(() => {
|
|
127
|
+
if (library.tree.length === 0) return [];
|
|
128
|
+
return [
|
|
129
|
+
{
|
|
130
|
+
name: t('resources.library.allFolders', {
|
|
131
|
+
defaultValue: 'All folders',
|
|
132
|
+
}),
|
|
133
|
+
path: [] as string[],
|
|
134
|
+
children: library.tree,
|
|
135
|
+
},
|
|
136
|
+
];
|
|
137
|
+
}, [library.tree, t]);
|
|
138
|
+
|
|
139
|
+
const sortedTags = useMemo(
|
|
140
|
+
() =>
|
|
141
|
+
library.tags
|
|
142
|
+
.filter((entry) => library.selectedTags.includes(entry.name))
|
|
143
|
+
.concat(
|
|
144
|
+
library.tags.filter(
|
|
145
|
+
(entry) => !library.selectedTags.includes(entry.name)
|
|
146
|
+
)
|
|
147
|
+
),
|
|
148
|
+
[library.tags, library.selectedTags]
|
|
149
|
+
);
|
|
150
|
+
|
|
151
|
+
const visibleTags = library.tagsOpen
|
|
152
|
+
? sortedTags
|
|
153
|
+
: sortedTags.slice(0, COLLECTION_LIMIT);
|
|
154
|
+
const hasMoreTags = sortedTags.length > COLLECTION_LIMIT;
|
|
155
|
+
|
|
156
|
+
return (
|
|
157
|
+
<View>
|
|
158
|
+
<View className="gap-y-3 p-4">
|
|
159
|
+
<Input
|
|
160
|
+
value={library.search}
|
|
161
|
+
onChangeText={library.setSearch}
|
|
162
|
+
placeholder={t('resources.library.search', {
|
|
163
|
+
defaultValue: 'Search resources',
|
|
164
|
+
})}
|
|
165
|
+
/>
|
|
166
|
+
<View className="flex-row flex-wrap items-center justify-between gap-2">
|
|
167
|
+
<View className="flex-row flex-wrap gap-2">
|
|
168
|
+
{(['all', ...RESOURCE_KINDS] as const).map((kind) => (
|
|
169
|
+
<Pressable
|
|
170
|
+
key={kind}
|
|
171
|
+
onPress={() =>
|
|
172
|
+
library.setKind(
|
|
173
|
+
kind === 'all' ? 'all' : (kind as ResourceKind)
|
|
174
|
+
)
|
|
175
|
+
}
|
|
176
|
+
className={`rounded-full px-3 py-1 ${
|
|
177
|
+
library.kind === kind ? 'bg-primary' : 'bg-muted'
|
|
178
|
+
}`}
|
|
179
|
+
>
|
|
180
|
+
<ThemedText
|
|
181
|
+
className={
|
|
182
|
+
library.kind === kind
|
|
183
|
+
? 'text-primary-foreground text-xs'
|
|
184
|
+
: 'text-muted-foreground text-xs'
|
|
185
|
+
}
|
|
186
|
+
>
|
|
187
|
+
{kind === 'all'
|
|
188
|
+
? t('resources.library.allKinds', { defaultValue: 'All' })
|
|
189
|
+
: t(`resources.kinds.${kind}`)}
|
|
190
|
+
</ThemedText>
|
|
191
|
+
</Pressable>
|
|
192
|
+
))}
|
|
193
|
+
</View>
|
|
194
|
+
<View className="flex-row gap-1">
|
|
195
|
+
<Pressable
|
|
196
|
+
onPress={() => library.setView('list')}
|
|
197
|
+
className={`rounded-full p-2 ${
|
|
198
|
+
library.view === 'list' ? 'bg-primary' : 'bg-muted'
|
|
199
|
+
}`}
|
|
200
|
+
>
|
|
201
|
+
<LayoutListIcon
|
|
202
|
+
size={20}
|
|
203
|
+
className={
|
|
204
|
+
library.view === 'list'
|
|
205
|
+
? 'text-primary-foreground'
|
|
206
|
+
: 'text-muted-foreground'
|
|
207
|
+
}
|
|
208
|
+
/>
|
|
209
|
+
</Pressable>
|
|
210
|
+
<Pressable
|
|
211
|
+
onPress={() => library.setView('cards')}
|
|
212
|
+
className={`rounded-full p-2 ${
|
|
213
|
+
library.view === 'cards' ? 'bg-primary' : 'bg-muted'
|
|
214
|
+
}`}
|
|
215
|
+
>
|
|
216
|
+
<LayoutGridIcon
|
|
217
|
+
size={20}
|
|
218
|
+
className={
|
|
219
|
+
library.view === 'cards'
|
|
220
|
+
? 'text-primary-foreground'
|
|
221
|
+
: 'text-muted-foreground'
|
|
222
|
+
}
|
|
223
|
+
/>
|
|
224
|
+
</Pressable>
|
|
225
|
+
<Pressable
|
|
226
|
+
onPress={() => library.setSaved(!library.saved)}
|
|
227
|
+
className={`rounded-full p-2 ${
|
|
228
|
+
library.saved ? 'bg-primary' : 'bg-muted'
|
|
229
|
+
}`}
|
|
230
|
+
>
|
|
231
|
+
<BookmarkIcon
|
|
232
|
+
size={20}
|
|
233
|
+
className={
|
|
234
|
+
library.saved
|
|
235
|
+
? 'text-primary-foreground'
|
|
236
|
+
: 'text-muted-foreground'
|
|
237
|
+
}
|
|
238
|
+
/>
|
|
239
|
+
</Pressable>
|
|
240
|
+
</View>
|
|
241
|
+
</View>
|
|
242
|
+
|
|
243
|
+
{/* Breadcrumb + tree */}
|
|
244
|
+
<View>
|
|
245
|
+
<View className="flex-row items-center gap-2">
|
|
246
|
+
<Pressable onPress={() => library.setPathPrefix([])}>
|
|
247
|
+
<ThemedText className="text-sm text-muted-foreground">
|
|
248
|
+
All
|
|
249
|
+
</ThemedText>
|
|
250
|
+
</Pressable>
|
|
251
|
+
{library.pathPrefix.length > 0 ? (
|
|
252
|
+
<>
|
|
253
|
+
<ThemedText className="text-sm text-muted-foreground">
|
|
254
|
+
/
|
|
255
|
+
</ThemedText>
|
|
256
|
+
<ThemedText className="text-sm text-muted-foreground">
|
|
257
|
+
{library.pathPrefix.join(' / ')}
|
|
258
|
+
</ThemedText>
|
|
259
|
+
</>
|
|
260
|
+
) : null}
|
|
261
|
+
<Pressable
|
|
262
|
+
onPress={() => library.setHierarchy(!library.hierarchy)}
|
|
263
|
+
className="ml-auto"
|
|
264
|
+
>
|
|
265
|
+
{library.hierarchy ? (
|
|
266
|
+
<ChevronDownIcon size={20} className="text-muted-foreground" />
|
|
267
|
+
) : (
|
|
268
|
+
<ChevronRightIcon size={20} className="text-muted-foreground" />
|
|
269
|
+
)}
|
|
270
|
+
</Pressable>
|
|
271
|
+
</View>
|
|
272
|
+
{library.hierarchy && treeNodes.length ? (
|
|
273
|
+
<View className="ml-3 gap-y-1">
|
|
274
|
+
<Tree
|
|
275
|
+
nodes={treeNodes}
|
|
276
|
+
selected={library.pathPrefix}
|
|
277
|
+
onSelect={library.setPathPrefix}
|
|
278
|
+
counts={collectionCounts}
|
|
279
|
+
expanded={expanded}
|
|
280
|
+
onToggle={toggleNode}
|
|
281
|
+
/>
|
|
282
|
+
</View>
|
|
283
|
+
) : null}
|
|
284
|
+
</View>
|
|
285
|
+
|
|
286
|
+
{/* Tags (collapsible secondary discovery) */}
|
|
287
|
+
{library.tags.length ? (
|
|
288
|
+
<View className="gap-y-1">
|
|
289
|
+
<View className="flex-row flex-wrap gap-1">
|
|
290
|
+
{visibleTags.map((entry) => {
|
|
291
|
+
const isSelected = library.selectedTags.includes(entry.name);
|
|
292
|
+
return (
|
|
293
|
+
<Pressable
|
|
294
|
+
key={entry.name}
|
|
295
|
+
onPress={() => library.toggleTag(entry.name)}
|
|
296
|
+
className={`rounded-full px-2 py-0.5 ${
|
|
297
|
+
isSelected ? 'bg-primary' : 'bg-muted'
|
|
298
|
+
}`}
|
|
299
|
+
>
|
|
300
|
+
<ThemedText className="text-xs">
|
|
301
|
+
#{entry.name} {entry.count}
|
|
302
|
+
</ThemedText>
|
|
303
|
+
</Pressable>
|
|
304
|
+
);
|
|
305
|
+
})}
|
|
306
|
+
</View>
|
|
307
|
+
{hasMoreTags ? (
|
|
308
|
+
<Pressable
|
|
309
|
+
onPress={() => library.setTagsOpen(!library.tagsOpen)}
|
|
310
|
+
className="rounded-full bg-muted px-2 py-0.5"
|
|
311
|
+
>
|
|
312
|
+
<ThemedText className="text-xs text-muted-foreground">
|
|
313
|
+
{library.tagsOpen
|
|
314
|
+
? t('resources.library.hideTags', {
|
|
315
|
+
defaultValue: 'Hide',
|
|
316
|
+
})
|
|
317
|
+
: t('resources.library.showHiddenTags', {
|
|
318
|
+
defaultValue: '+ {{count}}',
|
|
319
|
+
count: sortedTags.length - COLLECTION_LIMIT,
|
|
320
|
+
})}
|
|
321
|
+
</ThemedText>
|
|
322
|
+
</Pressable>
|
|
323
|
+
) : null}
|
|
324
|
+
</View>
|
|
325
|
+
) : null}
|
|
326
|
+
|
|
327
|
+
{/* Resource count */}
|
|
328
|
+
{library.posts.length > 0 ? (
|
|
329
|
+
<ThemedText className="text-xs text-muted-foreground">
|
|
330
|
+
{t('resources.library.resourceCount', {
|
|
331
|
+
defaultValue: 'Showing {{count}} resources',
|
|
332
|
+
count: library.posts.length,
|
|
333
|
+
})}
|
|
334
|
+
</ThemedText>
|
|
335
|
+
) : null}
|
|
336
|
+
</View>
|
|
337
|
+
|
|
338
|
+
{library.query.isLoading ? (
|
|
339
|
+
<View className="h-32 items-center justify-center">
|
|
340
|
+
<LoadingSpinner size="large" />
|
|
341
|
+
</View>
|
|
342
|
+
) : library.posts.length === 0 ? (
|
|
343
|
+
<ThemedText className="p-8 text-center text-muted-foreground">
|
|
344
|
+
{library.activeFilterCount > 0
|
|
345
|
+
? t('resources.library.noResults', {
|
|
346
|
+
defaultValue: 'No resources match your filters.',
|
|
347
|
+
})
|
|
348
|
+
: library.pathPrefix.length
|
|
349
|
+
? t('resources.library.emptyCollection', {
|
|
350
|
+
defaultValue: 'This collection has no resources yet.',
|
|
351
|
+
})
|
|
352
|
+
: t('resources.library.empty', {
|
|
353
|
+
defaultValue: 'No resources yet.',
|
|
354
|
+
})}
|
|
355
|
+
</ThemedText>
|
|
356
|
+
) : library.view === 'list' ? (
|
|
357
|
+
<View className="divide-border">
|
|
358
|
+
{library.posts.map((post) => (
|
|
359
|
+
<ResourceCard key={post.id} post={post} layout="list" />
|
|
360
|
+
))}
|
|
361
|
+
</View>
|
|
362
|
+
) : (
|
|
363
|
+
<ScrollView horizontal={false} contentContainerClassName="gap-4 p-4">
|
|
364
|
+
{library.posts.map((post) => (
|
|
365
|
+
<ResourceCard key={post.id} post={post} layout="card" />
|
|
366
|
+
))}
|
|
367
|
+
</ScrollView>
|
|
368
|
+
)}
|
|
369
|
+
</View>
|
|
370
|
+
);
|
|
371
|
+
};
|