@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,369 @@
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
+ />
164
+ <View className="flex-row flex-wrap items-center justify-between gap-2">
165
+ <View className="flex-row flex-wrap gap-2">
166
+ {(['all', ...RESOURCE_KINDS] as const).map((kind) => (
167
+ <Pressable
168
+ key={kind}
169
+ onPress={() =>
170
+ library.setKind(
171
+ kind === 'all' ? 'all' : (kind as ResourceKind)
172
+ )
173
+ }
174
+ className={`rounded-full px-3 py-1 ${
175
+ library.kind === kind ? 'bg-primary' : 'bg-muted'
176
+ }`}
177
+ >
178
+ <ThemedText
179
+ className={
180
+ library.kind === kind
181
+ ? 'text-primary-foreground text-xs'
182
+ : 'text-muted-foreground text-xs'
183
+ }
184
+ >
185
+ {kind === 'all'
186
+ ? t('resources.library.allKinds')
187
+ : t(`resources.kinds.${kind}`)}
188
+ </ThemedText>
189
+ </Pressable>
190
+ ))}
191
+ </View>
192
+ <View className="flex-row gap-1">
193
+ <Pressable
194
+ onPress={() => library.setView('list')}
195
+ className={`rounded-full p-2 ${
196
+ library.view === 'list' ? 'bg-primary' : 'bg-muted'
197
+ }`}
198
+ >
199
+ <LayoutListIcon
200
+ size={20}
201
+ className={
202
+ library.view === 'list'
203
+ ? 'text-primary-foreground'
204
+ : 'text-muted-foreground'
205
+ }
206
+ />
207
+ </Pressable>
208
+ <Pressable
209
+ onPress={() => library.setView('cards')}
210
+ className={`rounded-full p-2 ${
211
+ library.view === 'cards' ? 'bg-primary' : 'bg-muted'
212
+ }`}
213
+ >
214
+ <LayoutGridIcon
215
+ size={20}
216
+ className={
217
+ library.view === 'cards'
218
+ ? 'text-primary-foreground'
219
+ : 'text-muted-foreground'
220
+ }
221
+ />
222
+ </Pressable>
223
+ <Pressable
224
+ onPress={() => library.setSaved(!library.saved)}
225
+ className={`rounded-full p-2 ${
226
+ library.saved ? 'bg-primary' : 'bg-muted'
227
+ }`}
228
+ >
229
+ <BookmarkIcon
230
+ size={20}
231
+ className={
232
+ library.saved
233
+ ? 'text-primary-foreground'
234
+ : 'text-muted-foreground'
235
+ }
236
+ />
237
+ </Pressable>
238
+ </View>
239
+ </View>
240
+
241
+ {/* Breadcrumb + tree */}
242
+ <View>
243
+ <View className="flex-row items-center gap-2">
244
+ <Pressable onPress={() => library.setPathPrefix([])}>
245
+ <ThemedText className="text-sm text-muted-foreground">
246
+ All
247
+ </ThemedText>
248
+ </Pressable>
249
+ {library.pathPrefix.length > 0 ? (
250
+ <>
251
+ <ThemedText className="text-sm text-muted-foreground">
252
+ /
253
+ </ThemedText>
254
+ <ThemedText className="text-sm text-muted-foreground">
255
+ {library.pathPrefix.join(' / ')}
256
+ </ThemedText>
257
+ </>
258
+ ) : null}
259
+ <Pressable
260
+ onPress={() => library.setHierarchy(!library.hierarchy)}
261
+ className="ml-auto"
262
+ >
263
+ {library.hierarchy ? (
264
+ <ChevronDownIcon size={20} className="text-muted-foreground" />
265
+ ) : (
266
+ <ChevronRightIcon size={20} className="text-muted-foreground" />
267
+ )}
268
+ </Pressable>
269
+ </View>
270
+ {library.hierarchy && treeNodes.length ? (
271
+ <View className="ml-3 gap-y-1">
272
+ <Tree
273
+ nodes={treeNodes}
274
+ selected={library.pathPrefix}
275
+ onSelect={library.setPathPrefix}
276
+ counts={collectionCounts}
277
+ expanded={expanded}
278
+ onToggle={toggleNode}
279
+ />
280
+ </View>
281
+ ) : null}
282
+ </View>
283
+
284
+ {/* Tags (collapsible secondary discovery) */}
285
+ {library.tags.length ? (
286
+ <View className="gap-y-1">
287
+ <View className="flex-row flex-wrap gap-1">
288
+ {visibleTags.map((entry) => {
289
+ const isSelected = library.selectedTags.includes(entry.name);
290
+ return (
291
+ <Pressable
292
+ key={entry.name}
293
+ onPress={() => library.toggleTag(entry.name)}
294
+ className={`rounded-full px-2 py-0.5 ${
295
+ isSelected ? 'bg-primary' : 'bg-muted'
296
+ }`}
297
+ >
298
+ <ThemedText className="text-xs">
299
+ #{entry.name} {entry.count}
300
+ </ThemedText>
301
+ </Pressable>
302
+ );
303
+ })}
304
+ </View>
305
+ {hasMoreTags ? (
306
+ <Pressable
307
+ onPress={() => library.setTagsOpen(!library.tagsOpen)}
308
+ className="rounded-full bg-muted px-2 py-0.5"
309
+ >
310
+ <ThemedText className="text-xs text-muted-foreground">
311
+ {library.tagsOpen
312
+ ? t('resources.library.hideTags', {
313
+ defaultValue: 'Hide',
314
+ })
315
+ : t('resources.library.showHiddenTags', {
316
+ defaultValue: '+ {{count}}',
317
+ count: sortedTags.length - COLLECTION_LIMIT,
318
+ })}
319
+ </ThemedText>
320
+ </Pressable>
321
+ ) : null}
322
+ </View>
323
+ ) : null}
324
+
325
+ {/* Resource count */}
326
+ {library.posts.length > 0 ? (
327
+ <ThemedText className="text-xs text-muted-foreground">
328
+ {t('resources.library.resourceCount', {
329
+ defaultValue: 'Showing {{count}} resources',
330
+ count: library.posts.length,
331
+ })}
332
+ </ThemedText>
333
+ ) : null}
334
+ </View>
335
+
336
+ {library.query.isLoading ? (
337
+ <View className="h-32 items-center justify-center">
338
+ <LoadingSpinner size="large" />
339
+ </View>
340
+ ) : library.posts.length === 0 ? (
341
+ <ThemedText className="p-8 text-center text-muted-foreground">
342
+ {library.activeFilterCount > 0
343
+ ? t('resources.library.noResults', {
344
+ defaultValue: 'No resources match your filters.',
345
+ })
346
+ : library.pathPrefix.length
347
+ ? t('resources.library.emptyCollection', {
348
+ defaultValue: 'This collection has no resources yet.',
349
+ })
350
+ : t('resources.library.empty', {
351
+ defaultValue: 'No resources yet.',
352
+ })}
353
+ </ThemedText>
354
+ ) : library.view === 'list' ? (
355
+ <View className="divide-border">
356
+ {library.posts.map((post) => (
357
+ <ResourceCard key={post.id} post={post} layout="list" />
358
+ ))}
359
+ </View>
360
+ ) : (
361
+ <ScrollView horizontal={false} contentContainerClassName="gap-4 p-4">
362
+ {library.posts.map((post) => (
363
+ <ResourceCard key={post.id} post={post} layout="card" />
364
+ ))}
365
+ </ScrollView>
366
+ )}
367
+ </View>
368
+ );
369
+ };
@@ -0,0 +1,4 @@
1
+ export { ResourceLibrary } from './ResourceLibrary';
2
+ export type { ResourceLibraryProps } from './ResourceLibrary';
3
+ export { ResourceCard } from './ResourceCard';
4
+ export type { ResourceCardProps } from './ResourceCard';
package/src/global.css CHANGED
@@ -4,50 +4,50 @@
4
4
 
