@openpeepshq/rn-components 0.14.0 → 0.15.0
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 +4 -3
- package/src/components/buttonOverflow.test.tsx +463 -0
- package/src/components/conversations/ConversationParticipantsModal.tsx +1 -6
- package/src/components/groups/GroupCard.tsx +26 -23
- package/src/components/groups/JoinGroupButton.tsx +7 -2
- package/src/components/jams/JamCapacityGate.tsx +9 -1
- package/src/components/jams/JamChatDrawer.test.tsx +263 -0
- package/src/components/jams/JamChatDrawer.tsx +117 -52
- package/src/components/jams/JamConference.tsx +5 -0
- package/src/components/jams/JamFooter.tsx +26 -22
- package/src/components/jams/JamParticipantConference.tsx +7 -4
- package/src/components/jams/JamPeopleDrawer.test.tsx +216 -0
- package/src/components/jams/JamPeopleDrawer.tsx +51 -5
- package/src/components/jams/JamRequestJoin.tsx +30 -3
- package/src/components/jams/JamRoomIndicators.test.tsx +190 -38
- package/src/components/jams/JamRoomIndicators.tsx +62 -20
- package/src/components/jams/LeaveCloseButton.tsx +5 -1
- package/src/components/jams/useTrackSubscriptionBump.test.ts +294 -0
- package/src/components/jams/useTrackSubscriptionBump.ts +44 -0
- package/src/components/post/feed/events/EventsCalendar.test.tsx +33 -18
- package/src/components/post/pieces/ShareMenu.test.tsx +217 -0
- package/src/components/post/pieces/ShareMenu.tsx +107 -61
- package/src/components/post/post-form/VisibilitySheet.test.tsx +153 -0
- package/src/components/post/post-form/VisibilitySheet.tsx +6 -5
- package/src/components/post/types/Event.tsx +6 -2
- package/src/components/profile/Avatar.test.tsx +147 -0
- package/src/components/profile/Avatar.tsx +30 -1
- package/src/components/profile/ProfileCard.test.tsx +165 -8
- package/src/components/profile/ProfileCard.tsx +63 -10
- package/src/components/profile/ProfileSelector.test.tsx +147 -5
- package/src/components/profile/ProfileSelector.tsx +64 -18
- package/src/components/profile/ProfileWithActionCard.tsx +14 -6
- package/src/lib/post.ts +0 -128
- package/src/pages/conversations/New.test.tsx +340 -0
- package/src/pages/conversations/New.tsx +35 -30
- package/src/pages/events/Index.tsx +4 -1
- package/src/pages/events/My.tsx +1 -1
- package/src/pages/groups/Show.tsx +1 -1
- package/src/pages/posts/New.carryover.test.tsx +245 -0
- package/src/pages/posts/New.tsx +18 -2
- package/src/pages/posts/Reply.tsx +17 -2
- package/src/stores/useLocalPostStore.ts +7 -4
- package/src/theme/useThemeOpacity.test.ts +70 -0
|
@@ -1,20 +1,33 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Regression tests for the ProfileSelector sheet title
|
|
2
|
+
* Regression tests for the ProfileSelector sheet title, picker-row tint,
|
|
3
|
+
* selection a11y and id-based selection (issue #1666).
|
|
3
4
|
*
|
|
4
5
|
* The sheet used to hard-code the English string "Add members", so every
|
|
5
6
|
* caller that omitted `title` (jam moderators, group members, event
|
|
6
7
|
* moderators) rendered untranslated copy, and the audience picker could be
|
|
7
8
|
* re-titled to a non-matching string. Web defaults to
|
|
8
9
|
* `profile.selector.title` ("Select profiles"); RN must match.
|
|
10
|
+
*
|
|
11
|
+
* The picker rows also carried no visual selection state, so testers could
|
|
12
|
+
* not see which profiles were picked. NativeWind v4 cannot apply the `/N`
|
|
13
|
+
* opacity modifier to a CSS-variable color, so the tint is built inline via
|
|
14
|
+
* `useThemeOpacity` (`rgba` style) — asserted here as the resolved style
|
|
15
|
+
* value. The tint must use a token that actually contrasts on the sheet:
|
|
16
|
+
* `secondary` is a near-white neutral in the RN palette (web's is the brand
|
|
17
|
+
* teal), so a `secondary` wash is invisible; the selected row uses `primary`
|
|
18
|
+
* at low opacity. The mocked hook is keyed by token so a regression back to
|
|
19
|
+
* `secondary` fails here.
|
|
9
20
|
*/
|
|
10
21
|
|
|
11
22
|
const React = require('react');
|
|
12
23
|
const ReactTestRenderer = require('react-test-renderer');
|
|
13
24
|
|
|
14
|
-
const mockT = (key: string) => MESSAGES[key] ?? key;
|
|
15
|
-
|
|
16
25
|
const MESSAGES: Record<string, string> = {
|
|
17
26
|
'profile.selector.title': 'Select profiles',
|
|
27
|
+
// Deliberately NOT the literal ', selected' the old code hard-coded, so
|
|
28
|
+
// this suite fails if the label regresses to a hard-coded English
|
|
29
|
+
// fragment instead of resolving the locale key (issue #1666 review S1).
|
|
30
|
+
'profile.selector.rowSelected': '{{name}} (selected)',
|
|
18
31
|
'profile.search.placeholder': 'Search profiles',
|
|
19
32
|
'profile.search.noResults': 'No results found',
|
|
20
33
|
'common.members.addSuccess': 'Added',
|
|
@@ -23,11 +36,19 @@ const MESSAGES: Record<string, string> = {
|
|
|
23
36
|
'common.actions.add': 'Add',
|
|
24
37
|
};
|
|
25
38
|
|
|
39
|
+
// Mirrors i18next's default interpolation so the row-label regression test
|
|
40
|
+
// can assert the composed, localized screen-reader string (issue #1666
|
|
41
|
+
// review S1).
|
|
42
|
+
const mockT = (key: string, opts?: { name?: string }) =>
|
|
43
|
+
(MESSAGES[key] ?? key).replace('{{name}}', opts?.name ?? '');
|
|
44
|
+
|
|
26
45
|
jest.mock('react-native', () => ({
|
|
27
46
|
View: (props: { children?: unknown }) =>
|
|
28
47
|
React.createElement('View', null, props.children),
|
|
29
48
|
ScrollView: (props: { children?: unknown }) =>
|
|
30
49
|
React.createElement('ScrollView', null, props.children),
|
|
50
|
+
Pressable: (props: Record<string, unknown>) =>
|
|
51
|
+
React.createElement('Pressable', props, props.children),
|
|
31
52
|
ActivityIndicator: () => null,
|
|
32
53
|
}));
|
|
33
54
|
|
|
@@ -48,6 +69,12 @@ jest.mock('@openpeepshq/react', () => ({
|
|
|
48
69
|
|
|
49
70
|
const PROFILES: unknown[] = [];
|
|
50
71
|
|
|
72
|
+
// Two profile objects; PROFILES[0] is passed as the sheet's initial selection
|
|
73
|
+
// so the tint test can compare a selected row against an unselected one.
|
|
74
|
+
const ada = { id: 'p1', handle: 'ada', displayName: 'Ada' };
|
|
75
|
+
const alan = { id: 'p2', handle: 'alan', displayName: 'Alan' };
|
|
76
|
+
PROFILES.push(ada, alan);
|
|
77
|
+
|
|
51
78
|
jest.mock('../../lib/utils', () => ({
|
|
52
79
|
profileMatchesQuery: () => true,
|
|
53
80
|
}));
|
|
@@ -74,13 +101,29 @@ jest.mock('../custom/modals/common', () => ({
|
|
|
74
101
|
|
|
75
102
|
jest.mock('react-native-toast-message', () => ({ show: jest.fn() }));
|
|
76
103
|
|
|
104
|
+
jest.mock('../../theme/useThemeOpacity', () => ({
|
|
105
|
+
// Mirrors the real hook's shape. Values come from theme/defaults.ts so the
|
|
106
|
+
// tint style is asserted deterministically; keyed by token so a regression
|
|
107
|
+
// back to the invisible `secondary` wash fails (issue #1666 review S1).
|
|
108
|
+
useThemeOpacity: () => ({
|
|
109
|
+
background: (name: string, opacity: number) => ({
|
|
110
|
+
backgroundColor:
|
|
111
|
+
name === 'primary'
|
|
112
|
+
? `rgba(22, 22, 26, ${opacity})`
|
|
113
|
+
: `rgba(244, 244, 245, ${opacity})`,
|
|
114
|
+
}),
|
|
115
|
+
}),
|
|
116
|
+
}));
|
|
117
|
+
|
|
77
118
|
jest.mock('../../lib/bottom-sheet-ref', () => ({
|
|
78
119
|
bottomSheetClose: jest.fn(),
|
|
79
120
|
}));
|
|
80
121
|
|
|
81
122
|
jest.mock('./ProfileCard', () => ({
|
|
82
|
-
MiniProfileCard: () =>
|
|
83
|
-
|
|
123
|
+
MiniProfileCard: (props: Record<string, unknown>) =>
|
|
124
|
+
React.createElement('MiniProfileCard', props),
|
|
125
|
+
ProfileCard: (props: Record<string, unknown>) =>
|
|
126
|
+
React.createElement('ProfileCard', props),
|
|
84
127
|
}));
|
|
85
128
|
|
|
86
129
|
import type { ProfilePickerSheetProps } from './ProfileSelector';
|
|
@@ -113,3 +156,102 @@ describe('ProfileSelector sheet title (issue #1666)', () => {
|
|
|
113
156
|
expect(titleText(tree)).toBe('Add members to Test Group');
|
|
114
157
|
});
|
|
115
158
|
});
|
|
159
|
+
|
|
160
|
+
describe('ProfileSelector selected-row tint (issue #1666)', () => {
|
|
161
|
+
it('tints the selected row with primary at low opacity and leaves the unselected ones clear', () => {
|
|
162
|
+
const tree = renderSelector({
|
|
163
|
+
initialProfiles: [PROFILES[0]] as never,
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
const rows = tree.root.findAllByType('Pressable');
|
|
167
|
+
expect(rows.length).toBeGreaterThanOrEqual(2);
|
|
168
|
+
const selected = rows.find(
|
|
169
|
+
(node: { props: { accessibilityState?: { selected?: boolean } } }) =>
|
|
170
|
+
node.props.accessibilityState?.selected === true
|
|
171
|
+
);
|
|
172
|
+
expect(selected).toBeDefined();
|
|
173
|
+
expect(selected.props.style).toEqual({
|
|
174
|
+
backgroundColor: 'rgba(22, 22, 26, 0.15)',
|
|
175
|
+
});
|
|
176
|
+
const unselected = rows.find(
|
|
177
|
+
(node: { props: { accessibilityState?: { selected?: boolean } } }) =>
|
|
178
|
+
node.props.accessibilityState?.selected === false
|
|
179
|
+
);
|
|
180
|
+
expect(unselected).toBeDefined();
|
|
181
|
+
expect(unselected.props.style).toBeUndefined();
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
it('marks the rows as accessible buttons with a selected state (web parity)', () => {
|
|
185
|
+
const tree = renderSelector({
|
|
186
|
+
initialProfiles: [PROFILES[0]] as never,
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
// Only the selectable rows carry `accessibilityState`; the selected-chip
|
|
190
|
+
// remove buttons (also Pressable) do not, so scope to the rows.
|
|
191
|
+
const rows = tree.root
|
|
192
|
+
.findAllByType('Pressable')
|
|
193
|
+
.filter(
|
|
194
|
+
(node: { props: { accessibilityState?: unknown } }) =>
|
|
195
|
+
node.props.accessibilityState !== undefined
|
|
196
|
+
);
|
|
197
|
+
const selected = rows.filter(
|
|
198
|
+
(node: { props: { accessibilityState?: { selected?: boolean } } }) =>
|
|
199
|
+
node.props.accessibilityState?.selected === true
|
|
200
|
+
);
|
|
201
|
+
const unselected = rows.filter(
|
|
202
|
+
(node: { props: { accessibilityState?: { selected?: boolean } } }) =>
|
|
203
|
+
node.props.accessibilityState?.selected === false
|
|
204
|
+
);
|
|
205
|
+
expect(selected.length).toBe(1);
|
|
206
|
+
expect(unselected.length).toBeGreaterThan(0);
|
|
207
|
+
for (const row of rows) {
|
|
208
|
+
expect(row.props.accessibilityRole).toBe('button');
|
|
209
|
+
expect(typeof row.props.accessibilityLabel).toBe('string');
|
|
210
|
+
expect(row.props.accessibilityLabel.length).toBeGreaterThan(0);
|
|
211
|
+
}
|
|
212
|
+
expect(selected[0].props.accessibilityLabel).toContain('selected');
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
it('builds the selected-row label from the profile.selector.rowSelected locale key (issue #1666 review S1)', () => {
|
|
216
|
+
// The label must come from a t() key, not a hard-coded English fragment:
|
|
217
|
+
// the mock t() resolves the key and interpolates {{name}}, so a
|
|
218
|
+
// regression to a literal ", selected" concatenation would skip the key
|
|
219
|
+
// entirely and leave the label with no interpolation.
|
|
220
|
+
const tree = renderSelector({
|
|
221
|
+
initialProfiles: [PROFILES[0]] as never,
|
|
222
|
+
});
|
|
223
|
+
const rows = tree.root
|
|
224
|
+
.findAllByType('Pressable')
|
|
225
|
+
.filter(
|
|
226
|
+
(node: { props: { accessibilityState?: unknown } }) =>
|
|
227
|
+
node.props.accessibilityState !== undefined
|
|
228
|
+
);
|
|
229
|
+
const selected = rows.find(
|
|
230
|
+
(node: { props: { accessibilityState?: { selected?: boolean } } }) =>
|
|
231
|
+
node.props.accessibilityState?.selected === true
|
|
232
|
+
);
|
|
233
|
+
const unselected = rows.find(
|
|
234
|
+
(node: { props: { accessibilityState?: { selected?: boolean } } }) =>
|
|
235
|
+
node.props.accessibilityState?.selected === false
|
|
236
|
+
);
|
|
237
|
+
expect(selected.props.accessibilityLabel).toBe('Ada (selected)');
|
|
238
|
+
expect(unselected.props.accessibilityLabel).toBe('Alan');
|
|
239
|
+
});
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
describe('ProfileSelector id-based selection (issue #1666 review S3)', () => {
|
|
243
|
+
it('keeps the selection when the caller re-seeds with a fresh object of the same id', () => {
|
|
244
|
+
// A re-mounted sheet (or upstream object churn) seeds `initialProfiles`
|
|
245
|
+
// with a new object; reference equality would drop the selection, so the
|
|
246
|
+
// row must still render selected for the matching id.
|
|
247
|
+
const freshAda = { id: 'p1', handle: 'ada', displayName: 'Ada' };
|
|
248
|
+
const tree = renderSelector({ initialProfiles: [freshAda] as never });
|
|
249
|
+
|
|
250
|
+
const rows = tree.root.findAllByType('Pressable');
|
|
251
|
+
const selected = rows.filter(
|
|
252
|
+
(node: { props: { accessibilityState?: { selected?: boolean } } }) =>
|
|
253
|
+
node.props.accessibilityState?.selected === true
|
|
254
|
+
);
|
|
255
|
+
expect(selected.length).toBe(1);
|
|
256
|
+
});
|
|
257
|
+
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React, { forwardRef, useEffect, useState } from 'react';
|
|
2
|
-
import { View, ScrollView, ActivityIndicator } from 'react-native';
|
|
2
|
+
import { View, ScrollView, ActivityIndicator, Pressable } from 'react-native';
|
|
3
3
|
import { BottomSheetModal } from '@gorhom/bottom-sheet';
|
|
4
4
|
import { ThemedText } from '../ui/themed-text';
|
|
5
5
|
import { PublicProfile } from '@openpeepshq/common';
|
|
@@ -11,6 +11,7 @@ import { BaseSheet, SheetFooter } from '../custom/modals/common';
|
|
|
11
11
|
import Toast from 'react-native-toast-message';
|
|
12
12
|
import { MiniProfileCard, ProfileCard } from './ProfileCard';
|
|
13
13
|
import { useTranslation } from 'react-i18next';
|
|
14
|
+
import { useThemeOpacity } from '../../theme/useThemeOpacity';
|
|
14
15
|
import { bottomSheetClose } from '../../lib/bottom-sheet-ref';
|
|
15
16
|
|
|
16
17
|
interface ProfilePickerSheetProps {
|
|
@@ -87,10 +88,23 @@ export const ProfileSelector = forwardRef<
|
|
|
87
88
|
}
|
|
88
89
|
}, [searchQuery, profiles, currentProfile, profilesToExclude]);
|
|
89
90
|
|
|
91
|
+
// NativeWind v4 can't apply `/N` opacity to CSS-variable colors, so the
|
|
92
|
+
// selected-row tint is built inline from the theme color (issue #1666).
|
|
93
|
+
// `secondary` is a near-white neutral in the RN palette (unlike web's
|
|
94
|
+
// teal), so a `secondary` wash is invisible on a white sheet; the tint
|
|
95
|
+
// uses `primary` at low opacity, matching web's brand-accent selection.
|
|
96
|
+
const { background: tintBackground } = useThemeOpacity();
|
|
97
|
+
|
|
98
|
+
// Compare by id, not object reference: callers re-seed `initialProfiles`
|
|
99
|
+
// with fresh objects on every present, so reference equality would drop
|
|
100
|
+
// the selection (issue #1666 review).
|
|
101
|
+
const isSelected = (profile: PublicProfile) =>
|
|
102
|
+
selectedProfiles.some((p) => p.id === profile.id);
|
|
103
|
+
|
|
90
104
|
const handleSelectProfile = (profile: PublicProfile) => {
|
|
91
105
|
setSelectedProfiles((prev) =>
|
|
92
|
-
prev.
|
|
93
|
-
? prev.filter((p) => p !== profile)
|
|
106
|
+
prev.some((p) => p.id === profile.id)
|
|
107
|
+
? prev.filter((p) => p.id !== profile.id)
|
|
94
108
|
: [...prev, profile]
|
|
95
109
|
);
|
|
96
110
|
if (single) {
|
|
@@ -164,21 +178,53 @@ export const ProfileSelector = forwardRef<
|
|
|
164
178
|
</View>
|
|
165
179
|
)}
|
|
166
180
|
|
|
167
|
-
{filteredProfiles?.map((profile) =>
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
181
|
+
{filteredProfiles?.map((profile) => {
|
|
182
|
+
const selected = isSelected(profile);
|
|
183
|
+
// Screen-reader copy is user-facing copy: compose the label
|
|
184
|
+
// from a locale key instead of a hard-coded English fragment
|
|
185
|
+
// (issue #1666 review S1).
|
|
186
|
+
const rowLabel = selected
|
|
187
|
+
? t('profile.selector.rowSelected', {
|
|
188
|
+
name: profile.displayName || `@${profile.handle}`,
|
|
189
|
+
})
|
|
190
|
+
: profile.displayName || `@${profile.handle}`;
|
|
191
|
+
// Two overlapping press surfaces, on purpose: the full row is a
|
|
192
|
+
// `Pressable` (the a11y element), but the left avatar+name column
|
|
193
|
+
// is also `ProfileCard`'s inner `TouchableWithoutFeedback`. RN
|
|
194
|
+
// hands a tap to the first responder that claims it, so a tap on
|
|
195
|
+
// the left column hits the inner touchable and a tap on the right
|
|
196
|
+
// (check-icon) region hits this Pressable — both call
|
|
197
|
+
// `handleSelectProfile`, so exactly one toggle per tap. Do not
|
|
198
|
+
// "simplify" away the inner touchable: it is the only tap target
|
|
199
|
+
// over the card itself, and dropping it would strand the right
|
|
200
|
+
// half of the row (issue #1666 review S3).
|
|
201
|
+
return (
|
|
202
|
+
<Pressable
|
|
203
|
+
key={profile.id}
|
|
204
|
+
className="rounded-md"
|
|
205
|
+
style={
|
|
206
|
+
selected ? tintBackground('primary', 0.15) : undefined
|
|
207
|
+
}
|
|
208
|
+
accessibilityRole="button"
|
|
209
|
+
accessibilityLabel={rowLabel}
|
|
210
|
+
accessibilityState={{ selected }}
|
|
211
|
+
onPress={() => handleSelectProfile(profile)}
|
|
212
|
+
>
|
|
213
|
+
<ProfileCard
|
|
214
|
+
profile={profile}
|
|
215
|
+
actionType="select"
|
|
216
|
+
handleSelectProfile={() => handleSelectProfile(profile)}
|
|
217
|
+
rightComponent={
|
|
218
|
+
selected ? (
|
|
219
|
+
<View className="items-center justify-center pr-1">
|
|
220
|
+
<CheckIcon size={16} className="text-primary" />
|
|
221
|
+
</View>
|
|
222
|
+
) : null
|
|
223
|
+
}
|
|
224
|
+
/>
|
|
225
|
+
</Pressable>
|
|
226
|
+
);
|
|
227
|
+
})}
|
|
182
228
|
|
|
183
229
|
{filteredProfiles?.length === 0 && (
|
|
184
230
|
<ThemedText className="text-center text-muted-foreground">
|
|
@@ -16,20 +16,28 @@ export const ProfileWithActionCard = ({
|
|
|
16
16
|
leading,
|
|
17
17
|
}: ProfileWithActionCardProps) => (
|
|
18
18
|
<View className="mb-4 w-full flex-row items-center justify-between">
|
|
19
|
-
<View className="flex-row items-center gap-2">
|
|
19
|
+
<View className="flex min-w-0 flex-1 flex-row items-center gap-2">
|
|
20
20
|
{leading}
|
|
21
|
-
<ProfileLink
|
|
21
|
+
<ProfileLink
|
|
22
|
+
profile={profile}
|
|
23
|
+
className="flex min-w-0 flex-1 flex-row items-center gap-2"
|
|
24
|
+
>
|
|
22
25
|
<ProfileAvatar profile={profile} />
|
|
23
|
-
<View>
|
|
24
|
-
<ThemedText className="font-bold">
|
|
26
|
+
<View className="min-w-0 flex-1">
|
|
27
|
+
<ThemedText className="font-bold" numberOfLines={1}>
|
|
25
28
|
{profile.displayName || profile.handle}
|
|
26
29
|
</ThemedText>
|
|
27
|
-
<ThemedText
|
|
30
|
+
<ThemedText
|
|
31
|
+
className="text-sm text-muted-foreground"
|
|
32
|
+
numberOfLines={1}
|
|
33
|
+
>
|
|
28
34
|
@{profile.handle}
|
|
29
35
|
</ThemedText>
|
|
30
36
|
</View>
|
|
31
37
|
</ProfileLink>
|
|
32
38
|
</View>
|
|
33
|
-
<
|
|
39
|
+
<View className="shrink-0">
|
|
40
|
+
<FollowUnfollowButton profile={profile} compact />
|
|
41
|
+
</View>
|
|
34
42
|
</View>
|
|
35
43
|
);
|
package/src/lib/post.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { PollChoiceForm } from '../types';
|
|
2
|
-
import Toast from 'react-native-toast-message';
|
|
3
1
|
import {
|
|
4
2
|
dateSorter,
|
|
5
3
|
MediaAttachmentData,
|
|
@@ -7,7 +5,6 @@ import {
|
|
|
7
5
|
PublicPost,
|
|
8
6
|
Thread,
|
|
9
7
|
} from '@openpeepshq/common';
|
|
10
|
-
import { uploadMedia } from './uploadMedia';
|
|
11
8
|
|
|
12
9
|
/** True if the attachment is still being processed server-side. */
|
|
13
10
|
export const isAttachmentProcessing = (
|
|
@@ -19,131 +16,6 @@ export const hasProcessingAttachments = (
|
|
|
19
16
|
postData: PostCreationData | undefined
|
|
20
17
|
): boolean => (postData?.data?.attachments ?? []).some(isAttachmentProcessing);
|
|
21
18
|
|
|
22
|
-
export const handleMediaUpload = async (
|
|
23
|
-
selectedMedia: { uri: string; type: 'video' | 'image'; alt?: string }[],
|
|
24
|
-
createAttachments: any,
|
|
25
|
-
serverConfig: string
|
|
26
|
-
) => {
|
|
27
|
-
const attachments = await Promise.all(
|
|
28
|
-
selectedMedia.map((media) =>
|
|
29
|
-
uploadMedia({
|
|
30
|
-
mediaUri: media.uri,
|
|
31
|
-
createAttachments: createAttachments,
|
|
32
|
-
type: media.type,
|
|
33
|
-
usage: `${serverConfig}:${media.type}`,
|
|
34
|
-
alt: media?.alt,
|
|
35
|
-
})
|
|
36
|
-
)
|
|
37
|
-
);
|
|
38
|
-
|
|
39
|
-
return attachments.filter(
|
|
40
|
-
(attachment): attachment is NonNullable<typeof attachment> =>
|
|
41
|
-
attachment !== null
|
|
42
|
-
);
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
export const validatePollData = (formData: PollChoiceForm): boolean => {
|
|
46
|
-
if (formData.choices.some((choice) => !choice.text.trim())) {
|
|
47
|
-
Toast.show({
|
|
48
|
-
type: 'error',
|
|
49
|
-
text1: 'Please fill in all poll choices',
|
|
50
|
-
});
|
|
51
|
-
return false;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
if (!formData.pollLength.trim()) {
|
|
55
|
-
Toast.show({
|
|
56
|
-
type: 'error',
|
|
57
|
-
text1: 'Please set a poll length',
|
|
58
|
-
});
|
|
59
|
-
return false;
|
|
60
|
-
}
|
|
61
|
-
return true;
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
export const noteToQuestion = (
|
|
65
|
-
postData: PostCreationData
|
|
66
|
-
): PostCreationData => ({
|
|
67
|
-
...postData,
|
|
68
|
-
type: 'question',
|
|
69
|
-
data: {
|
|
70
|
-
...postData.data,
|
|
71
|
-
type: 'question',
|
|
72
|
-
options: [
|
|
73
|
-
{
|
|
74
|
-
type: 'note',
|
|
75
|
-
content: '',
|
|
76
|
-
},
|
|
77
|
-
{
|
|
78
|
-
type: 'note',
|
|
79
|
-
content: '',
|
|
80
|
-
},
|
|
81
|
-
],
|
|
82
|
-
expiresAt: new Date(Date.now() + 1000 * 60 * 60 * 24 * 30).toISOString(),
|
|
83
|
-
},
|
|
84
|
-
});
|
|
85
|
-
export const toQuestion = (postData: PostCreationData): PostCreationData => ({
|
|
86
|
-
...postData,
|
|
87
|
-
type: 'question',
|
|
88
|
-
data: {
|
|
89
|
-
...postData.data,
|
|
90
|
-
type: 'question',
|
|
91
|
-
options: [
|
|
92
|
-
{
|
|
93
|
-
type: 'note',
|
|
94
|
-
content: '',
|
|
95
|
-
},
|
|
96
|
-
{
|
|
97
|
-
type: 'note',
|
|
98
|
-
content: '',
|
|
99
|
-
},
|
|
100
|
-
],
|
|
101
|
-
expiresAt: new Date(Date.now() + 1000 * 60 * 60 * 24 * 30).toISOString(),
|
|
102
|
-
},
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
export const toArticle = (postData: PostCreationData): PostCreationData => ({
|
|
106
|
-
...postData,
|
|
107
|
-
type: 'article',
|
|
108
|
-
data: {
|
|
109
|
-
content: postData.data.content,
|
|
110
|
-
type: 'article',
|
|
111
|
-
attachments: postData.data.attachments,
|
|
112
|
-
},
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
export const toNote = (postData: PostCreationData): PostCreationData => ({
|
|
116
|
-
...postData,
|
|
117
|
-
type: 'note',
|
|
118
|
-
data: {
|
|
119
|
-
content: postData.data.content,
|
|
120
|
-
type: 'note',
|
|
121
|
-
attachments: postData.data.attachments,
|
|
122
|
-
},
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
export const questionToNote = (
|
|
126
|
-
postData: PostCreationData
|
|
127
|
-
): PostCreationData => ({
|
|
128
|
-
...postData,
|
|
129
|
-
type: 'note',
|
|
130
|
-
data: {
|
|
131
|
-
content: postData.data.content,
|
|
132
|
-
type: 'note',
|
|
133
|
-
attachments: postData.data.attachments,
|
|
134
|
-
},
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
// export const handleScroll = (
|
|
138
|
-
// event: any,
|
|
139
|
-
// setCurrentIndex: (index: number) => void,
|
|
140
|
-
// ) => {
|
|
141
|
-
// const slideSize = event.nativeEvent.layoutMeasurement.width;
|
|
142
|
-
// const offset = event.nativeEvent.contentOffset.x;
|
|
143
|
-
// const currentIndex = Math.round(offset / slideSize);
|
|
144
|
-
// setCurrentIndex(currentIndex);
|
|
145
|
-
// };
|
|
146
|
-
|
|
147
19
|
export const lastLongestPathSelector = (
|
|
148
20
|
thread: Thread
|
|
149
21
|
): Thread & { depth: number } => {
|