@openpeepshq/rn-components 0.6.11 → 0.7.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openpeepshq/rn-components",
3
- "version": "0.6.11",
3
+ "version": "0.7.1",
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",
@@ -142,8 +142,8 @@
142
142
  "timezones-list": "^3.1.0",
143
143
  "validator": "^13.15.23",
144
144
  "zustand": "^5.0.3",
145
- "@openpeepshq/react": "^0.6.3",
146
- "@openpeepshq/common": "^0.3.2"
145
+ "@openpeepshq/common": "^0.4.0",
146
+ "@openpeepshq/react": "^0.7.0"
147
147
  },
148
148
  "devDependencies": {
149
149
  "@babel/core": "^7.26.7",
@@ -9,6 +9,7 @@ import { useCurrentProfile } from '@openpeepshq/react';
9
9
  import { MainStackParamList } from '../navigation/types/index';
10
10
  import { ThemedText } from '../ui/themed-text';
11
11
  import { GroupAvatar } from './GroupAvatar';
12
+ import { GroupNotificationButton } from './GroupNotificationSettingsModal';
12
13
  import { GroupOptionsMenu } from './GroupOptionsMenu';
13
14
  import { GroupShareMenu } from './GroupShareMenu';
14
15
  import { JoinGroupButton } from './JoinGroupButton';
@@ -46,6 +47,7 @@ export const GroupHeader = ({ group }: GroupHeaderProps) => {
46
47
  ) : (
47
48
  <>
48
49
  <GroupShareMenu group={group} />
50
+ <GroupNotificationButton group={group} />
49
51
  <GroupOptionsMenu group={group} />
50
52
  </>
51
53
  )}