5
5
  @layer base {
6
6
  :root {
7
- --background: 255 255 255;
8
- --foreground: 10 10 11;
9
- --card: 255 255 255;
10
- --card-foreground: 10 10 11;
11
- --popover: 255 255 255;
12
- --popover-foreground: 10 10 11;
13
- --primary: 22 22 26;
14
- --primary-foreground: 250 250 250;
15
- --secondary: 244 244 245;
16
- --secondary-foreground: 22 22 26;
17
- --muted: 244 244 246;
18
- --muted-foreground: 113 113 122;
19
- --accent: 244 244 245;
20
- --accent-foreground: 22 22 26;
21
- --destructive: 239 68 68;
22
- --destructive-foreground: 250 250 250;
23
- --border: 228 228 231;
24
- --input: 228 228 231;
25
- --ring: 22 22 26;
26
- --alpha: 250 250 250;
27
- --surface-2: 228 228 231;
7
+ --background: #ffffff;
8
+ --foreground: #0a0a0b;
9
+ --card: #ffffff;
10
+ --card-foreground: #0a0a0b;
11
+ --popover: #ffffff;
12
+ --popover-foreground: #0a0a0b;
13
+ --primary: #16161a;
14
+ --primary-foreground: #fafafa;
15
+ --secondary: #f4f4f5;
16
+ --secondary-foreground: #16161a;
17
+ --muted: #f4f4f6;
18
+ --muted-foreground: #71717a;
19
+ --accent: #f4f4f5;
20
+ --accent-foreground: #16161a;
21
+ --destructive: #ef4444;
22
+ --destructive-foreground: #fafafa;
23
+ --border: #e4e4e7;
24
+ --input: #e4e4e7;
25
+ --ring: #16161a;
26
+ --alpha: #fafafa;
27
+ --surface-2: #e4e4e7;
28
28
  }
29
29
 
30
30
  .dark:root {
31
- --background: 10 10 15;
32
- --foreground: 250 250 250;
33
- --card: 10 10 15;
34
- --card-foreground: 250 250 250;
35
- --popover: 10 10 15;
36
- --popover-foreground: 250 250 250;
37
- --primary: 250 250 250;
38
- --primary-foreground: 22 22 26;
39
- --secondary: 40 40 46;
40
- --secondary-foreground: 250 250 250;
41
- --muted: 39 39 42;
42
- --muted-foreground: 161 161 170;
43
- --accent: 40 40 46;
44
- --accent-foreground: 250 250 250;
45
- --destructive: 220 38 38;
46
- --destructive-foreground: 250 250 250;
47
- --border: 40 40 46;
48
- --input: 40 40 46;
49
- --ring: 212 212 216;
50
- --alpha: 24 24 27;
51
- --surface-2: 63 63 70;
31
+ --background: #0a0a0f;
32
+ --foreground: #fafafa;
33
+ --card: #0a0a0f;
34
+ --card-foreground: #fafafa;
35
+ --popover: #0a0a0f;
36
+ --popover-foreground: #fafafa;
37
+ --primary: #fafafa;
38
+ --primary-foreground: #16161a;
39
+ --secondary: #28282e;
40
+ --secondary-foreground: #fafafa;
41
+ --muted: #27272a;
42
+ --muted-foreground: #a1a1aa;
43
+ --accent: #28282e;
44
+ --accent-foreground: #fafafa;
45
+ --destructive: #dc2626;
46
+ --destructive-foreground: #fafafa;
47
+ --border: #28282e;
48
+ --input: #28282e;
49
+ --ring: #d4d4d8;
50
+ --alpha: #18181b;
51
+ --surface-2: #3f3f46;
52
52
  }
53
53
  }
