@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,241 @@
|
|
|
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
|
+
defaultValue: 'Title',
|
|
82
|
+
})}
|
|
83
|
+
</ThemedText>
|
|
84
|
+
<Input
|
|
85
|
+
value={resource.title}
|
|
86
|
+
onChangeText={(title) => patchResource({ title })}
|
|
87
|
+
/>
|
|
88
|
+
|
|
89
|
+
<ThemedText className="text-sm font-medium">
|
|
90
|
+
{t('resources.form.kind', {
|
|
91
|
+
defaultValue: 'Type',
|
|
92
|
+
})}
|
|
93
|
+
</ThemedText>
|
|
94
|
+
<View className="flex-row flex-wrap gap-2">
|
|
95
|
+
{RESOURCE_KINDS.map((kind) => (
|
|
96
|
+
<Pressable
|
|
97
|
+
key={kind}
|
|
98
|
+
onPress={() =>
|
|
99
|
+
patchResource({ resourceKind: kind as ResourceKind })
|
|
100
|
+
}
|
|
101
|
+
className={`rounded-full px-3 py-1 ${
|
|
102
|
+
resource.resourceKind === kind ? 'bg-primary' : 'bg-muted'
|
|
103
|
+
}`}
|
|
104
|
+
>
|
|
105
|
+
<ThemedText
|
|
106
|
+
className={
|
|
107
|
+
resource.resourceKind === kind
|
|
108
|
+
? 'text-xs text-primary-foreground'
|
|
109
|
+
: 'text-xs text-muted-foreground'
|
|
110
|
+
}
|
|
111
|
+
>
|
|
112
|
+
{t(`resources.kinds.${kind}`, { defaultValue: kind })}
|
|
113
|
+
</ThemedText>
|
|
114
|
+
</Pressable>
|
|
115
|
+
))}
|
|
116
|
+
</View>
|
|
117
|
+
|
|
118
|
+
{resource.resourceKind === 'link' ? (
|
|
119
|
+
<>
|
|
120
|
+
<ThemedText className="text-sm font-medium">
|
|
121
|
+
{t('resources.form.url', {
|
|
122
|
+
defaultValue: 'URL',
|
|
123
|
+
})}
|
|
124
|
+
</ThemedText>
|
|
125
|
+
<Input
|
|
126
|
+
value={resource.url ?? ''}
|
|
127
|
+
onChangeText={(url) => patchResource({ url })}
|
|
128
|
+
autoCapitalize="none"
|
|
129
|
+
/>
|
|
130
|
+
</>
|
|
131
|
+
) : (
|
|
132
|
+
<>
|
|
133
|
+
<Pressable
|
|
134
|
+
onPress={openMedia}
|
|
135
|
+
className="items-center rounded-md border border-input px-3 py-2"
|
|
136
|
+
>
|
|
137
|
+
<ThemedText>
|
|
138
|
+
{t('resources.form.addMedia', { defaultValue: 'Add files' })}
|
|
139
|
+
</ThemedText>
|
|
140
|
+
</Pressable>
|
|
141
|
+
<ComposeAttachments
|
|
142
|
+
attachments={resource.attachments ?? []}
|
|
143
|
+
removeAttachment={(index) =>
|
|
144
|
+
patchResource({
|
|
145
|
+
attachments: (resource.attachments ?? []).filter(
|
|
146
|
+
(_, i) => i !== index
|
|
147
|
+
),
|
|
148
|
+
})
|
|
149
|
+
}
|
|
150
|
+
updateAttachment={(index, attachment) =>
|
|
151
|
+
patchResource({
|
|
152
|
+
attachments: (resource.attachments ?? []).map((item, i) =>
|
|
153
|
+
i === index ? attachment : item
|
|
154
|
+
),
|
|
155
|
+
})
|
|
156
|
+
}
|
|
157
|
+
/>
|
|
158
|
+
</>
|
|
159
|
+
)}
|
|
160
|
+
|
|
161
|
+
<OpenpeepsMarkdownInput
|
|
162
|
+
rows={8}
|
|
163
|
+
maxLength={4000}
|
|
164
|
+
value={resource.content ?? ''}
|
|
165
|
+
onChange={(content) => patchResource({ content })}
|
|
166
|
+
placeholder={t('resources.form.descriptionPlaceholder', {
|
|
167
|
+
defaultValue: 'Describe this resource',
|
|
168
|
+
})}
|
|
169
|
+
/>
|
|
170
|
+
|
|
171
|
+
<ThemedText className="text-sm font-medium">
|
|
172
|
+
{t('resources.form.tags', {
|
|
173
|
+
defaultValue: 'Tags',
|
|
174
|
+
})}
|
|
175
|
+
</ThemedText>
|
|
176
|
+
<Input
|
|
177
|
+
value={tagDraft}
|
|
178
|
+
onChangeText={setTagDraft}
|
|
179
|
+
onSubmitEditing={addTag}
|
|
180
|
+
placeholder={t('resources.form.tagsPlaceholder', {
|
|
181
|
+
defaultValue: 'Add tags, then press Enter',
|
|
182
|
+
})}
|
|
183
|
+
/>
|
|
184
|
+
<View className="flex-row flex-wrap gap-1">
|
|
185
|
+
{normalizeResourceTags(resource.tags).map((tag) => (
|
|
186
|
+
<Pressable
|
|
187
|
+
key={tag}
|
|
188
|
+
onPress={() =>
|
|
189
|
+
patchResource({
|
|
190
|
+
tags: (resource.tags ?? []).filter(
|
|
191
|
+
(value) => value.toLowerCase() !== tag
|
|
192
|
+
),
|
|
193
|
+
})
|
|
194
|
+
}
|
|
195
|
+
>
|
|
196
|
+
<ThemedText className="rounded-full bg-muted px-2 py-0.5 text-xs">
|
|
197
|
+
#{tag}
|
|
198
|
+
</ThemedText>
|
|
199
|
+
</Pressable>
|
|
200
|
+
))}
|
|
201
|
+
</View>
|
|
202
|
+
|
|
203
|
+
<ThemedText className="text-sm font-medium">
|
|
204
|
+
{t('resources.form.hierarchy', {
|
|
205
|
+
defaultValue: 'Place in the library',
|
|
206
|
+
})}
|
|
207
|
+
</ThemedText>
|
|
208
|
+
<Input
|
|
209
|
+
value={(resource.categoryPath ?? []).join(' / ')}
|
|
210
|
+
onChangeText={(value) =>
|
|
211
|
+
patchResource({
|
|
212
|
+
categoryPath: value
|
|
213
|
+
.split('/')
|
|
214
|
+
.map((segment) => segment.trim())
|
|
215
|
+
.filter(Boolean),
|
|
216
|
+
})
|
|
217
|
+
}
|
|
218
|
+
placeholder={t('resources.form.addLevel', {
|
|
219
|
+
defaultValue: 'Add a folder',
|
|
220
|
+
})}
|
|
221
|
+
/>
|
|
222
|
+
|
|
223
|
+
<ThemedText className="text-sm font-medium">
|
|
224
|
+
{t('resources.form.visibility', {
|
|
225
|
+
defaultValue: 'Who can see this (Required)',
|
|
226
|
+
})}
|
|
227
|
+
</ThemedText>
|
|
228
|
+
<VisibilitySelector
|
|
229
|
+
audienceSetting={postData}
|
|
230
|
+
onChange={setAudience}
|
|
231
|
+
disabled={isEdit}
|
|
232
|
+
showDirect
|
|
233
|
+
/>
|
|
234
|
+
</View>
|
|
235
|
+
<ImagePickerSheet ref={imageRef} onSelect={addAttachments} />
|
|
236
|
+
<VideoPickerSheet ref={videoRef} onSelect={addAttachments} />
|
|
237
|
+
<AudioPickerSheet ref={audioRef} onSelect={addAttachments} />
|
|
238
|
+
<DocumentPickerSheet ref={documentRef} onSelect={addAttachments} />
|
|
239
|
+
</View>
|
|
240
|
+
);
|
|
241
|
+
};
|
|
@@ -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
|
+
};
|