@@ -0,0 +1,139 @@
1
+ import { useState } from 'react';
2
+ import { ActivityIndicator, Pressable, View } from 'react-native';
3
+ import { useTranslation } from 'react-i18next';
4
+ import Toast from 'react-native-toast-message';
5
+ import {
6
+ groupName,
7
+ groupNotificationLevelOptions,
8
+ type GroupNotificationLevel,
9
+ type GroupWithMeta,
10
+ } from '@openpeepshq/common';
11
+ import { useGroupNotificationLevel } from '@openpeepshq/react';
12
+ import { BellIcon } from '../icons/index';
13
+ import { ThemedText } from '../ui/themed-text';
14
+ import { RadioGroup, RadioGroupItem } from '../ui/radio-group';
15
+ import { useControlledSheet } from '../../hooks/use-controlled-sheet';
16
+ import { BaseSheet, SheetFooter } from '../custom/modals/common';
17
+
18
+ export interface GroupNotificationSettingsModalProps {
19
+ group: GroupWithMeta;
20
+ onClose: () => void;
21
+ }
22
+
23
+ const optionLabelKey: Record<GroupNotificationLevel, string> = {
24
+ all: 'groups.modals.manageNotifications.options.all',
25
+ mostRelevant: 'groups.modals.manageNotifications.options.mostRelevant',
26
+ off: 'groups.modals.manageNotifications.options.off',
27
+ };
28
+
29
+ const optionDescriptionKey: Record<GroupNotificationLevel, string> = {
30
+ all: 'groups.modals.manageNotifications.options.allDescription',
31
+ mostRelevant:
32
+ 'groups.modals.manageNotifications.options.mostRelevantDescription',
33
+ off: 'groups.modals.manageNotifications.options.offDescription',
34
+ };
35
+
36
+ export const GroupNotificationSettingsModal = ({
37
+ group,
38
+ onClose,
39
+ }: GroupNotificationSettingsModalProps) => {
40
+ const { t } = useTranslation();
41
+ const ref = useControlledSheet(true);
42
+ const { level, setLevel, save, saving, ready, loadFailed, error } =
43
+ useGroupNotificationLevel(group.id);
44
+
45
+ const onSave = async () => {
46
+ const saved = await save();
47
+ if (!saved) return;
48
+ Toast.show({
49
+ type: 'success',
50
+ text1: t('groups.modals.manageNotifications.saved', {
51
+ defaultValue: 'Group notification settings updated.',
52
+ }),
53
+ });
54
+ onClose();
55
+ };
56
+
57
+ return (
58
+ <BaseSheet ref={ref} onDismiss={onClose}>
59
+ <View className="flex-1 p-4">
60
+ <ThemedText className="mb-2 text-center text-xl font-semibold">
61
+ {t('groups.modals.manageNotifications.title')}
62
+ </ThemedText>
63
+ <ThemedText className="mb-6 text-center text-base text-muted-foreground">
64
+ {t('groups.modals.manageNotifications.description', {
65
+ groupName: groupName(group),
66
+ })}
67
+ </ThemedText>
68
+ {ready ? (
69
+ <RadioGroup
70
+ value={level}
71
+ onValueChange={(value) => setLevel(value as GroupNotificationLevel)}
72
+ >
73
+ {groupNotificationLevelOptions.map((option) => (
74
+ <View key={option} className="mb-4 flex-row items-start gap-x-3">
75
+ <RadioGroupItem value={option} />
76
+ <View className="flex-1">
77
+ <ThemedText className="text-base font-medium">
78
+ {t(optionLabelKey[option])}
79
+ </ThemedText>
80
+ <ThemedText className="text-sm text-muted-foreground">
81
+ {t(optionDescriptionKey[option])}
82
+ </ThemedText>
83
+ </View>
84
+ </View>
85
+ ))}
86
+ </RadioGroup>
87
+ ) : loadFailed ? (
88
+ <ThemedText className="mb-4 text-center text-sm text-destructive">
89
+ {t('groups.modals.manageNotifications.loadError', {
90
+ defaultValue: 'Could not load notification settings.',
91
+ })}
92
+ </ThemedText>
93
+ ) : (
94
+ <ActivityIndicator className="my-8" />
95
+ )}
96
+ {error ? (
97
+ <ThemedText className="mb-4 text-center text-sm text-destructive">
98
+ {error}
99
+ </ThemedText>
100
+ ) : null}
101
+ <SheetFooter
102
+ onCancel={onClose}
103
+ cancelText={t('common.cancel')}
104
+ onConfirm={() => void onSave()}
105
+ confirmText={saving ? t('common.saving') : t('common.save')}
106
+ disabled={saving || !ready}
107
+ isLoading={saving}
108
+ />
109
+ </View>
110
+ </BaseSheet>
111
+ );
112
+ };
113
+
114
+ export const GroupNotificationButton = ({
115
+ group,
116
+ }: {
117
+ group: GroupWithMeta;
118
+ }) => {
119
+ const { t } = useTranslation();
120
+ const [open, setOpen] = useState(false);
121
+
122
+ return (
123
+ <>
124
+ <Pressable
125
+ className="p-2"
126
+ accessibilityLabel={t('groups.modals.manageNotifications.title')}
127
+ onPress={() => setOpen(true)}
128
+ >
129
+ <BellIcon size={20} className="text-foreground" />
130
+ </Pressable>
131
+ {open ? (
132
+ <GroupNotificationSettingsModal
133
+ group={group}
134
+ onClose={() => setOpen(false)}
135
+ />
136
+ ) : null}
137
+ </>
138
+ );
139
+ };
@@ -5,6 +5,7 @@ import Clipboard from '@react-native-clipboard/clipboard';
5
5
  import Toast from 'react-native-toast-message';
6
6
  import { useNavigation } from '@react-navigation/native';
7
7
  import { NativeStackNavigationProp } from '@react-navigation/native-stack';
8
+ import { groupSectionPath, type GroupSection } from '@openpeepshq/common/lib';
8
9
  import type { GroupWithMeta } from '@openpeepshq/common/types';
9
10
  import { LinkIcon, PencilIcon, SendIcon, ShareIcon } from '../icons/index';
10
11
  import { MainStackParamList } from '../navigation/types/index';