@@ -22,7 +22,9 @@ import {
22
22
  EventsFeed,
23
23
  NewEventButton,
24
24
  NewNoteButton,
25
+ NewResourceButton,
25
26
  } from '../../components/post/index';
27
+ import { ResourceLibrary } from '../../components/resources';
26
28
  import {
27
29
  Tabs,
28
30
  TabsContent,
@@ -38,7 +40,7 @@ type GroupProps = CompositeScreenProps<
38
40
  NativeStackScreenProps<TabStackParamList>
39
41
  >;
40
42
 
41
- type Tab = 'posts' | 'events' | 'description';
43
+ type Tab = 'posts' | 'events' | 'resources' | 'description';
42
44
 
43
45
  export const GroupShow = ({ route, navigation }: GroupProps) => {
44
46
  const { openpeepsApi } = useOpenpeeps();
@@ -114,6 +116,12 @@ export const GroupShow = ({ route, navigation }: GroupProps) => {
114
116
  <TabsTrigger value="events" className={tabClass('events')}>
115
117
  <ThemedText>{t('groups.sections.events')}</ThemedText>
116
118
  </TabsTrigger>
119
+ <TabsTrigger
120
+ value="resources"
121
+ className={tabClass('resources')}
122
+ >
123
+ <ThemedText>{t('groups.sections.resources')}</ThemedText>
124
+ </TabsTrigger>
117
125
  <TabsTrigger
118
126
  value="description"
119
127
  className={tabClass('description')}
@@ -159,6 +167,9 @@ export const GroupShow = ({ route, navigation }: GroupProps) => {
159
167
  query={eventsTab === 'upcoming' ? upcomingEvents : pastEvents}
160
168
  />
161
169
  </TabsContent>
170
+ <TabsContent value="resources" className="p-0">
171
+ <ResourceLibrary groupId={group.id} />
172
+ </TabsContent>
162
173
  <TabsContent value="description" className="p-2">
163
174
  <GroupInfoAsComponent id={group.id} />
164
175
  </TabsContent>
@@ -180,6 +191,13 @@ export const GroupShow = ({ route, navigation }: GroupProps) => {
180
191
  group={group}
181
192
  />
182
193
  ) : null}
194
+ {group && tab === 'resources' ? (
195
+ <NewResourceButton
196
+ visibility="group"
197
+ currentProfile={currentProfile}
198
+ group={group}
199
+ />
200
+ ) : null}
183
201
  </ThemedView>
184
202
  );
185
203
  };
@@ -49,6 +49,9 @@ export { Tags } from './Tags';
49
49
  export { Explore } from './Explore';
50
50
  export { FeedsBookmarks } from './feeds/Bookmarks';
51
51
  export { ArticlesIndex } from './articles/Index';
52
+ export { ResourcesIndex } from './resources/Index';
53
+ export { NewResource } from './resources/New';
54
+ export { EditResource } from './resources/Edit';
52
55
  export { LanguageSettings } from './settings/Language';
53
56
  export { TimezoneSettings } from './settings/Timezone';
54
57
  export { NotificationSettings } from './settings/Notifications';
@@ -0,0 +1,72 @@
1
+ import React from 'react';
2
+ import { ActivityIndicator } from 'react-native';
3
+ import { KeyboardAwareScrollView } from 'react-native-keyboard-aware-scroll-view';
4
+ import { useTranslation } from 'react-i18next';
5
+ import Toast from 'react-native-toast-message';
6
+ import { truncateText } from '@openpeepshq/common/lib';
7
+ import { useEditResource } from '@openpeepshq/react';
8
+ import { HeaderActionButton, useSetPageHeader } from '../../components/layout';
9
+ import { ThemedView } from '../../components/ui/themed-view';
10
+ import { MainScreenProps } from '../../components/navigation/types/index';
11
+ import { ResourceForm } from '../../components/post/index';
12
+ import { ThemedText } from '../../components/ui/themed-text';
13
+
14
+ type EditResourceProps = MainScreenProps<'EditResource'>;
15
+
16
+ export const EditResource: React.FC<EditResourceProps> = ({ route }) => {
17
+ const { id } = route.params;
18
+ const { t } = useTranslation();
19
+ const {
20
+ postQuery,
21
+ postData,
22
+ setPostData,
23
+ resourceTitle,
24
+ submitting,
25
+ error,
26
+ clearError,
27
+ submit,
28
+ } = useEditResource(id);
29
+
30
+ React.useEffect(() => {
31
+ if (!error) return;
32
+ Toast.show({ type: 'error', text1: error });
33
+ clearError();
34
+ }, [error, clearError]);
35
+
36
+ const title = resourceTitle
37
+ ? `${t('resources.edit')} ${truncateText(resourceTitle)}`
38
+ : t('resources.edit');
39
+
40
+ useSetPageHeader(
41
+ title,
42
+ <HeaderActionButton
43
+ title={
44
+ submitting
45
+ ? t('common.saving', { defaultValue: 'Saving…' })
46
+ : t('resources.update.title', { defaultValue: 'Update resource' })
47
+ }
48
+ onPress={() => void submit()}
49
+ disabled={submitting || !postData}
50
+ loading={submitting}
51
+ />
52
+ );
53
+
54
+ return (
55
+ <ThemedView className="flex-1">
56
+ {postQuery.isLoading ? (
57
+ <ActivityIndicator size="small" />
58
+ ) : !postQuery.data || !postData ? (
59
+ <ThemedText className="p-8 text-center text-2xl">
60
+ {t('resources.notFound')}
61
+ </ThemedText>
62
+ ) : (
63
+ <KeyboardAwareScrollView
64
+ contentContainerClassName="grow"
65
+ className="pb-12"
66
+ >
67
+ <ResourceForm postData={postData} onChange={setPostData} isEdit />
68
+ </KeyboardAwareScrollView>
69
+ )}
70
+ </ThemedView>
71
+ );
72
+ };
@@ -0,0 +1,25 @@
1
+ import React from 'react';
2
+ import { useTranslation } from 'react-i18next';
3
+ import { useCurrentProfile, useDefaultVisibility } from '@openpeepshq/react';
4
+ import { useSetPageHeader } from '../../components/layout';
5
+ import { NewResourceButton } from '../../components/post/index';
6
+ import { ResourceLibrary } from '../../components/resources/index';
7
+ import { ThemedView } from '../../components/ui/themed-view';
8
+
9
+ export const ResourcesIndex = () => {
10
+ const { t } = useTranslation();
11
+ const currentProfile = useCurrentProfile();
12
+ const visibility = useDefaultVisibility();
13
+
14
+ useSetPageHeader(t('navigation.resources'));
15
+
16
+ return (
17
+ <ThemedView className="relative flex-1">
18
+ <ResourceLibrary />
19
+ <NewResourceButton
20
+ visibility={visibility}
21
+ currentProfile={currentProfile}
22
+ />
23
+ </ThemedView>
24
+ );
25
+ };
@@ -0,0 +1,55 @@
1
+ import React from 'react';
2
+ import { KeyboardAwareScrollView } from 'react-native-keyboard-aware-scroll-view';
3
+ import { useTranslation } from 'react-i18next';
4
+ import Toast from 'react-native-toast-message';
5
+ import { useNewResource } from '@openpeepshq/react';
6
+ import { HeaderActionButton, useSetPageHeader } from '../../components/layout';
7
+ import { ThemedView } from '../../components/ui/themed-view';
8
+ import { MainScreenProps } from '../../components/navigation/types/index';
9
+ import { ResourceForm } from '../../components/post/index';
10
+
11
+ type NewResourceProps = MainScreenProps<'NewResource'>;
12
+
13
+ export const NewResource: React.FC<NewResourceProps> = () => {
14
+ const { t } = useTranslation();
15
+ const {
16
+ postData,
17
+ setPostData,
18
+ canSubmit,
19
+ submitting,
20
+ error,
21
+ clearError,
22
+ submit,
23
+ } = useNewResource();
24
+
25
+ React.useEffect(() => {
26
+ if (!error) return;
27
+ Toast.show({ type: 'error', text1: error });
28
+ clearError();
29
+ }, [error, clearError]);
30
+
31
+ useSetPageHeader(
32
+ t('resources.new', { defaultValue: 'New resource' }),
33
+ <HeaderActionButton
34
+ title={
35
+ submitting
36
+ ? t('common.submitting', { defaultValue: 'Submitting…' })
37
+ : t('resources.create.title', { defaultValue: 'Create resource' })
38
+ }
39
+ onPress={() => void submit()}
40
+ disabled={submitting || !canSubmit}
41
+ loading={submitting}
42
+ />
43
+ );
44
+
45
+ return (
46
+ <ThemedView className="flex-1">
47
+ <KeyboardAwareScrollView
48
+ contentContainerClassName="grow"
49
+ className="pb-12"
50
+ >
51
+ <ResourceForm postData={postData} onChange={setPostData} />
52
+ </KeyboardAwareScrollView>
53
+ </ThemedView>
54
+ );
55
+ };