@openpeepshq/rn-components 0.3.12 → 0.4.0

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.3.12",
3
+ "version": "0.4.0",
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",
@@ -141,7 +141,7 @@
141
141
  "validator": "^13.15.23",
142
142
  "zustand": "^5.0.3",
143
143
  "@openpeepshq/common": "^0.2.0",
144
- "@openpeepshq/react": "^0.3.3"
144
+ "@openpeepshq/react": "^0.4.0"
145
145
  },
146
146
  "devDependencies": {
147
147
  "@babel/core": "^7.26.7",
@@ -182,13 +182,6 @@
182
182
  "turbo": "^1.10.7",
183
183
  "typescript": "~5.8.3"
184
184
  },
185
- "jest": {
186
- "preset": "react-native",
187
- "modulePathIgnorePatterns": [
188
- "<rootDir>/example/node_modules",
189
- "<rootDir>/lib/"
190
- ]
191
- },
192
185
  "commitlint": {
193
186
  "extends": [
194
187
  "@commitlint/config-conventional"
@@ -6,7 +6,10 @@ import { ChevronRightIcon } from '../icons/index';
6
6
 
7
7
  export interface ConfigMenuButtonProps {
8
8
  translationPrefix: string;
9
- onPress: () => void;
9
+ /** URL path (web). On RN, use onPress instead — URL navigation is not supported. */
10
+ action?: string;
11
+ /** Click handler. */
12
+ onPress?: () => void;
10
13
  titleFallback?: string;
11
14
  descriptionFallback?: string;
12
15
  }
@@ -19,9 +22,10 @@ export const ConfigMenuButton = ({
19
22
  descriptionFallback,
20
23
  }: ConfigMenuButtonProps) => {
21
24
  const { t } = useTranslation();
25
+ const handlePress = onPress ?? (() => {});
22
26
  return (
23
27
  <Pressable
24
- onPress={onPress}
28
+ onPress={handlePress}
25
29
  className="py-2 mb-2 flex-row justify-between items-center gap-x-4"
26
30
  >
27
31
  <View className="flex-1">
@@ -0,0 +1,147 @@
1
+ /**
2
+ * Regression tests for the page-chrome infinite update loop
3
+ * ("Maximum update depth exceeded") that crashed Groups, Jams and Explore
4
+ * (and any other page that registers header or plus actions with fresh,
5
+ * non-memoized values) in @openpeepshq/rn-components 0.3.12.
6
+ *
7
+ * Root cause: useSetPageHeader / useSetPlusButtonActions read their
8
+ * setters from the same context whose value changes whenever the header
9
+ * or plus state changes. A screen that registers a fresh element or
10
+ * object therefore re-renders on every chrome update, re-runs its layout
11
+ * effect and calls setState again.
12
+ */
13
+ import { type ReactNode } from 'react';
14
+ import ReactTestRenderer from 'react-test-renderer';
15
+ import {
16
+ PageChromeProvider,
17
+ usePageChrome,
18
+ useSetPageHeader,
19
+ useSetPlusButtonActions,
20
+ } from './pageChrome';
21
+
22
+ const MAX_RENDER_GUARD = 20;
23
+
24
+ const Text = ({ children }: { children?: ReactNode }) => (
25
+ <text>{children}</text>
26
+ );
27
+
28
+ const View = ({ children }: { children?: ReactNode }) => (
29
+ <view>{children}</view>
30
+ );
31
+
32
+ const render = (ui: ReactNode) => {
33
+ const element = <PageChromeProvider>{ui}</PageChromeProvider>;
34
+ let tree!: ReactTestRenderer.ReactTestRenderer;
35
+ ReactTestRenderer.act(() => {
36
+ tree = ReactTestRenderer.create(element);
37
+ });
38
+ return tree;
39
+ };
40
+
41
+ const UnstableHeaderScreen = ({ onRender }: { onRender: () => void }) => {
42
+ onRender();
43
+ useSetPageHeader(
44
+ 'Jams',
45
+ <View>
46
+ <Text>actions</Text>
47
+ </View>
48
+ );
49
+ return <Text>screen</Text>;
50
+ };
51
+
52
+ const UnstablePlusScreen = ({ onRender }: { onRender: () => void }) => {
53
+ onRender();
54
+ useSetPageHeader('Groups');
55
+ useSetPlusButtonActions({ title: 'New group', action: () => {} });
56
+ return <Text>screen</Text>;
57
+ };
58
+
59
+ const StableScreen = () => {
60
+ useSetPageHeader('Feed');
61
+ return <Text>screen</Text>;
62
+ };
63
+
64
+ const ChromeProbe = ({
65
+ onChrome,
66
+ }: {
67
+ onChrome: (title?: string, plusTitle?: string) => void;
68
+ }) => {
69
+ const { header, plus } = usePageChrome();
70
+ const plusTitle = Array.isArray(plus) ? plus[0]?.title : plus?.title;
71
+ onChrome(
72
+ typeof header?.title === 'string' ? header.title : undefined,
73
+ plusTitle
74
+ );
75
+ return null;
76
+ };
77
+
78
+ test('unstable header actions do not loop (jams/explore)', () => {
79
+ let renders = 0;
80
+ const tree = render(
81
+ <UnstableHeaderScreen
82
+ onRender={() => {
83
+ renders += 1;
84
+ if (renders > MAX_RENDER_GUARD) {
85
+ throw new Error('Maximum update depth exceeded');
86
+ }
87
+ }}
88
+ />
89
+ );
90
+ expect(renders).toBeLessThanOrEqual(MAX_RENDER_GUARD);
91
+ expect(JSON.stringify(tree.toJSON())).toContain('screen');
92
+ tree.unmount();
93
+ });
94
+
95
+ test('unstable plus actions do not loop (groups)', () => {
96
+ let renders = 0;
97
+ const tree = render(
98
+ <UnstablePlusScreen
99
+ onRender={() => {
100
+ renders += 1;
101
+ if (renders > MAX_RENDER_GUARD) {
102
+ throw new Error('Maximum update depth exceeded');
103
+ }
104
+ }}
105
+ />
106
+ );
107
+ expect(renders).toBeLessThanOrEqual(MAX_RENDER_GUARD);
108
+ expect(JSON.stringify(tree.toJSON())).toContain('screen');
109
+ tree.unmount();
110
+ });
111
+
112
+ test('stable title-only header still works', () => {
113
+ const tree = render(<StableScreen />);
114
+ expect(JSON.stringify(tree.toJSON())).toContain('screen');
115
+ tree.unmount();
116
+ });
117
+
118
+ test('display chrome still sees registered header and plus', () => {
119
+ let title: string | undefined;
120
+ let plusTitle: string | undefined;
121
+ const tree = render(
122
+ <View>
123
+ <UnstablePlusScreen onRender={() => {}} />
124
+ <ChromeProbe
125
+ onChrome={(nextTitle, nextPlusTitle) => {
126
+ title = nextTitle;
127
+ plusTitle = nextPlusTitle;
128
+ }}
129
+ />
130
+ </View>
131
+ );
132
+ expect(title).toBe('Groups');
133
+ expect(plusTitle).toBe('New group');
134
+ tree.unmount();
135
+ });
136
+
137
+ test('page chrome hooks throw outside RootLayout', () => {
138
+ const Bare = () => {
139
+ useSetPageHeader('Feed');
140
+ return null;
141
+ };
142
+ expect(() => {
143
+ ReactTestRenderer.act(() => {
144
+ ReactTestRenderer.create(<Bare />);
145
+ });
146
+ }).toThrow('Page chrome hooks must be used within RootLayout');
147
+ });
@@ -23,43 +23,78 @@ export type PageHeaderValue = {
23
23
  onBack?: () => void;
24
24
  };
25
25
 
26
- type PageChromeContextValue = {
27
- header: PageHeaderValue | undefined;
26
+ type PageChromeSetters = {
28
27
  setHeader: (header: PageHeaderValue | undefined) => void;
29
- plus: PlusButtonActions;
30
28
  setPlus: (plus: PlusButtonActions) => void;
31
29
  };
32
30
 
33
- const PageChromeContext = createContext<PageChromeContextValue | null>(null);
31
+ type PageChromeValues = {
32
+ header: PageHeaderValue | undefined;
33
+ plus: PlusButtonActions;
34
+ };
35
+
36
+ /**
37
+ * Stable setters context. Its value never changes, so components that call
38
+ * `useSetPageHeader` / `useSetPlusButtonActions` are not re-rendered when
39
+ * the chrome values change. Keeping the setters out of the value context is
40
+ * what prevents infinite update loops ("Maximum update depth exceeded") for
41
+ * pages that register a fresh, non-memoized header element or plus-actions
42
+ * object on every render.
43
+ */
44
+ const PageChromeSettersContext = createContext<PageChromeSetters | null>(null);
45
+
46
+ /**
47
+ * Chrome values context. Its value changes whenever the header or plus
48
+ * actions change, so it must only be consumed by display components
49
+ * (header/plus button) — never by a component that registers the values.
50
+ */
51
+ const PageChromeValuesContext = createContext<PageChromeValues | null>(null);
52
+
53
+ const MISSING_CHROME_ERROR = 'Page chrome hooks must be used within RootLayout';
34
54
 
35
55
  export const PageChromeProvider = ({ children }: { children: ReactNode }) => {
36
56
  const [header, setHeader] = useState<PageHeaderValue | undefined>();
37
57
  const [plus, setPlus] = useState<PlusButtonActions>(undefined);
38
- const value = useMemo(
39
- () => ({ header, setHeader, plus, setPlus }),
40
- [header, plus]
41
- );
58
+ // useState setters are stable, so this value is created exactly once.
59
+ const setters = useMemo(() => ({ setHeader, setPlus }), [setHeader, setPlus]);
60
+ const values = useMemo(() => ({ header, plus }), [header, plus]);
42
61
  return (
43
- <PageChromeContext.Provider value={value}>
44
- {children}
45
- </PageChromeContext.Provider>
62
+ <PageChromeSettersContext.Provider value={setters}>
63
+ <PageChromeValuesContext.Provider value={values}>
64
+ {children}
65
+ </PageChromeValuesContext.Provider>
66
+ </PageChromeSettersContext.Provider>
46
67
  );
47
68
  };
48
69
 
49
- export const usePageChrome = () => {
50
- const ctx = useContext(PageChromeContext);
70
+ const useSetters = () => {
71
+ const ctx = useContext(PageChromeSettersContext);
51
72
  if (!ctx) {
52
- throw new Error('usePageChrome must be used within RootLayout');
73
+ throw new Error(MISSING_CHROME_ERROR);
53
74
  }
54
75
  return ctx;
55
76
  };
56
77
 
78
+ const useValues = () => {
79
+ const ctx = useContext(PageChromeValuesContext);
80
+ if (!ctx) {
81
+ throw new Error(MISSING_CHROME_ERROR);
82
+ }
83
+ return ctx;
84
+ };
85
+
86
+ export const usePageChrome = () => {
87
+ const values = useValues();
88
+ const setters = useSetters();
89
+ return { ...values, ...setters };
90
+ };
91
+
57
92
  export const useSetPageHeader = (
58
93
  title?: ReactNode,
59
94
  actions?: ReactNode,
60
95
  onBack?: () => void
61
96
  ) => {
62
- const { setHeader } = usePageChrome();
97
+ const { setHeader } = useSetters();
63
98
  useLayoutEffect(() => {
64
99
  setHeader({ title, actions, onBack });
65
100
  return () => setHeader(undefined);
@@ -67,7 +102,7 @@ export const useSetPageHeader = (
67
102
  };
68
103
 
69
104
  export const useSetPlusButtonActions = (actions: PlusButtonActions) => {
70
- const { setPlus } = usePageChrome();
105
+ const { setPlus } = useSetters();
71
106
  useLayoutEffect(() => {
72
107
  setPlus(actions);
73
108
  return () => setPlus(undefined);
@@ -1,4 +1,5 @@
1
1
  import { useMemo } from 'react';
2
+ import { Linking } from 'react-native';
2
3
  import {
3
4
  CommonActions,
4
5
  createNavigationContainerRef,
@@ -188,6 +189,35 @@ export const navigateToTarget = (target: NavTarget) => {
188
189
  go('Auth', { screen: 'Login' });
189
190
  }
190
191
  break;
192
+ case 'admin':
193
+ // RN has no admin screens — fall back to settings tab.
194
+ go('Main', { screen: 'TabNavigator', params: { screen: 'Settings' } });
195
+ break;
196
+ case 'docs':
197
+ // Docs are web-only; open in the system browser.
198
+ if (target.path) {
199
+ Linking.openURL(
200
+ target.path.startsWith('/') ? `${target.path}` : target.path
201
+ );
202
+ }
203
+ break;
204
+ case 'paymentSuccess':
205
+ go('Main', { screen: 'TabNavigator', params: { screen: 'Onboarding' } });
206
+ break;
207
+ case 'external':
208
+ Linking.openURL(target.href);
209
+ break;
210
+ case 'path':
211
+ // Try to open as a URL; if it's a local path, fall back to home.
212
+ if (
213
+ target.path.startsWith('http://') ||
214
+ target.path.startsWith('https://')
215
+ ) {
216
+ Linking.openURL(target.path);
217
+ } else {
218
+ go('Main', { screen: 'TabNavigator', params: { screen: 'Home' } });
219
+ }
220
+ break;
191
221
  default:
192
222
  break;
193
223
  }
@@ -1,13 +1,13 @@
1
1
  import { View } from 'react-native';
2
2
  import React from 'react';
3
- import type { Group, Profile } from '@openpeepshq/common/types';
3
+ import type { Group, PublicProfile } from '@openpeepshq/common/types';
4
4
  import { DotIcon, UsersIcon, UserIcon } from '../icons/index';
5
5
  import { ThemedView } from '../ui/themed-view';
6
6
  import { ProfileAvatar } from '../profile/Avatar';
7
7
  import { GroupAvatar } from '../groups/GroupAvatar';
8
8
 
9
9
  interface NotificationWrapperProps {
10
- profile: Profile;
10
+ profile: PublicProfile;
11
11
  seen?: boolean;
12
12
  group?: Group | null;
13
13
  showProfile?: boolean;
@@ -2,22 +2,33 @@ import { ScrollView, RefreshControl, ActivityIndicator } from 'react-native';
2
2
  import React from 'react';
3
3
  import type { PublicNotification } from '@openpeepshq/common';
4
4
  import { useFocusEffect } from '@react-navigation/native';
5
+ import { useOpenpeeps } from '@openpeepshq/react';
5
6
  import { handleScroll } from '../../lib/utils';
6
7
  import { EmptyStateContainer } from '../custom/common/empty-state-container';
7
8
  import { NotificationItem } from './NotificationItem';
8
9
  import { InfiniteQueryResult } from '../../types';
9
10
 
10
- interface Props {
11
- query: InfiniteQueryResult<PublicNotification>;
11
+ export interface NotificationsListProps {
12
+ /** Supply your own query to control fetching externally. When omitted, the
13
+ * component fetches `useCurrentProfileNotifications` internally. */
14
+ query?: InfiniteQueryResult<PublicNotification>;
15
+ pageSize?: number;
12
16
  isNotificationFeed?: boolean;
13
17
  onRefresh?: () => Promise<unknown>;
14
18
  }
15
19
 
16
20
  export const NotificationsList = ({
17
- query,
21
+ query: externalQuery,
22
+ pageSize = 15,
18
23
  isNotificationFeed = true,
19
24
  onRefresh,
20
- }: Props) => {
25
+ }: NotificationsListProps) => {
26
+ const { openpeepsApi } = useOpenpeeps();
27
+ const internalQuery = openpeepsApi.useCurrentProfileNotifications({
28
+ limit: pageSize,
29
+ });
30
+ const query = externalQuery ?? internalQuery;
31
+
21
32
  const [refreshing, setRefreshing] = React.useState(false);
22
33
  const refetchRef = React.useRef(query.refetch);
23
34
  refetchRef.current = query.refetch;
@@ -3,6 +3,7 @@ import { useFeedPostPresentation } from '@openpeepshq/react';
3
3
  import { useNavigation } from '@react-navigation/native';
4
4
  import { NativeStackNavigationProp } from '@react-navigation/native-stack';
5
5
  import { Pressable } from 'react-native';
6
+ import { cn } from '../../lib/utils';
6
7
  import { MainStackParamList } from '../navigation/types/index';
7
8
  import {
8
9
  PostInfoHeader,
@@ -29,6 +30,7 @@ export interface FeedPostProps {
29
30
  hideReply?: boolean;
30
31
  previewMode?: boolean;
31
32
  showMenu?: boolean;
33
+ className?: string;
32
34
  }
33
35
 
34
36
  export const FeedPost = ({
@@ -41,6 +43,7 @@ export const FeedPost = ({
41
43
  hideReply,
42
44
  previewMode = false,
43
45
  showMenu = true,
46
+ className,
44
47
  }: FeedPostProps) => {
45
48
  const navigation =
46
49
  useNavigation<NativeStackNavigationProp<MainStackParamList>>();
@@ -77,7 +80,7 @@ export const FeedPost = ({
77
80
  <Pressable disabled={previewMode} onPress={handlePostPress}>
78
81
  <ThemedView
79
82
  ref={postViewRef}
80
- className="relative border-b border-border p-4"
83
+ className={cn('relative border-b border-border p-4', className)}
81
84
  >
82
85
  <UnreadPostIndicator show={isUnread} />
83
86
  {hasReactionHeader && (
@@ -16,6 +16,10 @@ export interface NewEventButtonProps {
16
16
  visibility: VisibilityType;
17
17
  currentProfile?: ProfileWithMeta;
18
18
  group?: GroupWithMeta;
19
+ /** When false, only registers the floating plus button (no inline button). */
20
+ showButton?: boolean;
21
+ /** Optional custom navigation callback (replaces default screen navigation). */
22
+ onNavigate?: () => void;
19
23
  }
20
24
 
21
25
  /** Registers the RootLayout plus button for creating an event. */
@@ -14,6 +14,8 @@ export interface NewNoteButtonProps {
14
14
  visibility: VisibilityType;
15
15
  currentProfile?: ProfileWithMeta;
16
16
  group?: GroupWithMeta;
17
+ /** When false, only registers the floating plus button (no inline feed button). */
18
+ inline?: boolean;
17
19
  }
18
20
 
19
21
  /** Registers the RootLayout plus button for creating a note. */
@@ -1,21 +1,34 @@
1
1
  import { View } from 'react-native';
2
2
  import React from 'react';
3
+ import { cn } from '../../../lib/utils';
3
4
 
4
5
  interface UnreadPostIndicatorProps {
5
6
  show: boolean;
7
+ className?: string;
8
+ /** `corner` is a top-left fold on feed cards; `dot` is the in-flow mark.
9
+ * On RN only `dot` is supported — `corner` renders nothing (CSS-only effect). */
10
+ variant?: 'dot' | 'corner';
6
11
  }
7
12
 
8
13
  /**
9
14
  * Subtle unread marker positioned in the host's left margin.
10
15
  * Absolutely positioned so visibility changes never shift layout.
11
16
  */
12
- export const UnreadPostIndicator = ({ show }: UnreadPostIndicatorProps) => {
17
+ export const UnreadPostIndicator = ({
18
+ show,
19
+ className,
20
+ variant = 'dot',
21
+ }: UnreadPostIndicatorProps) => {
13
22
  if (!show) return null;
23
+ if (variant === 'corner') return null;
14
24
 
15
25
  return (
16
26
  <View
17
27
  pointerEvents="none"
18
- className="absolute left-1.5 top-6 size-1.5 rounded-full bg-muted-foreground/45"
28
+ className={cn(
29
+ 'absolute left-1.5 top-6 size-1.5 rounded-full bg-muted-foreground/45',
30
+ className
31
+ )}
19
32
  />
20
33
  );
21
34
  };
@@ -13,11 +13,11 @@ import { MainStackParamList } from '../../navigation/types/index';
13
13
  import { useTranslation } from 'react-i18next';
14
14
  import { CachedImage } from '../../custom/common/index';
15
15
 
16
- interface Props {
16
+ export interface FeedArticleProps {
17
17
  post: PublicPost;
18
18
  }
19
19
 
20
- export const FeedArticle = ({ post }: Props) => {
20
+ export const FeedArticle = ({ post }: FeedArticleProps) => {
21
21
  const article = useMemo(() => post.data as Article, [post]);
22
22
 
23
23
  const previewContent = useMemo(
@@ -7,11 +7,11 @@ import { View } from 'react-native';
7
7
  import { ThemedText } from '../../ui/themed-text';
8
8
  import { OpenpeepsMarkdown } from '../../markdown/index';
9
9
 
10
- interface Props {
10
+ export interface FeedNoteProps {
11
11
  post: PublicPost;
12
12
  }
13
13
 
14
- export const FeedNote = ({ post }: Props) =>
14
+ export const FeedNote = ({ post }: FeedNoteProps) =>
15
15
  post?.data?.type === 'note' ? (
16
16
  <View>
17
17
  <Attachments {...{ post }} />
@@ -8,11 +8,13 @@ import { OpenpeepsMarkdown } from '../../markdown/index';
8
8
  import { ThemedText } from '../../ui/themed-text';
9
9
  import { PollContent } from '../pieces/PollContent';
10
10
 
11
- interface Props {
11
+ export interface FeedPollProps {
12
12
  post: PublicPost;
13
+ /** When false, show static options only (no voting). */
14
+ interactive?: boolean;
13
15
  }
14
16
 
15
- export const FeedPoll = ({ post }: Props) =>
17
+ export const FeedPoll = ({ post, interactive = true }: FeedPollProps) =>
16
18
  post?.data?.type === 'question' ? (
17
19
  <View>
18
20
  <Attachments {...{ post }} />
@@ -8,7 +8,7 @@ import { NativeStackNavigationProp } from '@react-navigation/native-stack';
8
8
  import { MainStackParamList } from '../../../navigation/types/index';
9
9
  import { CachedImage } from '../../../custom/common/index';
10
10
 
11
- interface CardArticleProps {
11
+ export interface CardArticleProps {
12
12
  post: PublicPost;
13
13
  }
14
14
 
@@ -16,7 +16,7 @@ import { ProfileEventRelationship } from './ProfileEventRelationship';
16
16
  import { useTranslation } from 'react-i18next';
17
17
 
18
18
  import { ParticipantsCard } from '../../index';
19
- interface CardEventProps {
19
+ export interface CardEventProps {
20
20
  post: PublicPost;
21
21
  showEventDate?: boolean;
22
22
  }
@@ -76,7 +76,7 @@ import {
76
76
  } from '../../index';
77
77
  import { ReportProfileOrPostModal } from '../../../profile/index';
78
78
  import { OpenpeepsMarkdown } from '../../../markdown/index';
79
- interface FullEventProps {
79
+ export interface FullEventProps {
80
80
  post: PublicPost;
81
81
  occurrence?: string;
82
82
  }
@@ -9,7 +9,7 @@ import { useOpenpeeps } from '@openpeepshq/react';
9
9
  import { ThemedText } from '../../../ui/themed-text';
10
10
  import { useTranslation } from 'react-i18next';
11
11
 
12
- interface ProfileEventRelationshipProps {
12
+ export interface ProfileEventRelationshipProps {
13
13
  post: PublicPost;
14
14
  }
15
15