@openpeepshq/rn-components 0.8.5 → 0.8.6

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openpeepshq/rn-components",
3
- "version": "0.8.5",
3
+ "version": "0.8.6",
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",
@@ -143,7 +143,7 @@
143
143
  "validator": "^13.15.23",
144
144
  "zustand": "^5.0.3",
145
145
  "@openpeepshq/common": "^0.4.0",
146
- "@openpeepshq/react": "^0.8.5"
146
+ "@openpeepshq/react": "^0.8.6"
147
147
  },
148
148
  "devDependencies": {
149
149
  "@babel/core": "^7.26.7",
@@ -8,8 +8,10 @@ import type {
8
8
  } from '@openpeepshq/common';
9
9
  import { HEADER_IMAGE_MAX_WIDTH } from '@openpeepshq/common/lib';
10
10
  import { applyAudienceSetting, useCurrentProfile } from '@openpeepshq/react';
11
+ import { MegaphoneIcon } from '../../icons/index';
11
12
  import { ImageInput } from '../../form/ImageInput';
12
13
  import { Input } from '../../ui/input';
14
+ import { Switch } from '../../ui/switch';
13
15
  import { ThemedText } from '../../ui/themed-text';
14
16
  import { OpenpeepsMarkdownInput } from './OpenpeepsMarkdownInput';
15
17
  import { VisibilitySelector } from './VisibilitySelector';
@@ -18,12 +20,18 @@ export interface ArticleFormProps {
18
20
  postData: PostCreationData;
19
21
  onChange: (data: PostCreationData) => void;
20
22
  isEdit?: boolean;
23
+ showNotify?: boolean;
24
+ notify?: boolean;
25
+ onNotifyChange?: (value: boolean) => void;
21
26
  }
22
27
 
23
28
  export const ArticleForm = ({
24
29
  postData,
25
30
  onChange,
26
31
  isEdit = false,
32
+ showNotify = false,
33
+ notify = false,
34
+ onNotifyChange,
27
35
  }: ArticleFormProps) => {
28
36
  const { t } = useTranslation();
29
37
  const me = useCurrentProfile();
@@ -95,6 +103,21 @@ export const ArticleForm = ({
95
103
  showDirect
96
104
  />
97
105
  </View>
106
+
107
+ {showNotify ? (
108
+ <View className="flex-row items-center justify-between py-1">
109
+ <View className="flex-row items-center gap-2">
110
+ <MegaphoneIcon size={20} className="text-foreground" />
111
+ <ThemedText className="text-base">
112
+ {t('posts.form.notifyEveryone')}
113
+ </ThemedText>
114
+ </View>
115
+ <Switch
116
+ checked={notify}
117
+ onCheckedChange={onNotifyChange ?? (() => undefined)}
118
+ />
119
+ </View>
120
+ ) : null}
98
121
  </View>
99
122
  </View>
100
123
  );
@@ -14,10 +14,16 @@ import {
14
14
  type RepeatEnd,
15
15
  type RepeatFreq,
16
16
  } from '@openpeepshq/react';
17
- import { CalendarIcon, ChevronDownIcon, XIcon } from '../../icons/index';
17
+ import {
18
+ CalendarIcon,
19
+ ChevronDownIcon,
20
+ MegaphoneIcon,
21
+ XIcon,
22
+ } from '../../icons/index';
18
23
  import { ImageInput } from '../../form/ImageInput';
19
24
  import { TimeZoneSelect } from '../../form/TimeZoneSelect';
20
25
  import { Checkbox } from '../../ui/checkbox';
26
+ import { Switch } from '../../ui/switch';
21
27
  import { Input } from '../../ui/input';
22
28
  import { Label } from '../../ui/label';
23
29
  import { RadioGroup, RadioGroupItem } from '../../ui/radio-group';
@@ -37,6 +43,9 @@ export interface EventFormProps {
37
43
  onChange: (data: PostCreationData) => void;
38
44
  isEdit?: boolean;
39
45
  occurrenceEdit?: boolean;
46
+ showNotify?: boolean;
47
+ notify?: boolean;
48
+ onNotifyChange?: (value: boolean) => void;
40
49
  }
41
50
 
42
51
  const REPEAT_FREQS: RepeatFreq[] = ['none', 'DAILY', 'WEEKLY', 'MONTHLY'];
@@ -87,6 +96,9 @@ export const EventForm = ({
87
96
  onChange,
88
97
  isEdit = false,
89
98
  occurrenceEdit = false,
99
+ showNotify = false,
100
+ notify = false,
101
+ onNotifyChange,
90
102
  }: EventFormProps) => {
91
103
  const { t } = useTranslation();
92
104
  const [endBeforeStart, setEndBeforeStart] = useState(false);
@@ -350,6 +362,21 @@ export const EventForm = ({
350
362
  />
351
363
  </View>
352
364
 
365
+ {showNotify ? (
366
+ <View className="flex-row items-center justify-between py-1">
367
+ <View className="flex-row items-center gap-2">
368
+ <MegaphoneIcon size={20} className="text-foreground" />
369
+ <ThemedText className="text-base">
370
+ {t('posts.form.notifyEveryone')}
371
+ </ThemedText>
372
+ </View>
373
+ <Switch
374
+ checked={notify}
375
+ onCheckedChange={onNotifyChange ?? (() => undefined)}
376
+ />
377
+ </View>
378
+ ) : null}
379
+
353
380
  <Pressable
354
381
  onPress={() =>
355
382
  patchEvent({ attendeeListPublic: !event.attendeeListPublic })
@@ -1,4 +1,4 @@
1
- import React, { useMemo, useRef, useState } from 'react';
1
+ import React, { useLayoutEffect, useMemo, useRef, useState } from 'react';
2
2
  import {
3
3
  Linking,
4
4
  Pressable,
@@ -60,6 +60,13 @@ export const OpenpeepsMarkdownInput = ({
60
60
  const [open, setOpen] = useState(false);
61
61
  const [showPreview, setShowPreview] = useState(false);
62
62
  const valueRef = useRef(value);
63
+
64
+ // Preview is local state. Clearing the text after send has to leave an
65
+ // editable field, not the preview pane.
66
+ useLayoutEffect(() => {
67
+ if (value.length === 0) setShowPreview(false);
68
+ }, [value]);
69
+
63
70
  const cursorRef = useRef(value.length);
64
71
 
65
72
  valueRef.current = value;
@@ -19,6 +19,9 @@ export const NewArticle: React.FC<NewArticleProps> = () => {
19
19
  submitting,
20
20
  error,
21
21
  clearError,
22
+ notify,
23
+ setNotify,
24
+ showNotify,
22
25
  submit,
23
26
  } = useNewArticle();
24
27
 
@@ -48,7 +51,13 @@ export const NewArticle: React.FC<NewArticleProps> = () => {
48
51
  contentContainerClassName="grow"
49
52
  className="pb-12"
50
53
  >
51
- <ArticleForm postData={postData} onChange={setPostData} />
54
+ <ArticleForm
55
+ postData={postData}
56
+ onChange={setPostData}
57
+ showNotify={showNotify}
58
+ notify={notify}
59
+ onNotifyChange={setNotify}
60
+ />
52
61
  </KeyboardAwareScrollView>
53
62
  </ThemedView>
54
63
  );
@@ -19,6 +19,9 @@ export const NewEvent = (_props: NewEventProps) => {
19
19
  submitting,
20
20
  error,
21
21
  clearError,
22
+ notify,
23
+ setNotify,
24
+ showNotify,
22
25
  submit,
23
26
  } = useNewEvent();
24
27
 
@@ -44,7 +47,13 @@ export const NewEvent = (_props: NewEventProps) => {
44
47
  contentContainerClassName="grow"
45
48
  className="pb-12"
46
49
  >
47
- <EventForm postData={postData} onChange={setPostData} />
50
+ <EventForm
51
+ postData={postData}
52
+ onChange={setPostData}
53
+ showNotify={showNotify}
54
+ notify={notify}
55
+ onNotifyChange={setNotify}
56
+ />
48
57
  </KeyboardAwareScrollView>
49
58
  </ThemedView>
50
59
  );
@@ -66,7 +66,7 @@ export const GroupsIndex: React.FC<GroupsProps> = ({ navigation }) => {
66
66
  useSetPlusButtonActions(
67
67
  canCreate
68
68
  ? {
69
- title: t('groups.new'),
69
+ title: t('groups.new.label'),
70
70
  action: () => navigation.navigate('CreateGroup'),
71
71
  }
72
72
  : undefined
@@ -21,7 +21,8 @@ import {
21
21
  import { HeaderActionButton, useSetPageHeader } from '../../components/layout';
22
22
  import { ThemedView } from '../../components/ui/themed-view';
23
23
  import {
24
- checkRoleCapabilities,
24
+ canAnnouncePosts,
25
+ isCommunityWideVisibility,
25
26
  MediaAttachment,
26
27
  pollOptionsWithinLimit,
27
28
  PostCreationData,
@@ -80,16 +81,12 @@ export const NewPost = ({ route, navigation }: PostProps) => {
80
81
  }, [form, setPostData, resetPostData, postData]);
81
82
 
82
83
  const canNotify = useMemo(
83
- () =>
84
- checkRoleCapabilities(currentProfile?.roles ?? [], [
85
- 'allpeep-core-admin-notify',
86
- ]).success,
84
+ () => canAnnouncePosts(currentProfile?.roles),
87
85
  [currentProfile?.roles]
88
86
  );
89
87
 
90
88
  const showNotify =
91
- canNotify &&
92
- (postData.visibility === 'public' || postData.visibility === 'local');
89
+ canNotify && isCommunityWideVisibility(postData.visibility);
93
90
 
94
91
  const trimmedContent = (postData.data.content ?? '').trim();
95
92
  const pollOptions =
@@ -146,7 +143,7 @@ export const NewPost = ({ route, navigation }: PostProps) => {
146
143
 
147
144
  await handleGroupJoinIfNeeded();
148
145
  const response = await createPost(postData as PostCreationData);
149
- if (notify && canNotify && response?.id) {
146
+ if (notify && showNotify && response?.id) {
150
147
  await announcePost({ id: response.id });
151
148
  }
152
149
 
@@ -289,7 +286,13 @@ export const NewPost = ({ route, navigation }: PostProps) => {
289
286
  <ThemedView className="flex-1 bg-background">
290
287
  <KeyboardAwareScrollView className="flex-1">
291
288
  {isArticle ? (
292
- <ArticleForm postData={postData} onChange={setPostData} />
289
+ <ArticleForm
290
+ postData={postData}
291
+ onChange={setPostData}
292
+ showNotify={showNotify}
293
+ notify={notify}
294
+ onNotifyChange={setNotify}
295
+ />
293
296
  ) : (
294
297
  <PostForm
295
298
  postData={postData}