@@ -33,8 +34,17 @@ export const GroupShareMenu = ({ group }: GroupShareMenuProps) => {
33
34
  const { openNewPost } = useNewPostModal();
34
35
  const { setContt } = useNewConversationStore();
35
36
 
36
- const groupUrl = `${BASE_URL}/groups/@${group.handle}`;
37
+ const groupUrl = `${BASE_URL}${groupSectionPath(group.handle)}`;
37
38
  const inviteBlurb = t('groups.share.inviteBlurb', { url: groupUrl });
39
+ const copySectionLink = (section: GroupSection, copiedKey: string) => {
40
+ Clipboard.setString(
41
+ `${BASE_URL}${groupSectionPath(group.handle, section)}`
42
+ );
43
+ Toast.show({
44
+ type: 'success',
45
+ text1: t(copiedKey),
46
+ });
47
+ };
38
48
 
39
49
  return (
40
50
  <DropdownMenu>
@@ -78,17 +88,41 @@ export const GroupShareMenu = ({ group }: GroupShareMenuProps) => {
78
88
  </DropdownMenuLabel>
79
89
  <DropdownMenuItem
80
90
  className="flex-row items-center gap-x-2"
81
- onPress={() => {
82
- Clipboard.setString(groupUrl);
83
- Toast.show({
84
- type: 'success',
85
- text1: t('groups.share.linkCopied'),
86
- });
87
- }}
91
+ onPress={() => copySectionLink('posts', 'groups.share.linkCopied')}
88
92
  >
89
93
  <LinkIcon size={16} className="text-foreground" />
90
94
  <ThemedText>{t('groups.share.copyLink')}</ThemedText>
91
95
  </DropdownMenuItem>
96
+ <DropdownMenuItem
97
+ className="flex-row items-center gap-x-2"
98
+ onPress={() =>
99
+ copySectionLink('events', 'groups.share.eventsLinkCopied')
100
+ }
101
+ >
102
+ <LinkIcon size={16} className="text-foreground" />
103
+ <ThemedText>{t('groups.share.copyEventsLink')}</ThemedText>
104
+ </DropdownMenuItem>
105
+ <DropdownMenuItem
106
+ className="flex-row items-center gap-x-2"
107
+ onPress={() =>
108
+ copySectionLink('resources', 'groups.share.resourcesLinkCopied')
109
+ }
110
+ >
111
+ <LinkIcon size={16} className="text-foreground" />
112
+ <ThemedText>{t('groups.share.copyResourcesLink')}</ThemedText>
113
+ </DropdownMenuItem>
114
+ <DropdownMenuItem
115
+ className="flex-row items-center gap-x-2"
116
+ onPress={() =>
117
+ copySectionLink(
118
+ 'description',
119
+ 'groups.share.descriptionLinkCopied'
120
+ )
121
+ }
122
+ >
123
+ <LinkIcon size={16} className="text-foreground" />
124
+ <ThemedText>{t('groups.share.copyDescriptionLink')}</ThemedText>
125
+ </DropdownMenuItem>
92
126
  </DropdownMenuGroup>
93
127
  </DropdownMenuContent>
94
128
  </DropdownMenu>
@@ -13,5 +13,6 @@ export * from './GroupHeader';
13
13
  export * from './GroupMembersList';
14
14
  export * from './GroupNameFromId';
15
15
  export * from './GroupOptionsMenu';
16
+ export * from './GroupNotificationSettingsModal';
16
17
  export * from './GroupShareMenu';
17
18
  export * from './JoinGroupButton';
@@ -45,6 +45,7 @@ export const buildGoto =
45
45
  navigation.navigate('Group', {
46
46
  id: params?.id,
47
47
  handle: params?.handle,
48
+ ...(params?.tab ? { tab: params.tab } : {}),
48
49
  });
49
50
  break;
50
51
  case 'messages':
@@ -1,4 +1,5 @@
1
1
  import { NavigatorScreenParams } from '@react-navigation/native';
2
+ import type { GroupSection } from '@openpeepshq/common/lib';
2
3
  import { TabStackParamList } from './tabs';
3
4
  import { NativeStackScreenProps } from '@react-navigation/native-stack';
4
5
 
@@ -38,6 +39,7 @@ export type MainStackParamList = {
38
39
  Group: {
39
40
  id?: string;
40
41
  handle?: string;
42
+ tab?: GroupSection;
41
43
  };
42
44
  GroupMembers: {
43
45
  id: string;
@@ -59,6 +59,7 @@ import {
59
59
  canAccessJamRecordings,
60
60
  canModerateJam,
61
61
  canViewJamAttendees,
62
+ defaultRsvpRecurrenceId,
62
63
  effectiveEventTimes,
63
64
  eventTimeZoneOptions,
64
65
  formatEventClockTime,
@@ -109,7 +110,11 @@ export const FullEvent: React.FC<FullEventProps> = ({ post, occurrence }) => {
109
110
  ? event.maxAttendees - countYesRsvps(post, occurrence)
110
111
  : null;
111
112
  const rsvpManage = openpeepsApi.rsvpManageAction();
112
- const times = effectiveEventTimes(event, occurrence);
113
+ const times = effectiveEventTimes(
114
+ event,
115
+ occurrence ??
116
+ (event?.recurrence ? defaultRsvpRecurrenceId(event) : undefined)
117
+ );
113
118
  const tz = eventTimeZoneOptions(event?.timeZone);
114
119
  const recurrenceLabel = event?.recurrence
115
120
  ? formatEventRecurrence(event.recurrence, t, event.start)
package/src/lib/utils.ts CHANGED
@@ -6,6 +6,7 @@ import {
6
6
  Profile,
7
7
  PublicProfile,
8
8
  SuccessFailureResponse,
9
+ groupSectionFromHash,
9
10
  } from '@openpeepshq/common';
10
11
  import { NativeScrollEvent } from 'react-native';
11
12
  import { buildGoto } from '../components/navigation/helpers';
@@ -125,25 +126,36 @@ export const handleInternalURLNavigation = (
125
126
  goto: ReturnType<typeof buildGoto>
126
127
  ) => {
127
128
  const navigatePath = (path: string) => {
128
- if (isGroupPath(path)) {
129
+ const hashStart = path.indexOf('#');
130
+ const hash = hashStart === -1 ? '' : path.slice(hashStart);
131
+ const pathWithoutHash = hashStart === -1 ? path : path.slice(0, hashStart);
132
+
133
+ if (isGroupPath(pathWithoutHash)) {
134
+ const pathname = pathWithoutHash.split('?')[0] ?? pathWithoutHash;
129
135
  goto({
130
136
  target: 'group',
131
- params: { handle: path.slice('/groups/@'.length).split('/')[0] },
137
+ params: {
138
+ handle: pathname.slice('/groups/@'.length).split('/')[0],
139
+ tab: groupSectionFromHash(hash),
140
+ },
132
141
  });
133
142
  return true;
134
143
  }
135
- if (isJamPath(path)) {
136
- goto({ target: 'event', params: { id: path.split('/')[2] } });
144
+ if (isJamPath(pathWithoutHash)) {
145
+ goto({ target: 'event', params: { id: pathWithoutHash.split('/')[2] } });
137
146
  return true;
138
147
  }
139
- if (isPostPath(path)) {
140
- goto({ target: 'posts', params: { id: path.split('/')[2] } });
148
+ if (isPostPath(pathWithoutHash)) {
149
+ goto({
150
+ target: 'posts',
151
+ params: { id: pathWithoutHash.split('/')[2] },
152
+ });
141
153
  return true;
142
154
  }
143
- if (isProfilePath(path)) {
155
+ if (isProfilePath(pathWithoutHash)) {
144
156
  goto({
145
157
  target: 'profile',
146
- params: { handle: path.slice(2).split('/')[0] },
158
+ params: { handle: pathWithoutHash.slice(2).split('/')[0] },
147
159
  });
148
160
  return true;
149
161
  }
@@ -158,12 +170,11 @@ export const handleInternalURLNavigation = (
158
170
  }
159
171
  }
160
172
 
161
- const path = isLocalLink(defaultAction, BASE_URL as string)
162
- ? new URL(defaultAction).pathname
163
- : null;
164
-
165
- if (path && navigatePath(path)) {
166
- return;
173
+ if (isLocalLink(defaultAction, BASE_URL as string)) {
174
+ const url = new URL(defaultAction);
175
+ if (navigatePath(`${url.pathname}${url.hash}`)) {
176
+ return;
177
+ }
167
178
  }
168
179
 
169
180
  const actionList = defaultAction.replace('goto:/', '').split('/');
@@ -9,7 +9,11 @@ import { KeyboardAwareScrollView } from 'react-native-keyboard-aware-scroll-view
9
9
  import { useTranslation } from 'react-i18next';
10
10
  import { CompositeScreenProps } from '@react-navigation/native';
11
11
  import { NativeStackScreenProps } from '@react-navigation/native-stack';
12
- import { groupName } from '@openpeepshq/common/lib';
12
+ import {
13
+ groupName,
14
+ groupSectionFromHash,
15
+ type GroupSection,
16
+ } from '@openpeepshq/common/lib';
13
17
  import { useCurrentProfile, useOpenpeeps } from '@openpeepshq/react';
14
18
  import { useSetPageHeader } from '../../components/layout';
15
19
  import { ThemedView } from '../../components/ui/themed-view';
@@ -40,15 +44,20 @@ type GroupProps = CompositeScreenProps<
40
44
  NativeStackScreenProps<TabStackParamList>
41
45
  >;
42
46
 
43
- type Tab = 'posts' | 'events' | 'resources' | 'description';
44
-
45
47
  export const GroupShow = ({ route, navigation }: GroupProps) => {
46
48
  const { openpeepsApi } = useOpenpeeps();
47
49
  const { t } = useTranslation();
48
50
  const currentProfile = useCurrentProfile();
49
51
  const [isRefreshing, setIsRefreshing] = useState(false);
50
- const { id, handle } = route.params;
51
- const [tab, setTab] = useState<Tab>('posts');
52
+ const { id, handle, tab: tabParam } = route.params;
53
+ const [tab, setTab] = useState<GroupSection>(() =>
54
+ groupSectionFromHash(tabParam ? `#${tabParam}` : '')
55
+ );
56
+
57
+ useEffect(() => {
58
+ if (!tabParam) return;
59
+ setTab(groupSectionFromHash(`#${tabParam}`));
60
+ }, [tabParam]);
52
61
  const groupById = openpeepsApi.useGroup(id || '');
53
62
  const groupByHandle = openpeepsApi.useGroupByHandle(handle || '');
54
63
 
@@ -76,7 +85,7 @@ export const GroupShow = ({ route, navigation }: GroupProps) => {
76
85
  setIsRefreshing(false);
77
86
  };
78
87
 
79
- const tabClass = (value: Tab) =>
88
+ const tabClass = (value: GroupSection) =>
80
89
  tab === value ? 'border-b-2 border-primary font-semibold' : '';
81
90
 
82
91
  useSetPageHeader(truncateText(group ? groupName(group) : '', 30));
@@ -106,7 +115,7 @@ export const GroupShow = ({ route, navigation }: GroupProps) => {
106
115
  <GroupHeader group={group} />
107
116
  <Tabs
108
117
  value={tab}
109
- onValueChange={(value) => setTab(value as Tab)}
118
+ onValueChange={(value) => setTab(value as GroupSection)}
110
119
  className="mx-auto w-full flex-col gap-1.5"
111
120
  >
112
121
  <TabsList className="w-full flex-row rounded-none border-b border-muted bg-transparent p-0 px-3">
package/src/types/goto.ts CHANGED
@@ -1,3 +1,5 @@
1
+ import type { GroupSection } from '@openpeepshq/common/lib';
2
+
1
3
  /**
2
4
  * Ad-hoc params for `buildGoto` deep links and side-menu actions (string targets).
3
5
  */
@@ -6,4 +8,5 @@ export type GotoHandlerParams = {
6
8
  handle?: string;
7
9
  tag?: string;
8
10
  jamId?: string;
11
+ tab?: GroupSection;
9
12
  };