@openpeepshq/rn-components 0.3.6 → 0.3.7
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 +1 -1
- package/src/components/custom/common/empty-state-container.tsx +42 -114
- package/src/components/custom/headers/tab-screens-header.tsx +3 -4
- package/src/components/custom/navigation/side-menu.tsx +2 -2
- package/src/components/navigation/auth-wrapper.tsx +1 -1
- package/src/components/notifications/NotificationItem.tsx +1 -1
- package/src/components/notifications/NotificationsList.tsx +5 -1
- package/src/components/post/Feed.tsx +3 -1
- package/src/components/post/FeedPost.tsx +32 -37
- package/src/components/post/FeedPostContent.tsx +6 -8
- package/src/components/post/feed/events/EventsFeed.tsx +1 -0
- package/src/components/post/pieces/PostActions.tsx +46 -121
- package/src/components/post/pieces/PostInfoHeader.tsx +9 -5
- package/src/components/post/post-form/Footer.tsx +47 -64
- package/src/components/post/post-form/OpenpeepsMarkdownInput.tsx +3 -0
- package/src/components/post/post-form/PollComposerFields.tsx +2 -2
- package/src/components/post/post-form/PostForm.tsx +133 -129
- package/src/components/post/types/Note.tsx +1 -1
- package/src/components/post/types/Poll.tsx +1 -1
- package/src/components/post/types/article/CardArticle.tsx +1 -1
- package/src/components/post/types/event/CardEvent.tsx +1 -1
- package/src/components/post/types/event/FullEvent.tsx +21 -20
- package/src/components/profile/ProfileCard.tsx +1 -1
- package/src/components/profile/ProfileHeader.tsx +8 -10
- package/src/pages/Explore.tsx +30 -5
- package/src/pages/Members.tsx +2 -2
- package/src/pages/conversations/Index.tsx +1 -1
- package/src/pages/conversations/New.tsx +8 -1
- package/src/pages/groups/Index.tsx +8 -1
- package/src/pages/groups/Info.tsx +4 -4
- package/src/pages/groups/Show.tsx +42 -3
- package/src/pages/posts/Edit.tsx +43 -5
- package/src/pages/posts/New.tsx +121 -74
- package/src/pages/posts/Reply.tsx +77 -49
- package/src/pages/profile/Followers.tsx +4 -1
- package/src/pages/profile/Following.tsx +4 -1
package/src/pages/Explore.tsx
CHANGED
|
@@ -236,7 +236,12 @@ export const Explore: React.FC<ExploreScreenProps> = ({ navigation }) => {
|
|
|
236
236
|
/>
|
|
237
237
|
)}
|
|
238
238
|
uniqueBy={(item) => String(item?.data?.id)}
|
|
239
|
-
ListEmptyComponent={
|
|
239
|
+
ListEmptyComponent={
|
|
240
|
+
<EmptyStateContainer
|
|
241
|
+
type="profiles"
|
|
242
|
+
copyKey="explore.noProfilesFound"
|
|
243
|
+
/>
|
|
244
|
+
}
|
|
240
245
|
/>
|
|
241
246
|
</TabsContent>
|
|
242
247
|
<TabsContent value="posts" className="w-full p-0">
|
|
@@ -251,7 +256,12 @@ export const Explore: React.FC<ExploreScreenProps> = ({ navigation }) => {
|
|
|
251
256
|
<FeedPost key={item.data.id} post={item.data} showReplyTo />
|
|
252
257
|
)}
|
|
253
258
|
uniqueBy={(item) => String(item?.data?.id)}
|
|
254
|
-
ListEmptyComponent={
|
|
259
|
+
ListEmptyComponent={
|
|
260
|
+
<EmptyStateContainer
|
|
261
|
+
type="posts"
|
|
262
|
+
copyKey="explore.noPostsFound"
|
|
263
|
+
/>
|
|
264
|
+
}
|
|
255
265
|
/>
|
|
256
266
|
</TabsContent>
|
|
257
267
|
<TabsContent value="jams" className="w-full p-2">
|
|
@@ -266,7 +276,12 @@ export const Explore: React.FC<ExploreScreenProps> = ({ navigation }) => {
|
|
|
266
276
|
<CardEvent key={item.data.id} post={item.data} />
|
|
267
277
|
)}
|
|
268
278
|
uniqueBy={(item) => String(item?.data?.id)}
|
|
269
|
-
ListEmptyComponent={
|
|
279
|
+
ListEmptyComponent={
|
|
280
|
+
<EmptyStateContainer
|
|
281
|
+
type="my-jams"
|
|
282
|
+
copyKey="explore.noJamsFound"
|
|
283
|
+
/>
|
|
284
|
+
}
|
|
270
285
|
/>
|
|
271
286
|
</TabsContent>
|
|
272
287
|
<TabsContent value="events" className="w-full p-2">
|
|
@@ -281,7 +296,12 @@ export const Explore: React.FC<ExploreScreenProps> = ({ navigation }) => {
|
|
|
281
296
|
<CardEvent key={item.data.id} post={item.data} />
|
|
282
297
|
)}
|
|
283
298
|
uniqueBy={(item) => String(item?.data?.id)}
|
|
284
|
-
ListEmptyComponent={
|
|
299
|
+
ListEmptyComponent={
|
|
300
|
+
<EmptyStateContainer
|
|
301
|
+
type="events"
|
|
302
|
+
copyKey="explore.noEventsFound"
|
|
303
|
+
/>
|
|
304
|
+
}
|
|
285
305
|
/>
|
|
286
306
|
</TabsContent>
|
|
287
307
|
<TabsContent value="groups" className="w-full p-2">
|
|
@@ -303,7 +323,12 @@ export const Explore: React.FC<ExploreScreenProps> = ({ navigation }) => {
|
|
|
303
323
|
/>
|
|
304
324
|
)}
|
|
305
325
|
uniqueBy={(item) => String(item?.data?.id)}
|
|
306
|
-
ListEmptyComponent={
|
|
326
|
+
ListEmptyComponent={
|
|
327
|
+
<EmptyStateContainer
|
|
328
|
+
type="groups"
|
|
329
|
+
copyKey="explore.noGroupsFound"
|
|
330
|
+
/>
|
|
331
|
+
}
|
|
307
332
|
/>
|
|
308
333
|
</TabsContent>
|
|
309
334
|
</Tabs>
|
package/src/pages/Members.tsx
CHANGED
|
@@ -88,7 +88,7 @@ export const Members: React.FC<DirectoryProps> = ({ navigation }) => {
|
|
|
88
88
|
</>
|
|
89
89
|
}
|
|
90
90
|
/>
|
|
91
|
-
<KeyboardAwareScrollView className="w-full grow flex bg-background
|
|
91
|
+
<KeyboardAwareScrollView className="relative w-full grow flex bg-background gap-y-4 border-t border-border p-2">
|
|
92
92
|
{isLoading && <ActivityIndicator size={'small'} />}
|
|
93
93
|
{filteredProfiles?.map((profile, index) => {
|
|
94
94
|
return (
|
|
@@ -117,7 +117,7 @@ export const Members: React.FC<DirectoryProps> = ({ navigation }) => {
|
|
|
117
117
|
})}
|
|
118
118
|
|
|
119
119
|
{filteredProfiles?.length === 0 && (
|
|
120
|
-
<EmptyStateContainer type="profiles" />
|
|
120
|
+
<EmptyStateContainer type="profiles" copyKey="members.empty" />
|
|
121
121
|
)}
|
|
122
122
|
<View className="mb-36" />
|
|
123
123
|
</KeyboardAwareScrollView>
|
|
@@ -136,7 +136,7 @@ export const ConversationsIndex: React.FC<MessagesProps> = ({ navigation }) => {
|
|
|
136
136
|
>
|
|
137
137
|
{isLoading && <ActivityIndicator size={'small'} />}
|
|
138
138
|
{!isLoading && filteredConversations?.length === 0 && (
|
|
139
|
-
<EmptyStateContainer type="messages" />
|
|
139
|
+
<EmptyStateContainer type="messages" copyKey="conversations.empty" />
|
|
140
140
|
)}
|
|
141
141
|
{!isLoading &&
|
|
142
142
|
filteredConversations?.map((conversation, idx) => (
|
|
@@ -118,7 +118,14 @@ export const NewConversation = ({
|
|
|
118
118
|
|
|
119
119
|
{!isLoading && filteredProfiles?.length === 0 && (
|
|
120
120
|
<View className="flex-1 items-center justify-center mt-4 pb-12">
|
|
121
|
-
<EmptyStateContainer
|
|
121
|
+
<EmptyStateContainer
|
|
122
|
+
type="profiles"
|
|
123
|
+
copyKey={
|
|
124
|
+
searchQuery
|
|
125
|
+
? 'profile.selector.emptySearch'
|
|
126
|
+
: 'profile.selector.empty'
|
|
127
|
+
}
|
|
128
|
+
/>
|
|
122
129
|
</View>
|
|
123
130
|
)}
|
|
124
131
|
</KeyboardAwareScrollView>
|
|
@@ -151,7 +151,14 @@ export const GroupsIndex: React.FC<GroupsProps> = ({ navigation }) => {
|
|
|
151
151
|
>
|
|
152
152
|
{isLoading && <ActivityIndicator size={'small'} />}
|
|
153
153
|
{!isLoading && visibleGroups.length === 0 && (
|
|
154
|
-
<EmptyStateContainer
|
|
154
|
+
<EmptyStateContainer
|
|
155
|
+
type="groups"
|
|
156
|
+
copyKey={
|
|
157
|
+
!searchQuery && filterBy === 'my-groups'
|
|
158
|
+
? 'groups.noGroupsYet'
|
|
159
|
+
: 'groups.noGroupsFound'
|
|
160
|
+
}
|
|
161
|
+
/>
|
|
155
162
|
)}
|
|
156
163
|
{!isLoading &&
|
|
157
164
|
visibleGroups.map((group) => (
|
|
@@ -51,13 +51,13 @@ export const GroupInfo = ({ route }: GroupInfoProps) => {
|
|
|
51
51
|
<>
|
|
52
52
|
<ThemedText className="text-2xl">About Group</ThemedText>
|
|
53
53
|
|
|
54
|
-
<View className="
|
|
54
|
+
<View className="my-4 border-b border-border py-4">
|
|
55
55
|
<ThemedText className="text-lg font-semibold">
|
|
56
56
|
Description
|
|
57
57
|
</ThemedText>
|
|
58
58
|
<OpenpeepsMarkdown source={groupData?.description || ''} />
|
|
59
59
|
</View>
|
|
60
|
-
<View className="
|
|
60
|
+
<View className="my-4 space-y-6 border-b border-border py-4">
|
|
61
61
|
<ThemedText className="text-lg font-semibold">Details</ThemedText>
|
|
62
62
|
|
|
63
63
|
<ThemedText className="">
|
|
@@ -130,7 +130,7 @@ export const GroupInfoAsComponent: React.FC<GroupInfoAsComponentProps> = ({
|
|
|
130
130
|
{isLoading && <ActivityIndicator size={'small'} />}
|
|
131
131
|
{!isLoading && (
|
|
132
132
|
<>
|
|
133
|
-
<View className="border-b
|
|
133
|
+
<View className="border-b border-border">
|
|
134
134
|
<ThemedText className="text-lg font-semibold">
|
|
135
135
|
Description
|
|
136
136
|
</ThemedText>
|
|
@@ -140,7 +140,7 @@ export const GroupInfoAsComponent: React.FC<GroupInfoAsComponentProps> = ({
|
|
|
140
140
|
}
|
|
141
141
|
/>
|
|
142
142
|
</View>
|
|
143
|
-
<View className="
|
|
143
|
+
<View className="my-2 flex gap-y-2 border-b border-border py-4">
|
|
144
144
|
<ThemedText className="text-lg font-semibold">Details</ThemedText>
|
|
145
145
|
<View>
|
|
146
146
|
<ThemedText className="font-semibold">Created</ThemedText>
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import React, { useEffect, useState } from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
ActivityIndicator,
|
|
4
|
+
Pressable,
|
|
5
|
+
RefreshControl,
|
|
6
|
+
View,
|
|
7
|
+
} from 'react-native';
|
|
3
8
|
import { KeyboardAwareScrollView } from 'react-native-keyboard-aware-scroll-view';
|
|
4
9
|
import { useTranslation } from 'react-i18next';
|
|
5
10
|
import { CompositeScreenProps } from '@react-navigation/native';
|
|
@@ -52,6 +57,8 @@ export const GroupShow = ({ route, navigation }: GroupProps) => {
|
|
|
52
57
|
const upcomingEvents = openpeepsApi.useGroupUpcomingEventsFeed(
|
|
53
58
|
group?.id ?? ''
|
|
54
59
|
);
|
|
60
|
+
const pastEvents = openpeepsApi.useGroupPastEventsFeed(group?.id ?? '');
|
|
61
|
+
const [eventsTab, setEventsTab] = useState<'upcoming' | 'past'>('upcoming');
|
|
55
62
|
|
|
56
63
|
useEffect(
|
|
57
64
|
() =>
|
|
@@ -68,7 +75,7 @@ export const GroupShow = ({ route, navigation }: GroupProps) => {
|
|
|
68
75
|
};
|
|
69
76
|
|
|
70
77
|
const tabClass = (value: Tab) =>
|
|
71
|
-
tab === value ? 'border-b-2 border-
|
|
78
|
+
tab === value ? 'border-b-2 border-primary font-semibold' : '';
|
|
72
79
|
|
|
73
80
|
return (
|
|
74
81
|
<ThemedSafeAreaView className="relative flex-1">
|
|
@@ -117,7 +124,39 @@ export const GroupShow = ({ route, navigation }: GroupProps) => {
|
|
|
117
124
|
<GroupFeed group={group} />
|
|
118
125
|
</TabsContent>
|
|
119
126
|
<TabsContent value="events" className="p-2">
|
|
120
|
-
<
|
|
127
|
+
<View className="mb-2 flex-row border-b border-border">
|
|
128
|
+
<Pressable
|
|
129
|
+
className={`px-4 py-2 ${
|
|
130
|
+
eventsTab === 'upcoming'
|
|
131
|
+
? 'border-b-2 border-primary'
|
|
132
|
+
: ''
|
|
133
|
+
}`}
|
|
134
|
+
onPress={() => setEventsTab('upcoming')}
|
|
135
|
+
>
|
|
136
|
+
<ThemedText
|
|
137
|
+
className={
|
|
138
|
+
eventsTab === 'upcoming' ? 'font-semibold' : ''
|
|
139
|
+
}
|
|
140
|
+
>
|
|
141
|
+
{t('events.feed.upcoming')}
|
|
142
|
+
</ThemedText>
|
|
143
|
+
</Pressable>
|
|
144
|
+
<Pressable
|
|
145
|
+
className={`px-4 py-2 ${
|
|
146
|
+
eventsTab === 'past' ? 'border-b-2 border-primary' : ''
|
|
147
|
+
}`}
|
|
148
|
+
onPress={() => setEventsTab('past')}
|
|
149
|
+
>
|
|
150
|
+
<ThemedText
|
|
151
|
+
className={eventsTab === 'past' ? 'font-semibold' : ''}
|
|
152
|
+
>
|
|
153
|
+
{t('events.feed.past')}
|
|
154
|
+
</ThemedText>
|
|
155
|
+
</Pressable>
|
|
156
|
+
</View>
|
|
157
|
+
<EventsFeed
|
|
158
|
+
query={eventsTab === 'upcoming' ? upcomingEvents : pastEvents}
|
|
159
|
+
/>
|
|
121
160
|
</TabsContent>
|
|
122
161
|
<TabsContent value="description" className="p-2">
|
|
123
162
|
<GroupInfoAsComponent id={group.id} />
|
package/src/pages/posts/Edit.tsx
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { useEffect, useState } from 'react';
|
|
1
|
+
import React, { useEffect, useMemo, useState } from 'react';
|
|
2
2
|
import { useOpenpeeps } from '@openpeepshq/react';
|
|
3
3
|
import { GenericHeader } from '../../components/custom/index';
|
|
4
4
|
import Toast from 'react-native-toast-message';
|
|
@@ -6,7 +6,12 @@ import { ThemedSafeAreaView } from '../../components/ui/themed-safe-area-view';
|
|
|
6
6
|
import { PostForm } from '../../components/post/post-form/PostForm';
|
|
7
7
|
import { useTranslation } from 'react-i18next';
|
|
8
8
|
import { MainScreenProps } from '../../components/navigation/types/index';
|
|
9
|
-
import {
|
|
9
|
+
import {
|
|
10
|
+
PostCreationData,
|
|
11
|
+
pollOptionsWithinLimit,
|
|
12
|
+
postCreationDataSchema,
|
|
13
|
+
resolvePollOptionContents,
|
|
14
|
+
} from '@openpeepshq/common';
|
|
10
15
|
import { ActivityIndicator } from 'react-native';
|
|
11
16
|
import { useForm } from 'react-hook-form';
|
|
12
17
|
import { hasProcessingAttachments } from '../../lib/post';
|
|
@@ -41,9 +46,42 @@ export const EditPost = ({ route, navigation }: PostProps) => {
|
|
|
41
46
|
const [isPosting, setIsPosting] = useState(false);
|
|
42
47
|
const attachmentsProcessing = hasProcessingAttachments(postData);
|
|
43
48
|
|
|
49
|
+
const trimmedContent = (postData?.data.content ?? '').trim();
|
|
50
|
+
const pollOptions =
|
|
51
|
+
postData?.data.type === 'question'
|
|
52
|
+
? postData.data.options.map((option) => option.content)
|
|
53
|
+
: [];
|
|
54
|
+
const resolvedPollOptions = resolvePollOptionContents(pollOptions, (index) =>
|
|
55
|
+
t('posts.form.poll.option', { number: index + 1 })
|
|
56
|
+
);
|
|
57
|
+
const pollOptionsValid =
|
|
58
|
+
resolvedPollOptions.length >= 2 &&
|
|
59
|
+
pollOptionsWithinLimit(resolvedPollOptions);
|
|
60
|
+
|
|
61
|
+
const canSubmit = useMemo(() => {
|
|
62
|
+
if (!postData || isPosting || attachmentsProcessing) {
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
if (postData.data.type === 'question') {
|
|
66
|
+
return trimmedContent.length > 0 && pollOptionsValid;
|
|
67
|
+
}
|
|
68
|
+
if (postData.type === 'article') {
|
|
69
|
+
return trimmedContent.length > 0;
|
|
70
|
+
}
|
|
71
|
+
return (
|
|
72
|
+
(trimmedContent.length > 0 && trimmedContent.length <= 500) ||
|
|
73
|
+
(postData.data.attachments?.length ?? 0) > 0
|
|
74
|
+
);
|
|
75
|
+
}, [
|
|
76
|
+
attachmentsProcessing,
|
|
77
|
+
isPosting,
|
|
78
|
+
pollOptionsValid,
|
|
79
|
+
postData,
|
|
80
|
+
trimmedContent.length,
|
|
81
|
+
]);
|
|
82
|
+
|
|
44
83
|
const handlePostUpdate = async () => {
|
|
45
|
-
if (!postData || !post?.data) {
|
|
46
|
-
Toast.show({ type: 'error', text1: t('posts.create.error') });
|
|
84
|
+
if (!postData || !post?.data || !canSubmit) {
|
|
47
85
|
return;
|
|
48
86
|
}
|
|
49
87
|
|
|
@@ -89,7 +127,7 @@ export const EditPost = ({ route, navigation }: PostProps) => {
|
|
|
89
127
|
: t('posts.edit.submit')
|
|
90
128
|
}
|
|
91
129
|
onRightButtonPress={handlePostUpdate}
|
|
92
|
-
rightButtonDisabled={
|
|
130
|
+
rightButtonDisabled={!canSubmit}
|
|
93
131
|
/>
|
|
94
132
|
{postData && (
|
|
95
133
|
<>
|
package/src/pages/posts/New.tsx
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
import React, {
|
|
1
|
+
import React, {
|
|
2
|
+
useCallback,
|
|
3
|
+
useEffect,
|
|
4
|
+
useMemo,
|
|
5
|
+
useRef,
|
|
6
|
+
useState,
|
|
7
|
+
} from 'react';
|
|
2
8
|
import { checkMediaPermissions } from '../../lib/media-permissions';
|
|
3
9
|
import { NativeStackScreenProps } from '@react-navigation/native-stack';
|
|
4
10
|
import {
|
|
@@ -10,14 +16,15 @@ import {
|
|
|
10
16
|
AudioPickerSheet,
|
|
11
17
|
GenericHeader,
|
|
12
18
|
ImagePickerSheet,
|
|
13
|
-
VideoPickerSheet,
|
|
14
19
|
DocumentPickerSheet,
|
|
15
20
|
type DocumentPickerSheetHandle,
|
|
16
21
|
} from '../../components/custom/index';
|
|
17
22
|
import {
|
|
23
|
+
checkRoleCapabilities,
|
|
18
24
|
MediaAttachment,
|
|
25
|
+
pollOptionsWithinLimit,
|
|
19
26
|
PostCreationData,
|
|
20
|
-
|
|
27
|
+
resolvePollOptionContents,
|
|
21
28
|
VisibilityType,
|
|
22
29
|
} from '@openpeepshq/common';
|
|
23
30
|
import { CompositeScreenProps } from '@react-navigation/native';
|
|
@@ -27,14 +34,10 @@ import { useLocalPostStore } from '../../stores/useLocalPostStore';
|
|
|
27
34
|
import { PostForm } from '../../components/post/post-form/PostForm';
|
|
28
35
|
import { useTranslation } from 'react-i18next';
|
|
29
36
|
import { KeyboardAwareScrollView } from 'react-native-keyboard-aware-scroll-view';
|
|
30
|
-
import Footer from '../../components/post/post-form/Footer';
|
|
37
|
+
import { Footer } from '../../components/post/post-form/Footer';
|
|
38
|
+
import { PostTypeSwitcher } from '../../components/post/post-form/PostTypeSwitcher';
|
|
31
39
|
import { BottomSheetModal } from '@gorhom/bottom-sheet';
|
|
32
|
-
import {
|
|
33
|
-
hasProcessingAttachments,
|
|
34
|
-
toArticle,
|
|
35
|
-
toNote,
|
|
36
|
-
toQuestion,
|
|
37
|
-
} from '../../lib/post';
|
|
40
|
+
import { hasProcessingAttachments, toNote, toQuestion } from '../../lib/post';
|
|
38
41
|
import { useForm } from 'react-hook-form';
|
|
39
42
|
|
|
40
43
|
import { ArticleForm } from '../../components/post/index';
|
|
@@ -51,8 +54,11 @@ export const NewPost = ({ route, navigation }: PostProps) => {
|
|
|
51
54
|
const publicContent = !!server?.publicContent;
|
|
52
55
|
|
|
53
56
|
const createPost = openpeepsApi.createPostAction();
|
|
57
|
+
const announcePost = openpeepsApi.admin.announcePostAction();
|
|
58
|
+
const joinGroup = openpeepsApi.joinGroupAction();
|
|
54
59
|
|
|
55
60
|
const [isPosting, setIsPosting] = useState(false);
|
|
61
|
+
const [notify, setNotify] = useState(false);
|
|
56
62
|
|
|
57
63
|
const postData = useLocalPostStore((state) => state.postData);
|
|
58
64
|
const attachmentsProcessing = hasProcessingAttachments(postData);
|
|
@@ -60,7 +66,6 @@ export const NewPost = ({ route, navigation }: PostProps) => {
|
|
|
60
66
|
const resetPostData = useLocalPostStore((state) => state.resetPostData);
|
|
61
67
|
|
|
62
68
|
const imagePickerModalRef = useRef<BottomSheetModal>(null);
|
|
63
|
-
const videoPickerModalRef = useRef<BottomSheetModal>(null);
|
|
64
69
|
const audioPickerModalRef = useRef<BottomSheetModal>(null);
|
|
65
70
|
const documentPickerModalRef = useRef<DocumentPickerSheetHandle>(null);
|
|
66
71
|
|
|
@@ -68,24 +73,86 @@ export const NewPost = ({ route, navigation }: PostProps) => {
|
|
|
68
73
|
defaultValues: postData,
|
|
69
74
|
});
|
|
70
75
|
|
|
71
|
-
const joinGroup = openpeepsApi.addGroupMemberAction();
|
|
72
|
-
|
|
73
76
|
const resetForm = useCallback(async () => {
|
|
74
77
|
form.reset();
|
|
75
78
|
setPostData(postData);
|
|
76
79
|
resetPostData();
|
|
77
80
|
}, [form, setPostData, resetPostData, postData]);
|
|
78
81
|
|
|
82
|
+
const canNotify = useMemo(
|
|
83
|
+
() =>
|
|
84
|
+
checkRoleCapabilities(currentProfile?.roles ?? [], [
|
|
85
|
+
'allpeep-core-admin-notify',
|
|
86
|
+
]).success,
|
|
87
|
+
[currentProfile?.roles]
|
|
88
|
+
);
|
|
89
|
+
|
|
90
|
+
const showNotify =
|
|
91
|
+
canNotify &&
|
|
92
|
+
(postData.visibility === 'public' || postData.visibility === 'local');
|
|
93
|
+
|
|
94
|
+
const trimmedContent = (postData.data.content ?? '').trim();
|
|
95
|
+
const pollOptions =
|
|
96
|
+
postData.data.type === 'question'
|
|
97
|
+
? postData.data.options.map((option) => option.content)
|
|
98
|
+
: [];
|
|
99
|
+
const resolvedPollOptions = resolvePollOptionContents(pollOptions, (index) =>
|
|
100
|
+
t('posts.form.poll.option', { number: index + 1 })
|
|
101
|
+
);
|
|
102
|
+
const pollOptionsValid =
|
|
103
|
+
resolvedPollOptions.length >= 2 &&
|
|
104
|
+
pollOptionsWithinLimit(resolvedPollOptions);
|
|
105
|
+
|
|
106
|
+
const canSubmit = useMemo(() => {
|
|
107
|
+
if (isPosting || attachmentsProcessing) {
|
|
108
|
+
return false;
|
|
109
|
+
}
|
|
110
|
+
if (postData.visibility === 'direct' && !postData.audience?.length) {
|
|
111
|
+
return false;
|
|
112
|
+
}
|
|
113
|
+
if (postData.visibility === 'group' && !postData.groupId) {
|
|
114
|
+
return false;
|
|
115
|
+
}
|
|
116
|
+
if (postData.data.type === 'question') {
|
|
117
|
+
return trimmedContent.length > 0 && pollOptionsValid;
|
|
118
|
+
}
|
|
119
|
+
if (postData.type === 'article') {
|
|
120
|
+
return trimmedContent.length > 0;
|
|
121
|
+
}
|
|
122
|
+
return (
|
|
123
|
+
(trimmedContent.length > 0 && trimmedContent.length <= 500) ||
|
|
124
|
+
(postData.data.attachments?.length ?? 0) > 0
|
|
125
|
+
);
|
|
126
|
+
}, [
|
|
127
|
+
attachmentsProcessing,
|
|
128
|
+
isPosting,
|
|
129
|
+
pollOptionsValid,
|
|
130
|
+
postData.audience?.length,
|
|
131
|
+
postData.data.attachments?.length,
|
|
132
|
+
postData.data.type,
|
|
133
|
+
postData.groupId,
|
|
134
|
+
postData.type,
|
|
135
|
+
postData.visibility,
|
|
136
|
+
trimmedContent.length,
|
|
137
|
+
]);
|
|
138
|
+
|
|
79
139
|
const handlePostCreation = async () => {
|
|
140
|
+
if (!canSubmit) {
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
|
|
80
144
|
try {
|
|
81
145
|
setIsPosting(true);
|
|
82
146
|
|
|
83
147
|
await handleGroupJoinIfNeeded();
|
|
84
|
-
await createPost(postData as PostCreationData);
|
|
148
|
+
const response = await createPost(postData as PostCreationData);
|
|
149
|
+
if (notify && canNotify && response?.id) {
|
|
150
|
+
await announcePost({ id: response.id });
|
|
151
|
+
}
|
|
85
152
|
|
|
86
153
|
await handlePostSuccess();
|
|
87
154
|
} catch {
|
|
88
|
-
Toast.show({ type: 'error', text1: t('posts.create.
|
|
155
|
+
Toast.show({ type: 'error', text1: t('posts.create.errorGeneric') });
|
|
89
156
|
} finally {
|
|
90
157
|
setIsPosting(false);
|
|
91
158
|
}
|
|
@@ -95,21 +162,19 @@ export const NewPost = ({ route, navigation }: PostProps) => {
|
|
|
95
162
|
if (
|
|
96
163
|
postData.visibility === 'group' &&
|
|
97
164
|
postData.groupId &&
|
|
98
|
-
!currentProfile?.memberships
|
|
99
|
-
|
|
100
|
-
|
|
165
|
+
!currentProfile?.memberships?.some(
|
|
166
|
+
(membership) => membership.group.id === postData.groupId
|
|
167
|
+
)
|
|
101
168
|
) {
|
|
102
|
-
await joinGroup({
|
|
103
|
-
...(currentProfile as PublicProfile),
|
|
104
|
-
});
|
|
169
|
+
await joinGroup({ id: postData.groupId });
|
|
105
170
|
}
|
|
106
171
|
};
|
|
107
172
|
|
|
108
173
|
const handlePostSuccess = async () => {
|
|
109
|
-
Toast.show({ type: 'success', text1: t('posts.create.
|
|
174
|
+
Toast.show({ type: 'success', text1: t('posts.create.successToast') });
|
|
175
|
+
await resetForm();
|
|
110
176
|
|
|
111
177
|
if (postData.visibility === 'group' && postData.groupId) {
|
|
112
|
-
resetForm();
|
|
113
178
|
if (navigation.canGoBack()) {
|
|
114
179
|
navigation.goBack();
|
|
115
180
|
}
|
|
@@ -135,13 +200,6 @@ export const NewPost = ({ route, navigation }: PostProps) => {
|
|
|
135
200
|
}
|
|
136
201
|
}, [t]);
|
|
137
202
|
|
|
138
|
-
const handleVideoModalPress = useCallback(async () => {
|
|
139
|
-
const hasPermission = await checkMediaPermissions(t, 'video');
|
|
140
|
-
if (hasPermission) {
|
|
141
|
-
videoPickerModalRef.current?.present();
|
|
142
|
-
}
|
|
143
|
-
}, [t]);
|
|
144
|
-
|
|
145
203
|
const handleAudioModalPress = useCallback(async () => {
|
|
146
204
|
const hasPermission = await checkMediaPermissions(t, 'audio');
|
|
147
205
|
if (hasPermission) {
|
|
@@ -164,31 +222,18 @@ export const NewPost = ({ route, navigation }: PostProps) => {
|
|
|
164
222
|
[postData, form, setPostData]
|
|
165
223
|
);
|
|
166
224
|
|
|
167
|
-
const
|
|
168
|
-
|
|
169
|
-
postData.data.type ===
|
|
170
|
-
|
|
171
|
-
: toQuestion(postData);
|
|
172
|
-
form.reset(newPostData);
|
|
173
|
-
setPostData(newPostData);
|
|
174
|
-
}, [postData, form, setPostData]);
|
|
175
|
-
|
|
176
|
-
const handleSwithToArticlePress = useCallback(() => {
|
|
177
|
-
const newPostData =
|
|
178
|
-
postData.type === 'article' ? toNote(postData) : toArticle(postData);
|
|
179
|
-
form.reset(newPostData);
|
|
180
|
-
setPostData(newPostData);
|
|
181
|
-
}, [postData, form, setPostData]);
|
|
182
|
-
|
|
183
|
-
useEffect(() => {
|
|
184
|
-
const unsubscribe = navigation.addListener('focus', () => {
|
|
185
|
-
if (!route.params?.originatorId && !route.params?.withContent) {
|
|
186
|
-
resetForm();
|
|
225
|
+
const handleSelectComposerType = useCallback(
|
|
226
|
+
(next: 'note' | 'question') => {
|
|
227
|
+
if (postData.data.type === next) {
|
|
228
|
+
return;
|
|
187
229
|
}
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
230
|
+
const newPostData =
|
|
231
|
+
next === 'question' ? toQuestion(postData) : toNote(postData);
|
|
232
|
+
form.reset(newPostData);
|
|
233
|
+
setPostData(newPostData);
|
|
234
|
+
},
|
|
235
|
+
[postData, form, setPostData]
|
|
236
|
+
);
|
|
192
237
|
|
|
193
238
|
useEffect(() => {
|
|
194
239
|
if (!publicContent && postData.visibility === 'public') {
|
|
@@ -211,15 +256,14 @@ export const NewPost = ({ route, navigation }: PostProps) => {
|
|
|
211
256
|
setPostData(newPostData);
|
|
212
257
|
}, [route, form, setPostData]);
|
|
213
258
|
|
|
259
|
+
const isArticle = postData.type === 'article';
|
|
260
|
+
const composerType = postData.data.type === 'question' ? 'question' : 'note';
|
|
261
|
+
|
|
214
262
|
return (
|
|
215
263
|
<ThemedSafeAreaView className="flex-1 bg-background">
|
|
216
264
|
<GenericHeader
|
|
217
265
|
title={
|
|
218
|
-
|
|
219
|
-
? t('articles.create.title')
|
|
220
|
-
: postData.data.type === 'question'
|
|
221
|
-
? t('posts.create.title')
|
|
222
|
-
: t('posts.create.title')
|
|
266
|
+
isArticle ? t('articles.create.title') : t('posts.newPost.title')
|
|
223
267
|
}
|
|
224
268
|
rightType="button"
|
|
225
269
|
rightButtonTitle={
|
|
@@ -239,40 +283,43 @@ export const NewPost = ({ route, navigation }: PostProps) => {
|
|
|
239
283
|
navigation.goBack();
|
|
240
284
|
}
|
|
241
285
|
}}
|
|
242
|
-
rightButtonDisabled={
|
|
286
|
+
rightButtonDisabled={!canSubmit}
|
|
243
287
|
onRightButtonPress={handlePostCreation}
|
|
244
288
|
/>
|
|
245
289
|
<KeyboardAwareScrollView className="flex-1">
|
|
246
|
-
{
|
|
290
|
+
{isArticle ? (
|
|
247
291
|
<ArticleForm postData={postData} onChange={setPostData} />
|
|
248
|
-
)
|
|
249
|
-
{(postData.type === 'question' || postData.type === 'note') && (
|
|
292
|
+
) : (
|
|
250
293
|
<PostForm
|
|
251
294
|
postData={postData}
|
|
252
295
|
setPostData={setPostData}
|
|
253
|
-
canEditVisibility
|
|
296
|
+
canEditVisibility={route.params?.triggeredFrom !== 'group'}
|
|
254
297
|
form={form}
|
|
298
|
+
showNotify={showNotify}
|
|
299
|
+
notify={notify}
|
|
300
|
+
onNotifyChange={setNotify}
|
|
255
301
|
/>
|
|
256
302
|
)}
|
|
257
303
|
</KeyboardAwareScrollView>
|
|
258
304
|
<Footer
|
|
259
|
-
|
|
260
|
-
postType={postData?.data?.type}
|
|
305
|
+
hideMedia={isArticle || composerType === 'question'}
|
|
261
306
|
onImagePress={handleImageModalPress}
|
|
262
|
-
|
|
263
|
-
onVideoPress={handleVideoModalPress}
|
|
264
|
-
onPollPress={handleSwitchPollPress}
|
|
307
|
+
onAudioPress={handleAudioModalPress}
|
|
265
308
|
onDocumentPress={handleDocumentModalPress}
|
|
266
|
-
|
|
309
|
+
typeSwitcher={
|
|
310
|
+
<PostTypeSwitcher
|
|
311
|
+
type={isArticle ? 'article' : composerType}
|
|
312
|
+
onSelect={handleSelectComposerType}
|
|
313
|
+
onClose={() => undefined}
|
|
314
|
+
visibility={postData.visibility}
|
|
315
|
+
groupId={postData.groupId ?? undefined}
|
|
316
|
+
/>
|
|
317
|
+
}
|
|
267
318
|
/>
|
|
268
319
|
<ImagePickerSheet
|
|
269
320
|
ref={imagePickerModalRef}
|
|
270
321
|
onSelect={handleAddAttachments}
|
|
271
322
|
/>
|
|
272
|
-
<VideoPickerSheet
|
|
273
|
-
ref={videoPickerModalRef}
|
|
274
|
-
onSelect={handleAddAttachments}
|
|
275
|
-
/>
|
|
276
323
|
<AudioPickerSheet
|
|
277
324
|
ref={audioPickerModalRef}
|
|
278
325
|
onSelect={handleAddAttachments}
|