@openpeepshq/rn-components 0.8.0 → 0.8.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.
- package/package.json +3 -3
- package/src/components/custom/modals/media/audio-picker-sheet.tsx +21 -25
- package/src/components/custom/modals/media/document-picker-sheet.tsx +22 -16
- package/src/components/custom/modals/media/video-picker-sheet.tsx +4 -2
- package/src/components/markdown/extensions/link.tsx +1 -1
- package/src/components/post/post-form/ResourceForm.tsx +28 -11
- package/src/components/resources/ResourceCard.tsx +17 -1
- package/src/pages/groups/Index.tsx +2 -4
- package/src/pages/groups/New.tsx +25 -12
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openpeepshq/rn-components",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.2",
|
|
4
4
|
"description": "React Native community screens and shared UI (extracted from the Black Ambition app) for the OpenPeeps stack.",
|
|
5
5
|
"source": "./src/index.ts",
|
|
6
6
|
"main": "./src/index.ts",
|
|
@@ -142,8 +142,8 @@
|
|
|
142
142
|
"timezones-list": "^3.1.0",
|
|
143
143
|
"validator": "^13.15.23",
|
|
144
144
|
"zustand": "^5.0.3",
|
|
145
|
-
"@openpeepshq/
|
|
146
|
-
"@openpeepshq/
|
|
145
|
+
"@openpeepshq/common": "^0.4.0",
|
|
146
|
+
"@openpeepshq/react": "^0.8.2"
|
|
147
147
|
},
|
|
148
148
|
"devDependencies": {
|
|
149
149
|
"@babel/core": "^7.26.7",
|
|
@@ -23,12 +23,14 @@ const { width: SCREEN_WIDTH } = Dimensions.get('window');
|
|
|
23
23
|
|
|
24
24
|
interface AudioPickerSheetProps {
|
|
25
25
|
onSelect: (audioAttachments: MediaAttachment[]) => void | Promise<void>;
|
|
26
|
+
/** When false, the sheet selects a single file (no multiple toggle). */
|
|
27
|
+
multiple?: boolean;
|
|
26
28
|
}
|
|
27
29
|
|
|
28
30
|
export const AudioPickerSheet = forwardRef<
|
|
29
31
|
BottomSheetModal,
|
|
30
32
|
AudioPickerSheetProps
|
|
31
|
-
>(({ onSelect }, ref) => {
|
|
33
|
+
>(({ onSelect, multiple = true }, ref) => {
|
|
32
34
|
const [selectedAudios, setSelectedAudios] = useState<string[]>([]);
|
|
33
35
|
const [isMultipleSelect, setIsMultipleSelect] = useState(false);
|
|
34
36
|
const [currentAudioIndex, setCurrentAudioIndex] = useState(0);
|
|
@@ -122,39 +124,33 @@ export const AudioPickerSheet = forwardRef<
|
|
|
122
124
|
<View className="flex-1">
|
|
123
125
|
{renderSelectedAudiosPreview()}
|
|
124
126
|
|
|
125
|
-
|
|
126
|
-
<View className="flex-row items-center
|
|
127
|
-
<
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
size={'icon'}
|
|
139
|
-
className="rounded-full"
|
|
140
|
-
onPress={handleMicrophonePress}>
|
|
141
|
-
<MicIcon size={16} className="text-foreground" />
|
|
142
|
-
</Button> */}
|
|
127
|
+
{multiple ? (
|
|
128
|
+
<View className="flex-row justify-between items-center px-4 py-3">
|
|
129
|
+
<View className="flex-row items-center gap-4">
|
|
130
|
+
<Button
|
|
131
|
+
variant={isMultipleSelect ? 'secondary' : 'ghost'}
|
|
132
|
+
size={'sm'}
|
|
133
|
+
onPress={() => setIsMultipleSelect(!isMultipleSelect)}
|
|
134
|
+
>
|
|
135
|
+
<Text className="text-foreground text-base font-medium">
|
|
136
|
+
{t('common.form.selectMultiple')}
|
|
137
|
+
</Text>
|
|
138
|
+
</Button>
|
|
139
|
+
</View>
|
|
143
140
|
</View>
|
|
144
|
-
|
|
141
|
+
) : null}
|
|
145
142
|
|
|
146
143
|
<Button
|
|
147
144
|
variant={'ghost'}
|
|
148
145
|
onPress={async () => {
|
|
149
146
|
const result = await pick({
|
|
150
147
|
type: 'audio',
|
|
151
|
-
multiple: isMultipleSelect,
|
|
148
|
+
multiple: multiple && isMultipleSelect,
|
|
152
149
|
});
|
|
153
150
|
if (result) {
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
]);
|
|
151
|
+
const uris = result.map((r) => r.uri);
|
|
152
|
+
// Single mode replaces the pick; multiple mode appends.
|
|
153
|
+
setSelectedAudios(multiple ? [...selectedAudios, ...uris] : uris);
|
|
158
154
|
}
|
|
159
155
|
}}
|
|
160
156
|
>
|
|
@@ -39,6 +39,8 @@ import {
|
|
|
39
39
|
|
|
40
40
|
interface DocumentPickerSheetProps {
|
|
41
41
|
onSelect: (documentAttachments: MediaAttachment[]) => void | Promise<void>;
|
|
42
|
+
/** When false, the picker is limited to a single file. */
|
|
43
|
+
multiple?: boolean;
|
|
42
44
|
}
|
|
43
45
|
|
|
44
46
|
export type DocumentPickerSheetHandle = {
|
|
@@ -89,7 +91,7 @@ const mergePickedDocs = (
|
|
|
89
91
|
export const DocumentPickerSheet = forwardRef<
|
|
90
92
|
DocumentPickerSheetHandle,
|
|
91
93
|
DocumentPickerSheetProps
|
|
92
|
-
>(({ onSelect }, ref) => {
|
|
94
|
+
>(({ onSelect, multiple = true }, ref) => {
|
|
93
95
|
const sheetRef = useRef<BottomSheetModal>(null);
|
|
94
96
|
const descriptionSheetRef = useRef<BottomSheetModal>(null);
|
|
95
97
|
|
|
@@ -111,14 +113,16 @@ export const DocumentPickerSheet = forwardRef<
|
|
|
111
113
|
|
|
112
114
|
const results = await pick({
|
|
113
115
|
type: [...ATTACHMENT_DOCUMENT_TYPES],
|
|
114
|
-
allowMultiSelection:
|
|
116
|
+
allowMultiSelection: multiple,
|
|
115
117
|
mode: 'import',
|
|
116
118
|
});
|
|
117
119
|
|
|
118
|
-
setSelectedDocs((prev) =>
|
|
120
|
+
setSelectedDocs((prev) =>
|
|
121
|
+
multiple ? mergePickedDocs(prev, results) : results
|
|
122
|
+
);
|
|
119
123
|
return results;
|
|
120
124
|
},
|
|
121
|
-
[]
|
|
125
|
+
[multiple]
|
|
122
126
|
);
|
|
123
127
|
|
|
124
128
|
const open = useCallback(async () => {
|
|
@@ -317,18 +321,20 @@ export const DocumentPickerSheet = forwardRef<
|
|
|
317
321
|
</View>
|
|
318
322
|
))}
|
|
319
323
|
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
324
|
+
{multiple ? (
|
|
325
|
+
<Button
|
|
326
|
+
variant="ghost"
|
|
327
|
+
className="flex-row items-center justify-center mt-2 border border-dashed border-border"
|
|
328
|
+
onPress={handlePickDocument}
|
|
329
|
+
>
|
|
330
|
+
<PlusIcon size={16} className="text-foreground mr-2" />
|
|
331
|
+
<Text className="text-foreground font-medium">
|
|
332
|
+
{t('form.documentInput.addMore', {
|
|
333
|
+
defaultValue: 'Add more files',
|
|
334
|
+
})}
|
|
335
|
+
</Text>
|
|
336
|
+
</Button>
|
|
337
|
+
) : null}
|
|
332
338
|
</View>
|
|
333
339
|
);
|
|
334
340
|
};
|
|
@@ -13,6 +13,8 @@ import { bottomSheetClose } from '../../../../lib/bottom-sheet-ref';
|
|
|
13
13
|
|
|
14
14
|
interface VideoPickerSheetProps {
|
|
15
15
|
onSelect: (videoAttachments: MediaAttachment[]) => void | Promise<void>;
|
|
16
|
+
/** When false, the library picker is limited to a single video. */
|
|
17
|
+
multiple?: boolean;
|
|
16
18
|
}
|
|
17
19
|
|
|
18
20
|
// Videos are selected via the system photo picker (launchImageLibrary), which
|
|
@@ -21,7 +23,7 @@ interface VideoPickerSheetProps {
|
|
|
21
23
|
export const VideoPickerSheet = forwardRef<
|
|
22
24
|
BottomSheetModal,
|
|
23
25
|
VideoPickerSheetProps
|
|
24
|
-
>(({ onSelect }, ref) => {
|
|
26
|
+
>(({ onSelect, multiple = true }, ref) => {
|
|
25
27
|
const [isLoading, setIsLoading] = useState(false);
|
|
26
28
|
const { t } = useTranslation();
|
|
27
29
|
const { openpeepsApi } = useOpenpeeps();
|
|
@@ -54,7 +56,7 @@ export const VideoPickerSheet = forwardRef<
|
|
|
54
56
|
const handleLibrary = async () => {
|
|
55
57
|
const result = await launchImageLibrary({
|
|
56
58
|
mediaType: 'video',
|
|
57
|
-
selectionLimit: 0,
|
|
59
|
+
selectionLimit: multiple ? 0 : 1,
|
|
58
60
|
});
|
|
59
61
|
if (result.didCancel || !result.assets?.length) {
|
|
60
62
|
return;
|
|
@@ -11,7 +11,7 @@ import { BASE_URL } from '../../../lib/constants';
|
|
|
11
11
|
export const linkRenderer =
|
|
12
12
|
(handleLinkPress: (url: string) => void): RenderFunction =>
|
|
13
13
|
(node, children, _parentNodes, styles) => {
|
|
14
|
-
const href =
|
|
14
|
+
const href = node.attributes.href || '';
|
|
15
15
|
const origin = BASE_URL as string;
|
|
16
16
|
const isExternal = isExternalLink(href, origin);
|
|
17
17
|
|
|
@@ -211,14 +211,18 @@ export const ResourceForm = ({
|
|
|
211
211
|
</>
|
|
212
212
|
) : (
|
|
213
213
|
<>
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
214
|
+
{/* Only galleries take more than one file; other kinds pick once. */}
|
|
215
|
+
{resource.resourceKind === 'gallery' ||
|
|
216
|
+
(resource.attachments ?? []).length === 0 ? (
|
|
217
|
+
<Pressable
|
|
218
|
+
onPress={openMedia}
|
|
219
|
+
className="items-center rounded-md border border-input px-3 py-2"
|
|
220
|
+
>
|
|
221
|
+
<ThemedText>
|
|
222
|
+
{t('resources.form.addMedia', { defaultValue: 'Add files' })}
|
|
223
|
+
</ThemedText>
|
|
224
|
+
</Pressable>
|
|
225
|
+
) : null}
|
|
222
226
|
<ComposeAttachments
|
|
223
227
|
attachments={resource.attachments ?? []}
|
|
224
228
|
removeAttachment={(index) =>
|
|
@@ -343,9 +347,22 @@ export const ResourceForm = ({
|
|
|
343
347
|
) : null}
|
|
344
348
|
</View>
|
|
345
349
|
<ImagePickerSheet ref={imageRef} onSelect={addAttachments} />
|
|
346
|
-
|
|
347
|
-
<
|
|
348
|
-
|
|
350
|
+
{/* Only galleries take more than one file; other kinds pick one. */}
|
|
351
|
+
<VideoPickerSheet
|
|
352
|
+
ref={videoRef}
|
|
353
|
+
multiple={false}
|
|
354
|
+
onSelect={addAttachments}
|
|
355
|
+
/>
|
|
356
|
+
<AudioPickerSheet
|
|
357
|
+
ref={audioRef}
|
|
358
|
+
multiple={false}
|
|
359
|
+
onSelect={addAttachments}
|
|
360
|
+
/>
|
|
361
|
+
<DocumentPickerSheet
|
|
362
|
+
ref={documentRef}
|
|
363
|
+
multiple={false}
|
|
364
|
+
onSelect={addAttachments}
|
|
365
|
+
/>
|
|
349
366
|
</View>
|
|
350
367
|
);
|
|
351
368
|
};
|
|
@@ -27,6 +27,7 @@ import {
|
|
|
27
27
|
BookmarkMinusIcon,
|
|
28
28
|
LinkIcon,
|
|
29
29
|
ImageOffIcon,
|
|
30
|
+
AudioLinesIcon,
|
|
30
31
|
} from '../icons';
|
|
31
32
|
|
|
32
33
|
export interface ResourceCardProps {
|
|
@@ -39,8 +40,12 @@ export interface ResourceCardProps {
|
|
|
39
40
|
inGroup?: boolean;
|
|
40
41
|
}
|
|
41
42
|
|
|
43
|
+
// Audio attachments render their generated waveform preview like any other
|
|
44
|
+
// visual; without one they fall back to the kind placeholder below.
|
|
42
45
|
const visualAttachments = (attachments: MediaAttachmentData[]) =>
|
|
43
|
-
attachments.filter(
|
|
46
|
+
attachments.filter(
|
|
47
|
+
(att) => attachmentMediaKind(att) !== 'audio' || !!att.previewUrl
|
|
48
|
+
);
|
|
44
49
|
|
|
45
50
|
const primaryActionLabel = (
|
|
46
51
|
kind: ResourceKind,
|
|
@@ -170,6 +175,13 @@ export const ResourceCard = ({
|
|
|
170
175
|
<CachedImage url={thumbSrc} className="h-12 w-12" resizeMode="cover" />
|
|
171
176
|
);
|
|
172
177
|
}
|
|
178
|
+
if (resource.resourceKind === 'audio') {
|
|
179
|
+
return (
|
|
180
|
+
<View className="h-12 w-12 items-center justify-center rounded-md bg-muted">
|
|
181
|
+
<AudioLinesIcon size={20} className="text-muted-foreground" />
|
|
182
|
+
</View>
|
|
183
|
+
);
|
|
184
|
+
}
|
|
173
185
|
if (resource.resourceKind === 'link' && resource.url) {
|
|
174
186
|
return (
|
|
175
187
|
<View className="h-12 w-12 items-center justify-center rounded-md bg-muted">
|
|
@@ -286,6 +298,10 @@ export const ResourceCard = ({
|
|
|
286
298
|
);
|
|
287
299
|
})}
|
|
288
300
|
</View>
|
|
301
|
+
) : resource.resourceKind === 'audio' ? (
|
|
302
|
+
<View className="h-48 w-full items-center justify-center rounded-md bg-muted">
|
|
303
|
+
<AudioLinesIcon size={32} className="text-muted-foreground/50" />
|
|
304
|
+
</View>
|
|
289
305
|
) : resource.resourceKind === 'link' && resource.url ? (
|
|
290
306
|
<View className="h-48 w-full items-center justify-center rounded-md bg-muted">
|
|
291
307
|
<LinkIcon size={32} className="text-muted-foreground/50" />
|
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
import { KeyboardAwareScrollView } from 'react-native-keyboard-aware-scroll-view';
|
|
9
9
|
import { CompositeScreenProps } from '@react-navigation/native';
|
|
10
10
|
import { NativeStackScreenProps } from '@react-navigation/native-stack';
|
|
11
|
-
import {
|
|
11
|
+
import { canCreateGroup } from '@openpeepshq/common';
|
|
12
12
|
import { useOpenpeeps } from '@openpeepshq/react';
|
|
13
13
|
import { useTranslation } from 'react-i18next';
|
|
14
14
|
import {
|
|
@@ -60,9 +60,7 @@ export const GroupsIndex: React.FC<GroupsProps> = ({ navigation }) => {
|
|
|
60
60
|
[groups, isMember, search, tab]
|
|
61
61
|
);
|
|
62
62
|
|
|
63
|
-
const canCreate =
|
|
64
|
-
'core-groups-create',
|
|
65
|
-
]).success;
|
|
63
|
+
const canCreate = canCreateGroup(currentProfile?.roles ?? []);
|
|
66
64
|
|
|
67
65
|
useSetPageHeader(t('navigation.groups', { defaultValue: 'Groups' }));
|
|
68
66
|
useSetPlusButtonActions(
|
package/src/pages/groups/New.tsx
CHANGED
|
@@ -13,7 +13,7 @@ import { Label } from '../../components/ui/label';
|
|
|
13
13
|
|
|
14
14
|
type NewGroupProps = MainScreenProps<'CreateGroup'>;
|
|
15
15
|
|
|
16
|
-
export const NewGroup: React.FC<NewGroupProps> = () => {
|
|
16
|
+
export const NewGroup: React.FC<NewGroupProps> = ({ navigation }) => {
|
|
17
17
|
const { t } = useTranslation();
|
|
18
18
|
const me = useCurrentProfile();
|
|
19
19
|
const {
|
|
@@ -25,6 +25,7 @@ export const NewGroup: React.FC<NewGroupProps> = () => {
|
|
|
25
25
|
error,
|
|
26
26
|
clearError,
|
|
27
27
|
fieldErrors,
|
|
28
|
+
canCreate,
|
|
28
29
|
submit,
|
|
29
30
|
} = useNewGroup();
|
|
30
31
|
|
|
@@ -34,20 +35,32 @@ export const NewGroup: React.FC<NewGroupProps> = () => {
|
|
|
34
35
|
clearError();
|
|
35
36
|
}, [error, clearError]);
|
|
36
37
|
|
|
38
|
+
React.useEffect(() => {
|
|
39
|
+
if (me && !canCreate) {
|
|
40
|
+
navigation.navigate('TabNavigator', { screen: 'Groups' });
|
|
41
|
+
}
|
|
42
|
+
}, [canCreate, me, navigation]);
|
|
43
|
+
|
|
37
44
|
useSetPageHeader(
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
45
|
+
canCreate
|
|
46
|
+
? t('groups.new.title', { defaultValue: 'Create group' })
|
|
47
|
+
: undefined,
|
|
48
|
+
canCreate ? (
|
|
49
|
+
<HeaderActionButton
|
|
50
|
+
title={
|
|
51
|
+
submitting
|
|
52
|
+
? t('common.submitting', { defaultValue: 'Creating…' })
|
|
53
|
+
: t('common.submit', { defaultValue: 'Create group' })
|
|
54
|
+
}
|
|
55
|
+
onPress={() => void submit()}
|
|
56
|
+
disabled={submitting}
|
|
57
|
+
loading={submitting}
|
|
58
|
+
/>
|
|
59
|
+
) : undefined
|
|
49
60
|
);
|
|
50
61
|
|
|
62
|
+
if (!canCreate) return null;
|
|
63
|
+
|
|
51
64
|
return (
|
|
52
65
|
<ThemedView className="flex-1">
|
|
53
66
|
<KeyboardAwareScrollView
|