@openpeepshq/rn-components 0.8.4 → 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.4",
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",
@@ -104,7 +104,7 @@ export const EditNotificationsSheet = forwardRef<
104
104
  };
105
105
 
106
106
  return (
107
- <BaseSheet ref={ref} key={name}>
107
+ <BaseSheet ref={ref} key={name} scrollable>
108
108
  <View className="flex-1 p-4">
109
109
  <View className="w-full">
110
110
  <ThemedText className="text-center text-xl font-semibold mb-6">
@@ -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;
@@ -13,6 +13,17 @@ import { Avatar, AvatarImage } from '../ui/avatar';
13
13
  import { UserXIcon } from '../icons/index';
14
14
  import { cn } from '../../lib/utils';
15
15
 
16
+ /** Tailwind spacing unit in dp (size-N / w-N → N × 4). */
17
+ const TAILWIND_UNIT = 4;
18
+ /** Initials and deleted-icon scale with the avatar instead of preset buckets. */
19
+ const FONT_RATIO = 0.375;
20
+ const ICON_RATIO = 0.4375;
21
+
22
+ const avatarPxFromClassName = (className?: string): number => {
23
+ const match = className?.match(/(?:^|\s)(?:size-|w-)(\d+)(?=\s|$)/);
24
+ return match ? Number(match[1]) * TAILWIND_UNIT : 64;
25
+ };
26
+
16
27
  export const ProfileAvatar = ({
17
28
  profile,
18
29
  className,
@@ -23,9 +34,9 @@ export const ProfileAvatar = ({
23
34
  const { t } = useTranslation();
24
35
  const { isDark } = useOpenPeepsTheme();
25
36
 
26
- const isSmall = className?.includes('size-8');
27
- const sizeClass = isSmall ? 'h-8 w-8' : 'h-16 w-16';
28
- const iconSize = isSmall ? 16 : 28;
37
+ const px = avatarPxFromClassName(className);
38
+ const iconSize = Math.max(12, Math.round(px * ICON_RATIO));
39
+ const fontSize = Math.max(10, Math.round(px * FONT_RATIO));
29
40
  const roundedClass = 'rounded-full';
30
41
  const deleted = isDeletedProfile(profile);
31
42
 
@@ -36,16 +47,18 @@ export const ProfileAvatar = ({
36
47
  const backgroundColor =
37
48
  !deleted && !avatarSource ? initialsBackground(hue, isDark) : undefined;
38
49
 
50
+ const rootClassName = cn(
51
+ 'border border-muted-foreground overflow-hidden',
52
+ roundedClass,
53
+ className
54
+ );
55
+
39
56
  if (deleted || !avatarSource) {
40
57
  return (
41
58
  <Avatar
42
59
  alt={t('profile.header.avatarAlt')}
43
- className={cn(
44
- 'border border-muted-foreground overflow-hidden',
45
- sizeClass,
46
- roundedClass,
47
- className
48
- )}
60
+ className={rootClassName}
61
+ style={{ width: px, height: px }}
49
62
  >
50
63
  <View
51
64
  className={cn(
@@ -57,10 +70,7 @@ export const ProfileAvatar = ({
57
70
  {deleted ? (
58
71
  <UserXIcon size={iconSize} className="text-muted-foreground" />
59
72
  ) : (
60
- <Text
61
- className="text-foreground font-medium"
62
- style={{ fontSize: isSmall ? 14 : 24 }}
63
- >
73
+ <Text className="text-foreground font-medium" style={{ fontSize }}>
64
74
  {getInitials(profile?.displayName, profile?.handle)}
65
75
  </Text>
66
76
  )}
@@ -72,12 +82,8 @@ export const ProfileAvatar = ({
72
82
  return (
73
83
  <Avatar
74
84
  alt={t('profile.header.avatarAlt')}
75
- className={cn(
76
- 'border border-muted-foreground overflow-hidden',
77
- sizeClass,
78
- roundedClass,
79
- className
80
- )}
85
+ className={rootClassName}
86
+ style={{ width: px, height: px }}
81
87
  >
82
88
  <AvatarImage
83
89
  source={avatarSource}
@@ -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
  );
@@ -205,7 +205,7 @@ export const ConversationShow = ({ route, navigation }: ConversationProps) => {
205
205
  <DropdownMenu>
206
206
  <KeyboardAvoidingView
207
207
  className="flex-1"
208
- behavior={Platform.OS === 'ios' ? 'padding' : undefined}
208
+ behavior={Platform.OS === 'ios' ? 'padding' : 'height'}
209
209
  keyboardVerticalOffset={Platform.OS === 'ios' ? 90 : 0}
210
210
  >
211
211
  <ScrollView
@@ -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}