@openpeepshq/rn-components 0.13.3 → 0.14.1
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/README.md +2 -0
- package/package.json +4 -3
- package/src/components/buttonOverflow.test.tsx +455 -0
- 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/JamDeviceSelectors.tsx +2 -2
- package/src/components/jams/JamFooter.tsx +26 -22
- package/src/components/jams/JamLobby.tsx +5 -3
- package/src/components/jams/JamParticipantConference.tsx +6 -1
- package/src/components/jams/JamPeopleDrawer.tsx +19 -3
- package/src/components/jams/JamRequestJoin.tsx +30 -3
- package/src/components/jams/JamRoomIndicators.test.tsx +80 -4
- package/src/components/jams/JamRoomIndicators.tsx +34 -1
- package/src/components/jams/JamVideoCall.tsx +5 -5
- package/src/components/jams/LeaveCloseButton.tsx +5 -1
- package/src/components/post/pieces/FeedPostStats.tsx +15 -11
- package/src/components/post/pieces/PollContent.tsx +1 -1
- package/src/components/post/pieces/PostMenu.test.tsx +333 -0
- package/src/components/post/pieces/PostMenu.tsx +19 -15
- package/src/components/post/post-form/ReplyModal.tsx +1 -1
- package/src/components/post/types/Event.tsx +6 -2
- package/src/components/profile/Avatar.tsx +4 -1
- package/src/components/profile/ProfileWithActionCard.tsx +14 -6
- package/src/components/resources/ResourceLibrary.tsx +0 -1
- package/src/hooks/use-controlled-sheet.test.tsx +140 -0
- package/src/hooks/use-controlled-sheet.ts +25 -2
- package/src/lib/post.ts +0 -128
- package/src/pages/Explore.tsx +1 -3
- package/src/pages/conversations/Info.tsx +1 -1
- package/src/pages/conversations/New.tsx +1 -1
- package/src/pages/posts/Edit.tsx +1 -1
- package/src/pages/posts/New.carryover.test.tsx +245 -0
- package/src/pages/posts/New.tsx +19 -3
- package/src/pages/posts/Reply.tsx +19 -4
- package/src/stores/useLocalPostStore.ts +7 -4
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 } => {
|
package/src/pages/Explore.tsx
CHANGED
|
@@ -64,9 +64,7 @@ export const Explore: React.FC<ExploreScreenProps> = ({ navigation }) => {
|
|
|
64
64
|
<View className="max-w-[200px] flex-row items-center">
|
|
65
65
|
<Input
|
|
66
66
|
className="flex-1"
|
|
67
|
-
placeholder={t('explore.searchPlaceholder'
|
|
68
|
-
defaultValue: 'Search',
|
|
69
|
-
})}
|
|
67
|
+
placeholder={t('explore.searchPlaceholder')}
|
|
70
68
|
value={searchQuery}
|
|
71
69
|
onChangeText={setSearchQuery}
|
|
72
70
|
/>
|
|
@@ -35,7 +35,7 @@ export const ConversationInfo = ({ route }: ConversationInfoProps) => {
|
|
|
35
35
|
const navigation =
|
|
36
36
|
useNavigation<NativeStackNavigationProp<MainStackParamList>>();
|
|
37
37
|
|
|
38
|
-
useSetPageHeader(t('conversations.info'));
|
|
38
|
+
useSetPageHeader(t('conversations.info.title'));
|
|
39
39
|
|
|
40
40
|
return (
|
|
41
41
|
<ThemedView className="flex-1">
|
|
@@ -46,7 +46,7 @@ export const NewConversation = ({
|
|
|
46
46
|
}, [currentProfile, allProfiles, searchQuery]);
|
|
47
47
|
|
|
48
48
|
useSetPageHeader(
|
|
49
|
-
t('conversations.selectMembers'
|
|
49
|
+
t('conversations.selectMembers'),
|
|
50
50
|
<HeaderActionButton
|
|
51
51
|
title={t('common.next', { defaultValue: 'Next' })}
|
|
52
52
|
onPress={() => navigation.navigate('DraftMessage')}
|
package/src/pages/posts/Edit.tsx
CHANGED
|
@@ -127,7 +127,7 @@ export const EditPost = ({ route, navigation }: PostProps) => {
|
|
|
127
127
|
isPosting
|
|
128
128
|
? t('posts.edit.loading')
|
|
129
129
|
: attachmentsProcessing
|
|
130
|
-
? t('
|
|
130
|
+
? t('form.upload.processing')
|
|
131
131
|
: t('posts.edit.submit')
|
|
132
132
|
}
|
|
133
133
|
onPress={() => void handlePostUpdate()}
|
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Regression coverage for #1799 (native composer) — the poll <-> note type
|
|
3
|
+
* switch must carry the typed text over *and* persist the converted draft to
|
|
4
|
+
* the app-lifetime local post store, so the carry-over (including the
|
|
5
|
+
* `questionDraft` stash that lets a later note -> poll restore the original
|
|
6
|
+
* poll) survives a screen unmount/remount.
|
|
7
|
+
*
|
|
8
|
+
* The native `NewPost` is a large composite, so every external import is
|
|
9
|
+
* mocked (node jest env, no native modules) — mirroring FullEvent.test.tsx.
|
|
10
|
+
* Only `handleSelectComposerType` is exercised; the surrounding form / footer
|
|
11
|
+
* / picker UI render inert mocks. The shared `toNote`/`toQuestion`/
|
|
12
|
+
* `isSwitchablePostData` helpers are loaded from `@openpeepshq/react`'s
|
|
13
|
+
* real source so the conversion logic under test is the production one.
|
|
14
|
+
*/
|
|
15
|
+
import { type ReactNode } from 'react';
|
|
16
|
+
import ReactTestRenderer from 'react-test-renderer';
|
|
17
|
+
|
|
18
|
+
const React = require('react');
|
|
19
|
+
|
|
20
|
+
// Shared helper (the production conversion logic) resolved from the real
|
|
21
|
+
// react package source. The jest moduleNameMapper only pins the package
|
|
22
|
+
// *root* import to contentLength; this explicit subpath keeps real toNote /
|
|
23
|
+
// toQuestion / isSwitchablePostData in the test.
|
|
24
|
+
const mockSharedPost = require('../../../../react/src/lib/post');
|
|
25
|
+
|
|
26
|
+
// --- react-native: host elements render as plain host tags ----------------
|
|
27
|
+
jest.mock('react-native', () => {
|
|
28
|
+
const make = (tag: string) => (props: { children?: ReactNode }) =>
|
|
29
|
+
React.createElement(tag, null, props.children);
|
|
30
|
+
return { View: make('View'), Text: make('Text') };
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
// --- i18n: resolve keys to their defaultValue -----------------------------
|
|
34
|
+
jest.mock('react-i18next', () => ({
|
|
35
|
+
useTranslation: () => ({
|
|
36
|
+
t: (_key: string, opts?: { defaultValue?: string; number?: number }) =>
|
|
37
|
+
opts?.defaultValue ?? _key,
|
|
38
|
+
}),
|
|
39
|
+
}));
|
|
40
|
+
|
|
41
|
+
// --- shared @openpeepshq/react: real conversion helpers, inert context ----
|
|
42
|
+
jest.mock('@openpeepshq/react', () => ({
|
|
43
|
+
isSwitchablePostData: mockSharedPost.isSwitchablePostData,
|
|
44
|
+
toNote: mockSharedPost.toNote,
|
|
45
|
+
toQuestion: mockSharedPost.toQuestion,
|
|
46
|
+
useOpenpeeps: () => ({
|
|
47
|
+
currentProfile: { id: 'me', roles: [] },
|
|
48
|
+
openpeepsApi: {
|
|
49
|
+
createPostAction: () => jest.fn(),
|
|
50
|
+
admin: { announcePostAction: () => jest.fn() },
|
|
51
|
+
joinGroupAction: () => jest.fn(),
|
|
52
|
+
useServerInfo: () => ({ data: { publicContent: true } }),
|
|
53
|
+
},
|
|
54
|
+
}),
|
|
55
|
+
}));
|
|
56
|
+
|
|
57
|
+
// --- common: the jest config pins the root import to contentLength.ts, which
|
|
58
|
+
// lacks these runtime helpers, so the page's named imports resolve here. --
|
|
59
|
+
jest.mock('@openpeepshq/common', () => ({
|
|
60
|
+
POLL_DEFAULT_EXPIRY_MS: 30 * 24 * 60 * 60 * 1000,
|
|
61
|
+
canAnnouncePosts: () => false,
|
|
62
|
+
isCommunityWideVisibility: () => true,
|
|
63
|
+
pollOptionsWithinLimit: () => true,
|
|
64
|
+
canSubmitPostContent: () => true,
|
|
65
|
+
resolvePollOptionContents: (opts: string[]) => opts,
|
|
66
|
+
visibleTextLength: (c?: string) => (c ?? '').length,
|
|
67
|
+
}));
|
|
68
|
+
|
|
69
|
+
// --- navigation: types are type-only, but the stack barrel is stubbed ------
|
|
70
|
+
jest.mock('@react-navigation/native', () => ({}));
|
|
71
|
+
jest.mock('@react-navigation/native-stack', () => ({}));
|
|
72
|
+
|
|
73
|
+
// --- local react-native deps ----------------------------------------------
|
|
74
|
+
jest.mock('react-native-toast-message', () => {
|
|
75
|
+
const Toast = { show: jest.fn() };
|
|
76
|
+
return { __esModule: true, default: Toast };
|
|
77
|
+
});
|
|
78
|
+
jest.mock('@gorhom/bottom-sheet', () => ({
|
|
79
|
+
BottomSheetModal: () => null,
|
|
80
|
+
}));
|
|
81
|
+
jest.mock('react-native-keyboard-aware-scroll-view', () => ({
|
|
82
|
+
KeyboardAwareScrollView: ({ children }: { children?: ReactNode }) =>
|
|
83
|
+
React.createElement('View', null, children),
|
|
84
|
+
}));
|
|
85
|
+
|
|
86
|
+
// --- react-hook-form: inert form, capturing reset() calls -----------------
|
|
87
|
+
let formResetCalls: unknown[][] = [];
|
|
88
|
+
jest.mock('react-hook-form', () => ({
|
|
89
|
+
useForm: () => ({
|
|
90
|
+
reset: (v?: unknown) => {
|
|
91
|
+
formResetCalls.push([v]);
|
|
92
|
+
},
|
|
93
|
+
}),
|
|
94
|
+
}));
|
|
95
|
+
|
|
96
|
+
// --- media permissions: always allowed (picker paths are inert) -----------
|
|
97
|
+
jest.mock('../../lib/media-permissions', () => ({
|
|
98
|
+
checkMediaPermissions: () => Promise.resolve(true),
|
|
99
|
+
}));
|
|
100
|
+
|
|
101
|
+
// --- layout + themed view: render inert ------------------------------------
|
|
102
|
+
jest.mock('../../components/layout', () => ({
|
|
103
|
+
HeaderActionButton: () => null,
|
|
104
|
+
useSetPageHeader: jest.fn(),
|
|
105
|
+
}));
|
|
106
|
+
jest.mock('../../components/ui/themed-view', () => ({
|
|
107
|
+
ThemedView: ({ children }: { children?: ReactNode }) =>
|
|
108
|
+
React.createElement('View', null, children),
|
|
109
|
+
}));
|
|
110
|
+
|
|
111
|
+
// --- picker sheets + article form: render inert ----------------------------
|
|
112
|
+
jest.mock('../../components/custom/index', () => ({
|
|
113
|
+
ImagePickerSheet: () => null,
|
|
114
|
+
AudioPickerSheet: () => null,
|
|
115
|
+
DocumentPickerSheet: () => null,
|
|
116
|
+
}));
|
|
117
|
+
jest.mock('../../components/post/index', () => ({
|
|
118
|
+
ArticleForm: () => null,
|
|
119
|
+
}));
|
|
120
|
+
|
|
121
|
+
// --- composer children: PostForm inert, PostTypeSwitcher forwards onSelect -
|
|
122
|
+
let switcherOnSelect: ((type: 'note' | 'question') => void) | undefined;
|
|
123
|
+
jest.mock('../../components/post/post-form/PostForm', () => ({
|
|
124
|
+
PostForm: () => null,
|
|
125
|
+
}));
|
|
126
|
+
jest.mock('../../components/post/post-form/PostTypeSwitcher', () => ({
|
|
127
|
+
PostTypeSwitcher: (props: {
|
|
128
|
+
type: string;
|
|
129
|
+
onSelect: (type: 'note' | 'question') => void;
|
|
130
|
+
}) => {
|
|
131
|
+
switcherOnSelect = props.onSelect;
|
|
132
|
+
return React.createElement('View', null);
|
|
133
|
+
},
|
|
134
|
+
}));
|
|
135
|
+
jest.mock('../../components/post/post-form/Footer', () => ({
|
|
136
|
+
// Renders the `typeSwitcher` slot so PostTypeSwitcher mounts and captures its
|
|
137
|
+
// onSelect (New.tsx passes the switcher as a prop, not a child).
|
|
138
|
+
Footer: (props: { typeSwitcher?: ReactNode }) =>
|
|
139
|
+
React.createElement('View', null, props.typeSwitcher),
|
|
140
|
+
}));
|
|
141
|
+
|
|
142
|
+
import { useLocalPostStore } from '../../stores/useLocalPostStore';
|
|
143
|
+
import { NewPost } from './New';
|
|
144
|
+
|
|
145
|
+
const NOTE_DRAFT = {
|
|
146
|
+
type: 'note',
|
|
147
|
+
visibility: 'public' as const,
|
|
148
|
+
data: { type: 'note' as const, content: '[TEST] note text before poll' },
|
|
149
|
+
mentions: [],
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
const QUESTION_DRAFT = {
|
|
153
|
+
type: 'question',
|
|
154
|
+
visibility: 'public' as const,
|
|
155
|
+
data: {
|
|
156
|
+
type: 'question' as const,
|
|
157
|
+
content: '[TEST] poll question',
|
|
158
|
+
options: [
|
|
159
|
+
{ type: 'note' as const, content: 'Option A' },
|
|
160
|
+
{ type: 'note' as const, content: 'Option B' },
|
|
161
|
+
],
|
|
162
|
+
expiresAt: '2026-12-31T18:00:00.000Z',
|
|
163
|
+
},
|
|
164
|
+
mentions: [],
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
function render(): ReactTestRenderer.ReactTestRenderer {
|
|
168
|
+
let tree!: ReactTestRenderer.ReactTestRenderer;
|
|
169
|
+
ReactTestRenderer.act(() => {
|
|
170
|
+
tree = ReactTestRenderer.create(
|
|
171
|
+
<NewPost route={{ params: {} }} navigation={{}} />
|
|
172
|
+
);
|
|
173
|
+
});
|
|
174
|
+
return tree;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
function clickSwitchTo(type: 'note' | 'question'): void {
|
|
178
|
+
expect(switcherOnSelect).toBeDefined();
|
|
179
|
+
ReactTestRenderer.act(() => {
|
|
180
|
+
switcherOnSelect!(type);
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
beforeEach(() => {
|
|
185
|
+
(
|
|
186
|
+
globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }
|
|
187
|
+
).IS_REACT_ACT_ENVIRONMENT = true;
|
|
188
|
+
useLocalPostStore.getState().resetPostData();
|
|
189
|
+
useLocalPostStore.setState({
|
|
190
|
+
postData: QUESTION_DRAFT,
|
|
191
|
+
replyData: {},
|
|
192
|
+
});
|
|
193
|
+
formResetCalls = [];
|
|
194
|
+
switcherOnSelect = undefined;
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
test('poll -> note persists a note draft carrying the questionDraft stash', () => {
|
|
198
|
+
render();
|
|
199
|
+
clickSwitchTo('note');
|
|
200
|
+
|
|
201
|
+
// The converted draft is written to the app-lifetime local post store — the
|
|
202
|
+
// remount-restore path the screen comments rely on.
|
|
203
|
+
const stored = useLocalPostStore.getState().postData;
|
|
204
|
+
expect(stored.data).toMatchObject({
|
|
205
|
+
type: 'note',
|
|
206
|
+
content: '[TEST] poll question',
|
|
207
|
+
});
|
|
208
|
+
// The stash carries the poll's structural fields so a later note -> poll
|
|
209
|
+
// restores them instead of rebuilding a blank poll.
|
|
210
|
+
expect(stored.questionDraft).toMatchObject({
|
|
211
|
+
options: [
|
|
212
|
+
{ type: 'note', content: 'Option A' },
|
|
213
|
+
{ type: 'note', content: 'Option B' },
|
|
214
|
+
],
|
|
215
|
+
expiresAt: '2026-12-31T18:00:00.000Z',
|
|
216
|
+
});
|
|
217
|
+
// The form is reset to the same converted draft (the handler passes one
|
|
218
|
+
// object to both form.reset and setPostData).
|
|
219
|
+
expect(formResetCalls.length).toBeGreaterThan(0);
|
|
220
|
+
const formNote = formResetCalls
|
|
221
|
+
.map((c) => c[0])
|
|
222
|
+
.find((p) => (p as { data?: { type?: string } })?.data?.type === 'note');
|
|
223
|
+
expect(formNote).toBe(stored);
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
test('note -> poll converts the note into a poll and drops the questionDraft stash', () => {
|
|
227
|
+
useLocalPostStore.setState({
|
|
228
|
+
postData: NOTE_DRAFT,
|
|
229
|
+
replyData: {},
|
|
230
|
+
});
|
|
231
|
+
render();
|
|
232
|
+
clickSwitchTo('question');
|
|
233
|
+
|
|
234
|
+
const stored = useLocalPostStore.getState().postData;
|
|
235
|
+
expect(stored.data).toMatchObject({
|
|
236
|
+
type: 'question',
|
|
237
|
+
content: '[TEST] note text before poll',
|
|
238
|
+
options: [
|
|
239
|
+
{ type: 'note', content: '' },
|
|
240
|
+
{ type: 'note', content: '' },
|
|
241
|
+
],
|
|
242
|
+
});
|
|
243
|
+
// A note -> poll conversion has no stash to carry, so no questionDraft.
|
|
244
|
+
expect(stored.questionDraft).toBeUndefined();
|
|
245
|
+
});
|
package/src/pages/posts/New.tsx
CHANGED
|
@@ -11,7 +11,12 @@ import {
|
|
|
11
11
|
MainStackParamList,
|
|
12
12
|
TabStackParamList,
|
|
13
13
|
} from '../../components/navigation/types/index';
|
|
14
|
-
import {
|
|
14
|
+
import {
|
|
15
|
+
isSwitchablePostData,
|
|
16
|
+
toNote,
|
|
17
|
+
toQuestion,
|
|
18
|
+
useOpenpeeps,
|
|
19
|
+
} from '@openpeepshq/react';
|
|
15
20
|
import {
|
|
16
21
|
AudioPickerSheet,
|
|
17
22
|
ImagePickerSheet,
|
|
@@ -40,7 +45,7 @@ import { KeyboardAwareScrollView } from 'react-native-keyboard-aware-scroll-view
|
|
|
40
45
|
import { Footer } from '../../components/post/post-form/Footer';
|
|
41
46
|
import { PostTypeSwitcher } from '../../components/post/post-form/PostTypeSwitcher';
|
|
42
47
|
import { BottomSheetModal } from '@gorhom/bottom-sheet';
|
|
43
|
-
import { hasProcessingAttachments
|
|
48
|
+
import { hasProcessingAttachments } from '../../lib/post';
|
|
44
49
|
import { useForm } from 'react-hook-form';
|
|
45
50
|
|
|
46
51
|
import { ArticleForm } from '../../components/post/index';
|
|
@@ -234,9 +239,20 @@ export const NewPost = ({ route, navigation }: PostProps) => {
|
|
|
234
239
|
if (postData.data.type === next) {
|
|
235
240
|
return;
|
|
236
241
|
}
|
|
242
|
+
if (!isSwitchablePostData(postData)) {
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
237
245
|
const newPostData =
|
|
238
246
|
next === 'question' ? toQuestion(postData) : toNote(postData);
|
|
239
247
|
form.reset(newPostData);
|
|
248
|
+
// Persisting the converted draft to the (module-scoped, app-lifetime)
|
|
249
|
+
// local post store is what makes the carry-over survive a screen
|
|
250
|
+
// unmount/remount: a fresh `NewPost` mount re-seeds its form from
|
|
251
|
+
// `useLocalPostStore.getState().postData`, so the converted note body /
|
|
252
|
+
// poll question (and, for a poll, its stashed `questionDraft` fields)
|
|
253
|
+
// are restored on return. A full app restart clears the store, so a
|
|
254
|
+
// draft only survives within a running app — matching the web, whose
|
|
255
|
+
// draft stores are in-memory too.
|
|
240
256
|
setPostData(newPostData);
|
|
241
257
|
},
|
|
242
258
|
[postData, form, setPostData]
|
|
@@ -273,7 +289,7 @@ export const NewPost = ({ route, navigation }: PostProps) => {
|
|
|
273
289
|
isPosting
|
|
274
290
|
? t('posts.create.loading')
|
|
275
291
|
: attachmentsProcessing
|
|
276
|
-
? t('
|
|
292
|
+
? t('form.upload.processing')
|
|
277
293
|
: t('posts.create.submit')
|
|
278
294
|
}
|
|
279
295
|
onPress={() => void handlePostCreation()}
|
|
@@ -5,7 +5,13 @@ import React, {
|
|
|
5
5
|
useRef,
|
|
6
6
|
useState,
|
|
7
7
|
} from 'react';
|
|
8
|
-
import {
|
|
8
|
+
import {
|
|
9
|
+
apiErrorMessage,
|
|
10
|
+
isSwitchablePostData,
|
|
11
|
+
toNote,
|
|
12
|
+
toQuestion,
|
|
13
|
+
useOpenpeeps,
|
|
14
|
+
} from '@openpeepshq/react';
|
|
9
15
|
import {
|
|
10
16
|
AudioPickerSheet,
|
|
11
17
|
DocumentPickerSheet,
|
|
@@ -40,7 +46,7 @@ import { KeyboardAwareScrollView } from 'react-native-keyboard-aware-scroll-view
|
|
|
40
46
|
import { Footer } from '../../components/post/post-form/Footer';
|
|
41
47
|
import { PostTypeSwitcher } from '../../components/post/post-form/PostTypeSwitcher';
|
|
42
48
|
import { useForm } from 'react-hook-form';
|
|
43
|
-
import { hasProcessingAttachments
|
|
49
|
+
import { hasProcessingAttachments } from '../../lib/post';
|
|
44
50
|
import { CompactReplyParent } from '../../components/post/CompactReplyParent';
|
|
45
51
|
|
|
46
52
|
import { ReplyModal } from '../../components/post/index';
|
|
@@ -230,9 +236,18 @@ export const ReplyPost = ({ route, navigation }: PostProps) => {
|
|
|
230
236
|
if (!postData || postData.data.type === next) {
|
|
231
237
|
return;
|
|
232
238
|
}
|
|
239
|
+
if (!isSwitchablePostData(postData)) {
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
233
242
|
const newPostData =
|
|
234
243
|
next === 'question' ? toQuestion(postData) : toNote(postData);
|
|
235
244
|
form.reset(newPostData);
|
|
245
|
+
// Persisting the converted draft to the (module-scoped, app-lifetime)
|
|
246
|
+
// `replyData[id]` store slot is what makes the carry-over survive the
|
|
247
|
+
// reply screen unmounting/remounting: a fresh `ReplyPost` mount
|
|
248
|
+
// re-seeds its form from `useLocalPostStore(...).replyData[id]`, so the
|
|
249
|
+
// converted note body / poll question (and, for a poll, its stashed
|
|
250
|
+
// `questionDraft` fields) are restored on return.
|
|
236
251
|
setPostData(newPostData);
|
|
237
252
|
},
|
|
238
253
|
[postData, form, setPostData]
|
|
@@ -246,13 +261,13 @@ export const ReplyPost = ({ route, navigation }: PostProps) => {
|
|
|
246
261
|
}, [t]);
|
|
247
262
|
|
|
248
263
|
useSetPageHeader(
|
|
249
|
-
t('posts.
|
|
264
|
+
t('posts.replyModal.title'),
|
|
250
265
|
<HeaderActionButton
|
|
251
266
|
title={
|
|
252
267
|
isPosting
|
|
253
268
|
? t('posts.create.loading')
|
|
254
269
|
: attachmentsProcessing
|
|
255
|
-
? t('
|
|
270
|
+
? t('form.upload.processing')
|
|
256
271
|
: t('posts.create.submit')
|
|
257
272
|
}
|
|
258
273
|
onPress={() => void handlePostCreation()}
|
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
POLL_DEFAULT_EXPIRY_MS,
|
|
3
|
+
PostCreationData,
|
|
4
|
+
PostType,
|
|
5
|
+
PostDataUnion,
|
|
6
|
+
} from '@openpeepshq/common';
|
|
2
7
|
import { create } from 'zustand';
|
|
3
8
|
|
|
4
9
|
const defaultPostData = (type: PostType): PostDataUnion => {
|
|
@@ -8,9 +13,7 @@ const defaultPostData = (type: PostType): PostDataUnion => {
|
|
|
8
13
|
type: 'question',
|
|
9
14
|
content: '',
|
|
10
15
|
options: [],
|
|
11
|
-
expiresAt: new Date(
|
|
12
|
-
Date.now() + 1000 * 60 * 60 * 24 * 30
|
|
13
|
-
).toISOString(),
|
|
16
|
+
expiresAt: new Date(Date.now() + POLL_DEFAULT_EXPIRY_MS).toISOString(),
|
|
14
17
|
};
|
|
15
18
|
case 'event':
|
|
16
19
|
return {
|