@openpeepshq/rn-components 0.15.0 → 0.16.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 +3 -3
- package/src/components/icons/index.ts +2 -0
- package/src/components/navigation/nativeRouter.tsx +13 -3
- package/src/components/notifications/NotificationHeaderActions.test.tsx +285 -0
- package/src/components/notifications/NotificationHeaderActions.tsx +91 -4
- package/src/components/notifications/NotificationsList.test.tsx +109 -0
- package/src/components/notifications/NotificationsList.tsx +13 -3
- package/src/components/notifications/types/Reaction.tsx +6 -2
- package/src/components/post/pieces/PostActions.test.tsx +244 -0
- package/src/components/post/pieces/PostActions.tsx +74 -49
- package/src/components/post/pieces/ReactionPicker.test.tsx +184 -0
- package/src/components/post/pieces/ReactionPicker.tsx +58 -0
- package/src/components/post/pieces/index.ts +1 -0
- package/src/components/post/pieces/modals/ReactionsModal.tsx +1 -1
- package/src/pages/Notifications.tsx +3 -1
- package/src/pages/Welcome.test.tsx +166 -0
- package/src/pages/Welcome.tsx +50 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openpeepshq/rn-components",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.16.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",
|
|
@@ -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/common": "^0.
|
|
146
|
-
"@openpeepshq/react": "^0.
|
|
145
|
+
"@openpeepshq/common": "^0.11.0",
|
|
146
|
+
"@openpeepshq/react": "^0.17.0",
|
|
147
147
|
"@openpeepshq/fetch-client": "^0.2.1"
|
|
148
148
|
},
|
|
149
149
|
"devDependencies": {
|
|
@@ -95,6 +95,7 @@ import {
|
|
|
95
95
|
File,
|
|
96
96
|
Circle,
|
|
97
97
|
Settings2,
|
|
98
|
+
SlidersHorizontal,
|
|
98
99
|
MessageSquareOff,
|
|
99
100
|
MessageSquarePlus,
|
|
100
101
|
CircleSlash2,
|
|
@@ -248,6 +249,7 @@ export const FileIcon = iconWithClassName(File);
|
|
|
248
249
|
export const ScreenShareIcon = iconWithClassName(ScreenShare);
|
|
249
250
|
export const CircleIcon = iconWithClassName(Circle);
|
|
250
251
|
export const Settings2Icon = iconWithClassName(Settings2);
|
|
252
|
+
export const SlidersHorizontalIcon = iconWithClassName(SlidersHorizontal);
|
|
251
253
|
export const MessageSquareOffIcon = iconWithClassName(MessageSquareOff);
|
|
252
254
|
export const MessageSquarePlusIcon = iconWithClassName(MessageSquarePlus);
|
|
253
255
|
export const CircleSlash2Icon = iconWithClassName(CircleSlash2);
|
|
@@ -230,7 +230,9 @@ export const navigateToTarget = (target: NavTarget) => {
|
|
|
230
230
|
}
|
|
231
231
|
break;
|
|
232
232
|
default:
|
|
233
|
-
|
|
233
|
+
// Exhaustiveness guard (mirrors the web navigator's): adding a
|
|
234
|
+
// NavTarget without a native mapping fails the typecheck here.
|
|
235
|
+
throw target satisfies never;
|
|
234
236
|
}
|
|
235
237
|
};
|
|
236
238
|
|
|
@@ -241,10 +243,18 @@ export const useNativeRouterAdapter = (): RouterAdapter =>
|
|
|
241
243
|
searchParams: new URLSearchParams(),
|
|
242
244
|
// Native has no URL bar to keep in sync, so there is no query to write.
|
|
243
245
|
setSearchParams: () => {},
|
|
244
|
-
hrefOf: () =>
|
|
246
|
+
hrefOf: (target: NavTarget): string => {
|
|
247
|
+
throw new Error(
|
|
248
|
+
`hrefOf('${target.type}') has no native mapping — native targets navigate directly (navigateToTarget), they have no hrefs.`
|
|
249
|
+
);
|
|
250
|
+
},
|
|
245
251
|
match: () => null,
|
|
246
252
|
navigate: (target) => {
|
|
247
|
-
if (typeof target === 'string')
|
|
253
|
+
if (typeof target === 'string') {
|
|
254
|
+
throw new Error(
|
|
255
|
+
'navigate(string) has no native mapping — pass a NavTarget so navigateToTarget can route it.'
|
|
256
|
+
);
|
|
257
|
+
}
|
|
248
258
|
navigateToTarget(target);
|
|
249
259
|
},
|
|
250
260
|
back: () => {
|
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Regression tests for the RN notification type-filter sheet (issue #354).
|
|
3
|
+
*
|
|
4
|
+
* The web `NotificationHeaderActions` already pins its filter menu; the RN
|
|
5
|
+
* sheet is the one rendering layer the shared-hook test cannot see (it renders
|
|
6
|
+
* rows from the `useNotificationFeedFilter` data and drives `toggle`/`showAll`
|
|
7
|
+
* from row presses). These lock in the RN-only wiring: one checkbox row per
|
|
8
|
+
* type with `accessibilityState.checked` from `isHidden`, cumulative toggles,
|
|
9
|
+
* and the conditional "Show all types" footer that clears the filter.
|
|
10
|
+
*
|
|
11
|
+
* External imports are mocked (node jest env, no native modules) — the sheet
|
|
12
|
+
* primitive renders its `data` rows inline so they are inspectable.
|
|
13
|
+
*/
|
|
14
|
+
import React from 'react';
|
|
15
|
+
import ReactTestRenderer from 'react-test-renderer';
|
|
16
|
+
import { NotificationHeaderActions } from './NotificationHeaderActions';
|
|
17
|
+
|
|
18
|
+
// --- shared mutable state (mock* prefix is hoisting-safe) -------------------
|
|
19
|
+
const TYPES = [{ type: 'repost' }, { type: 'reaction' }, { type: 'pollVote' }];
|
|
20
|
+
let mockHidden: Set<string> = new Set();
|
|
21
|
+
const mockToggle = jest.fn(async (type: string) => {
|
|
22
|
+
if (mockHidden.has(type)) mockHidden.delete(type);
|
|
23
|
+
else mockHidden.add(type);
|
|
24
|
+
});
|
|
25
|
+
const mockShowAll = jest.fn(async () => {
|
|
26
|
+
mockHidden = new Set();
|
|
27
|
+
});
|
|
28
|
+
const mockMarkAllSeen = jest.fn(async (_path?: unknown, _q?: unknown) => {});
|
|
29
|
+
|
|
30
|
+
jest.mock('react-native', () => {
|
|
31
|
+
const React = require('react');
|
|
32
|
+
const make = (tag: string) => (props: { children?: React.ReactNode }) =>
|
|
33
|
+
React.createElement(tag, props, props.children);
|
|
34
|
+
return {
|
|
35
|
+
View: make('View'),
|
|
36
|
+
Pressable: make('Pressable'),
|
|
37
|
+
Text: make('Text'),
|
|
38
|
+
};
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
jest.mock('react-i18next', () => ({
|
|
42
|
+
useTranslation: () => ({
|
|
43
|
+
t: (key: string, opts?: { defaultValue?: string }) =>
|
|
44
|
+
opts?.defaultValue ?? key,
|
|
45
|
+
}),
|
|
46
|
+
}));
|
|
47
|
+
|
|
48
|
+
jest.mock('react-native-toast-message', () => ({
|
|
49
|
+
__esModule: true,
|
|
50
|
+
default: { show: jest.fn() },
|
|
51
|
+
}));
|
|
52
|
+
|
|
53
|
+
jest.mock('@react-navigation/native', () => ({
|
|
54
|
+
useNavigation: () => ({ navigate: jest.fn() }),
|
|
55
|
+
}));
|
|
56
|
+
|
|
57
|
+
jest.mock('@openpeepshq/react', () => ({
|
|
58
|
+
useOpenpeeps: () => ({
|
|
59
|
+
openpeepsApi: {
|
|
60
|
+
// Returns the endpoint function directly (not an async wrapper) so the
|
|
61
|
+
// test can assert the args `markAllRead` forwards to it — the wiring
|
|
62
|
+
// that encodes the approved mark-all split (visible types only).
|
|
63
|
+
markAllNotificationsAsSeenAction: () => () => mockMarkAllSeen,
|
|
64
|
+
},
|
|
65
|
+
queryClient: {},
|
|
66
|
+
}),
|
|
67
|
+
markCachedNotificationsSeen: () => {},
|
|
68
|
+
useNotificationFeedFilter: () => ({
|
|
69
|
+
types: TYPES,
|
|
70
|
+
hiddenTypes: mockHidden,
|
|
71
|
+
isHidden: (type: string) => mockHidden.has(type),
|
|
72
|
+
toggle: mockToggle,
|
|
73
|
+
showAll: mockShowAll,
|
|
74
|
+
hasFilter: mockHidden.size > 0,
|
|
75
|
+
excludeTypes: mockHidden.size
|
|
76
|
+
? [...mockHidden].sort().join(',')
|
|
77
|
+
: undefined,
|
|
78
|
+
}),
|
|
79
|
+
}));
|
|
80
|
+
|
|
81
|
+
jest.mock('../icons/index', () => {
|
|
82
|
+
const React = require('react');
|
|
83
|
+
const icon = (name: string) => () => React.createElement(name);
|
|
84
|
+
return {
|
|
85
|
+
CheckCheckIcon: icon('CheckCheckIcon'),
|
|
86
|
+
Settings2Icon: icon('Settings2Icon'),
|
|
87
|
+
SlidersHorizontalIcon: icon('SlidersHorizontalIcon'),
|
|
88
|
+
};
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
jest.mock('../ui/button', () => {
|
|
92
|
+
const React = require('react');
|
|
93
|
+
return {
|
|
94
|
+
Button: (props: { children?: React.ReactNode }) =>
|
|
95
|
+
React.createElement('Button', props, props.children),
|
|
96
|
+
};
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
jest.mock('../ui/checkbox', () => {
|
|
100
|
+
const React = require('react');
|
|
101
|
+
return {
|
|
102
|
+
Checkbox: (props: Record<string, unknown>) =>
|
|
103
|
+
React.createElement('Checkbox', props),
|
|
104
|
+
};
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
jest.mock('../ui/themed-text', () => {
|
|
108
|
+
const React = require('react');
|
|
109
|
+
return {
|
|
110
|
+
ThemedText: (props: { children?: React.ReactNode }) =>
|
|
111
|
+
React.createElement('ThemedText', props, props.children),
|
|
112
|
+
};
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
jest.mock('../ui/bottom-sheet', () => {
|
|
116
|
+
const React = require('react');
|
|
117
|
+
const passThrough =
|
|
118
|
+
(tag: string) => (props: { children?: React.ReactNode }) =>
|
|
119
|
+
React.createElement(tag, props, props.children);
|
|
120
|
+
return {
|
|
121
|
+
BottomSheet: passThrough('BottomSheet'),
|
|
122
|
+
BottomSheetContent: passThrough('BottomSheetContent'),
|
|
123
|
+
BottomSheetHeader: passThrough('BottomSheetHeader'),
|
|
124
|
+
// Render `data` rows inline (plus the footer) so the sheet's contents are
|
|
125
|
+
// inspectable without a native ScrollView/FlatList.
|
|
126
|
+
BottomSheetFlatList: (props: {
|
|
127
|
+
data?: Array<{ type: string }>;
|
|
128
|
+
renderItem: (p: {
|
|
129
|
+
item: { type: string };
|
|
130
|
+
index: number;
|
|
131
|
+
}) => React.ReactNode;
|
|
132
|
+
ListFooterComponent?: React.ReactNode;
|
|
133
|
+
}) =>
|
|
134
|
+
React.createElement(
|
|
135
|
+
'BottomSheetFlatList',
|
|
136
|
+
null,
|
|
137
|
+
(props.data ?? []).map((item, index) =>
|
|
138
|
+
React.createElement(
|
|
139
|
+
'View',
|
|
140
|
+
{ key: index },
|
|
141
|
+
props.renderItem({ item, index })
|
|
142
|
+
)
|
|
143
|
+
),
|
|
144
|
+
props.ListFooterComponent
|
|
145
|
+
),
|
|
146
|
+
useBottomSheet: () => ({
|
|
147
|
+
ref: { current: { present: jest.fn(), dismiss: jest.fn() } },
|
|
148
|
+
open: jest.fn(),
|
|
149
|
+
close: jest.fn(),
|
|
150
|
+
}),
|
|
151
|
+
};
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
const render = () => {
|
|
155
|
+
let tree!: ReactTestRenderer.ReactTestRenderer;
|
|
156
|
+
ReactTestRenderer.act(() => {
|
|
157
|
+
tree = ReactTestRenderer.create(
|
|
158
|
+
React.createElement(NotificationHeaderActions)
|
|
159
|
+
);
|
|
160
|
+
});
|
|
161
|
+
return tree;
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
// The row Pressables carry `accessibilityRole="checkbox"`; the header Buttons
|
|
165
|
+
// and the "Show all types" footer do not, so this isolates the type rows.
|
|
166
|
+
const rows = (tree: ReactTestRenderer.ReactTestRenderer) =>
|
|
167
|
+
tree.root
|
|
168
|
+
.findAllByType('Pressable')
|
|
169
|
+
.filter((p) => p.props.accessibilityRole === 'checkbox');
|
|
170
|
+
const showAllRow = (tree: ReactTestRenderer.ReactTestRenderer) =>
|
|
171
|
+
tree.root
|
|
172
|
+
.findAllByType('Pressable')
|
|
173
|
+
.find((p) => p.props.accessibilityRole !== 'checkbox');
|
|
174
|
+
// The header's first Button is "Mark all as read" (its onPress drives
|
|
175
|
+
// markAllRead); the i18n mock resolves its label to the raw key.
|
|
176
|
+
const markAllReadButton = (tree: ReactTestRenderer.ReactTestRenderer) =>
|
|
177
|
+
tree.root
|
|
178
|
+
.findAllByType('Button')
|
|
179
|
+
.find(
|
|
180
|
+
(b) =>
|
|
181
|
+
b.props.accessibilityLabel ===
|
|
182
|
+
'settings.notifications.feedPreferences.markAllRead'
|
|
183
|
+
);
|
|
184
|
+
|
|
185
|
+
describe('NotificationHeaderActions (RN filter sheet)', () => {
|
|
186
|
+
beforeEach(() => {
|
|
187
|
+
mockHidden = new Set();
|
|
188
|
+
mockToggle.mockClear();
|
|
189
|
+
mockShowAll.mockClear();
|
|
190
|
+
mockMarkAllSeen.mockClear();
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
it('pins one checkbox row per type with checked state from isHidden', () => {
|
|
194
|
+
mockHidden = new Set(['reaction']);
|
|
195
|
+
const tree = render();
|
|
196
|
+
// repost, reaction (hidden), pollVote
|
|
197
|
+
expect(rows(tree).map((r) => r.props.accessibilityState.checked)).toEqual([
|
|
198
|
+
true,
|
|
199
|
+
false,
|
|
200
|
+
true,
|
|
201
|
+
]);
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
it('applies cumulative toggles, each flipping only its own row', () => {
|
|
205
|
+
const tree = render();
|
|
206
|
+
const first = rows(tree);
|
|
207
|
+
ReactTestRenderer.act(() => {
|
|
208
|
+
first[0].props.onPress();
|
|
209
|
+
});
|
|
210
|
+
expect(mockToggle).toHaveBeenCalledWith('repost');
|
|
211
|
+
tree.unmount();
|
|
212
|
+
|
|
213
|
+
// Re-render against the updated hidden set: repost is now hidden.
|
|
214
|
+
const tree2 = render();
|
|
215
|
+
expect(rows(tree2).map((r) => r.props.accessibilityState.checked)).toEqual([
|
|
216
|
+
false,
|
|
217
|
+
true,
|
|
218
|
+
true,
|
|
219
|
+
]);
|
|
220
|
+
ReactTestRenderer.act(() => {
|
|
221
|
+
rows(tree2)[1].props.onPress();
|
|
222
|
+
});
|
|
223
|
+
expect(mockToggle).toHaveBeenLastCalledWith('reaction');
|
|
224
|
+
tree2.unmount();
|
|
225
|
+
|
|
226
|
+
const tree3 = render();
|
|
227
|
+
expect(rows(tree3).map((r) => r.props.accessibilityState.checked)).toEqual([
|
|
228
|
+
false,
|
|
229
|
+
false,
|
|
230
|
+
true,
|
|
231
|
+
]);
|
|
232
|
+
tree3.unmount();
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
it('omits "Show all types" while nothing is hidden', () => {
|
|
236
|
+
const tree = render();
|
|
237
|
+
expect(showAllRow(tree)).toBeUndefined();
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
it('shows "Show all types" when filtered, and clearing unhides everything', () => {
|
|
241
|
+
mockHidden = new Set(['repost', 'pollVote']);
|
|
242
|
+
const tree = render();
|
|
243
|
+
const footer = showAllRow(tree);
|
|
244
|
+
expect(footer).toBeDefined();
|
|
245
|
+
|
|
246
|
+
ReactTestRenderer.act(() => {
|
|
247
|
+
footer!.props.onPress();
|
|
248
|
+
});
|
|
249
|
+
expect(mockShowAll).toHaveBeenCalled();
|
|
250
|
+
tree.unmount();
|
|
251
|
+
|
|
252
|
+
const tree2 = render();
|
|
253
|
+
expect(showAllRow(tree2)).toBeUndefined();
|
|
254
|
+
expect(rows(tree2).map((r) => r.props.accessibilityState.checked)).toEqual([
|
|
255
|
+
true,
|
|
256
|
+
true,
|
|
257
|
+
true,
|
|
258
|
+
]);
|
|
259
|
+
tree2.unmount();
|
|
260
|
+
});
|
|
261
|
+
|
|
262
|
+
it('mark-all-read passes the active filter as excludeTypes', () => {
|
|
263
|
+
mockHidden = new Set(['repost', 'reaction']);
|
|
264
|
+
const tree = render();
|
|
265
|
+
ReactTestRenderer.act(() => {
|
|
266
|
+
markAllReadButton(tree)!.props.onPress();
|
|
267
|
+
});
|
|
268
|
+
expect(mockMarkAllSeen).toHaveBeenCalledTimes(1);
|
|
269
|
+
// Sorted + comma-joined, exactly as the feed query and server schema expect.
|
|
270
|
+
expect(mockMarkAllSeen).toHaveBeenCalledWith(undefined, {
|
|
271
|
+
excludeTypes: 'reaction,repost',
|
|
272
|
+
});
|
|
273
|
+
tree.unmount();
|
|
274
|
+
});
|
|
275
|
+
|
|
276
|
+
it('mark-all-read passes no query params when nothing is filtered', () => {
|
|
277
|
+
const tree = render();
|
|
278
|
+
ReactTestRenderer.act(() => {
|
|
279
|
+
markAllReadButton(tree)!.props.onPress();
|
|
280
|
+
});
|
|
281
|
+
expect(mockMarkAllSeen).toHaveBeenCalledTimes(1);
|
|
282
|
+
expect(mockMarkAllSeen).toHaveBeenCalledWith(undefined, undefined);
|
|
283
|
+
tree.unmount();
|
|
284
|
+
});
|
|
285
|
+
});
|
|
@@ -1,25 +1,51 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { View } from 'react-native';
|
|
2
|
+
import { Pressable, View } from 'react-native';
|
|
3
3
|
import { useTranslation } from 'react-i18next';
|
|
4
4
|
import Toast from 'react-native-toast-message';
|
|
5
5
|
import { useNavigation } from '@react-navigation/native';
|
|
6
6
|
import { NativeStackNavigationProp } from '@react-navigation/native-stack';
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
7
|
+
import type { NotificationType } from '@openpeepshq/common';
|
|
8
|
+
import {
|
|
9
|
+
markCachedNotificationsSeen,
|
|
10
|
+
useNotificationFeedFilter,
|
|
11
|
+
useOpenpeeps,
|
|
12
|
+
} from '@openpeepshq/react';
|
|
13
|
+
import {
|
|
14
|
+
CheckCheckIcon,
|
|
15
|
+
Settings2Icon,
|
|
16
|
+
SlidersHorizontalIcon,
|
|
17
|
+
} from '../icons/index';
|
|
9
18
|
import { MainStackParamList } from '../navigation/types/index';
|
|
10
19
|
import { Button } from '../ui/button';
|
|
20
|
+
import {
|
|
21
|
+
BottomSheet,
|
|
22
|
+
BottomSheetContent,
|
|
23
|
+
BottomSheetFlatList,
|
|
24
|
+
BottomSheetHeader,
|
|
25
|
+
useBottomSheet,
|
|
26
|
+
} from '../ui/bottom-sheet';
|
|
27
|
+
import { Checkbox } from '../ui/checkbox';
|
|
28
|
+
import { ThemedText } from '../ui/themed-text';
|
|
11
29
|
|
|
12
30
|
export const NotificationHeaderActions = () => {
|
|
13
31
|
const { t } = useTranslation();
|
|
14
32
|
const { openpeepsApi, queryClient } = useOpenpeeps();
|
|
15
33
|
const navigation =
|
|
16
34
|
useNavigation<NativeStackNavigationProp<MainStackParamList>>();
|
|
35
|
+
const filter = useNotificationFeedFilter();
|
|
36
|
+
const filterSheet = useBottomSheet();
|
|
17
37
|
const markAllNotificationsAsSeen =
|
|
18
38
|
openpeepsApi.markAllNotificationsAsSeenAction()();
|
|
19
39
|
|
|
20
40
|
const markAllRead = async () => {
|
|
21
41
|
try {
|
|
22
|
-
|
|
42
|
+
// Cover only what is visible under the active filter; hidden types are
|
|
43
|
+
// left untouched (the feed never shows them, so they can't be "read").
|
|
44
|
+
// The first arg is the (absent) path-params slot.
|
|
45
|
+
await markAllNotificationsAsSeen(
|
|
46
|
+
undefined,
|
|
47
|
+
filter.hasFilter ? { excludeTypes: filter.excludeTypes } : undefined
|
|
48
|
+
);
|
|
23
49
|
markCachedNotificationsSeen(queryClient);
|
|
24
50
|
Toast.show({
|
|
25
51
|
type: 'success',
|
|
@@ -30,6 +56,8 @@ export const NotificationHeaderActions = () => {
|
|
|
30
56
|
}
|
|
31
57
|
};
|
|
32
58
|
|
|
59
|
+
const filterTitle = t('notification.filter.title');
|
|
60
|
+
|
|
33
61
|
return (
|
|
34
62
|
<View className="flex-row gap-x-2">
|
|
35
63
|
<Button
|
|
@@ -42,6 +70,14 @@ export const NotificationHeaderActions = () => {
|
|
|
42
70
|
>
|
|
43
71
|
<CheckCheckIcon size={18} className="text-foreground" />
|
|
44
72
|
</Button>
|
|
73
|
+
<Button
|
|
74
|
+
size="icon"
|
|
75
|
+
variant="outline"
|
|
76
|
+
accessibilityLabel={filterTitle}
|
|
77
|
+
onPress={filterSheet.open}
|
|
78
|
+
>
|
|
79
|
+
<SlidersHorizontalIcon size={18} className="text-foreground" />
|
|
80
|
+
</Button>
|
|
45
81
|
<Button
|
|
46
82
|
size="icon"
|
|
47
83
|
variant="outline"
|
|
@@ -50,6 +86,57 @@ export const NotificationHeaderActions = () => {
|
|
|
50
86
|
>
|
|
51
87
|
<Settings2Icon size={18} className="text-foreground" />
|
|
52
88
|
</Button>
|
|
89
|
+
|
|
90
|
+
<BottomSheet>
|
|
91
|
+
<BottomSheetContent ref={filterSheet.ref} snapPoints={['70%']}>
|
|
92
|
+
<BottomSheetHeader className="border-b-0">
|
|
93
|
+
<ThemedText className="text-base font-semibold">
|
|
94
|
+
{filterTitle}
|
|
95
|
+
</ThemedText>
|
|
96
|
+
</BottomSheetHeader>
|
|
97
|
+
<BottomSheetFlatList
|
|
98
|
+
className="py-0"
|
|
99
|
+
contentContainerStyle={{ paddingVertical: 0 }}
|
|
100
|
+
data={filter.types}
|
|
101
|
+
keyExtractor={(nt) => (nt as NotificationType).type}
|
|
102
|
+
renderItem={({ item }) => {
|
|
103
|
+
const nt = item as NotificationType;
|
|
104
|
+
return (
|
|
105
|
+
<Pressable
|
|
106
|
+
accessibilityRole="checkbox"
|
|
107
|
+
accessibilityState={{ checked: !filter.isHidden(nt.type) }}
|
|
108
|
+
onPress={() => void filter.toggle(nt.type)}
|
|
109
|
+
className="flex-row items-center gap-2 py-2"
|
|
110
|
+
>
|
|
111
|
+
<Checkbox
|
|
112
|
+
checked={!filter.isHidden(nt.type)}
|
|
113
|
+
// The row is the toggle; the checkbox is display-only.
|
|
114
|
+
pointerEvents="none"
|
|
115
|
+
onCheckedChange={() => {}}
|
|
116
|
+
/>
|
|
117
|
+
<ThemedText className="flex-1">
|
|
118
|
+
{t(`settings.notifications.types.${nt.type}.label`, {
|
|
119
|
+
defaultValue: nt.type,
|
|
120
|
+
})}
|
|
121
|
+
</ThemedText>
|
|
122
|
+
</Pressable>
|
|
123
|
+
);
|
|
124
|
+
}}
|
|
125
|
+
ListFooterComponent={
|
|
126
|
+
filter.hasFilter ? (
|
|
127
|
+
<Pressable
|
|
128
|
+
onPress={() => void filter.showAll()}
|
|
129
|
+
className="flex-row items-center py-2"
|
|
130
|
+
>
|
|
131
|
+
<ThemedText className="text-primary">
|
|
132
|
+
{t('notification.filter.showAll')}
|
|
133
|
+
</ThemedText>
|
|
134
|
+
</Pressable>
|
|
135
|
+
) : null
|
|
136
|
+
}
|
|
137
|
+
/>
|
|
138
|
+
</BottomSheetContent>
|
|
139
|
+
</BottomSheet>
|
|
53
140
|
</View>
|
|
54
141
|
);
|
|
55
142
|
};
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pins the RN `NotificationsList` empty-state copy (issue #354, round-8
|
|
3
|
+
* suggestion 2): with an active type filter the empty feed shows the
|
|
4
|
+
* `notification.emptyFiltered` copy, otherwise `notification.empty`. The feed
|
|
5
|
+
* filters server-side via `excludeTypes`, so both branches are reachable from
|
|
6
|
+
* the client.
|
|
7
|
+
*/
|
|
8
|
+
import React from 'react';
|
|
9
|
+
import ReactTestRenderer from 'react-test-renderer';
|
|
10
|
+
import { NotificationsList } from './NotificationsList';
|
|
11
|
+
|
|
12
|
+
let mockHasFilter = false;
|
|
13
|
+
let mockExcludeTypes: string | undefined;
|
|
14
|
+
const mockEmptyCalls: Array<{ copyKey: string }> = [];
|
|
15
|
+
|
|
16
|
+
jest.mock('react-native', () => ({
|
|
17
|
+
ScrollView: (props: { children?: React.ReactNode }) =>
|
|
18
|
+
React.createElement('ScrollView', null, props.children),
|
|
19
|
+
RefreshControl: (props: Record<string, unknown>) =>
|
|
20
|
+
React.createElement('RefreshControl', props),
|
|
21
|
+
ActivityIndicator: () => null,
|
|
22
|
+
}));
|
|
23
|
+
|
|
24
|
+
jest.mock('@react-navigation/native', () => ({
|
|
25
|
+
useFocusEffect: () => {},
|
|
26
|
+
}));
|
|
27
|
+
|
|
28
|
+
jest.mock('@openpeepshq/react', () => ({
|
|
29
|
+
useOpenpeeps: () => ({
|
|
30
|
+
openpeepsApi: {
|
|
31
|
+
useCurrentProfileNotifications: () => ({
|
|
32
|
+
data: { pages: [] },
|
|
33
|
+
isLoading: false,
|
|
34
|
+
refetch: async () => {},
|
|
35
|
+
}),
|
|
36
|
+
},
|
|
37
|
+
}),
|
|
38
|
+
useNotificationFeedFilter: () => ({
|
|
39
|
+
hasFilter: mockHasFilter,
|
|
40
|
+
excludeTypes: mockExcludeTypes,
|
|
41
|
+
}),
|
|
42
|
+
}));
|
|
43
|
+
|
|
44
|
+
jest.mock('../../lib/utils', () => ({
|
|
45
|
+
handleScroll: () => {},
|
|
46
|
+
}));
|
|
47
|
+
|
|
48
|
+
jest.mock('../custom/common/empty-state-container', () => {
|
|
49
|
+
// Rendered as a component type (not a host tag) so the props actually reach
|
|
50
|
+
// the mock body, which records the `copyKey` the list selected.
|
|
51
|
+
const MockEmpty = (props: { copyKey: string; defaultValue?: string }) => {
|
|
52
|
+
mockEmptyCalls.push(props);
|
|
53
|
+
return React.createElement('EmptyStateContainer', null, props.copyKey);
|
|
54
|
+
};
|
|
55
|
+
return { EmptyStateContainer: MockEmpty };
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
jest.mock('./NotificationItem', () => ({
|
|
59
|
+
NotificationItem: () => null,
|
|
60
|
+
}));
|
|
61
|
+
|
|
62
|
+
// An empty feed query: no items, not loading, no further pages.
|
|
63
|
+
const emptyQuery = {
|
|
64
|
+
data: { pages: [] },
|
|
65
|
+
isLoading: false,
|
|
66
|
+
isFetchingNextPage: false,
|
|
67
|
+
hasNextPage: false,
|
|
68
|
+
refetch: async () => {},
|
|
69
|
+
fetchNextPage: async () => {},
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
describe('NotificationsList (RN empty state)', () => {
|
|
73
|
+
beforeEach(() => {
|
|
74
|
+
mockHasFilter = false;
|
|
75
|
+
mockExcludeTypes = undefined;
|
|
76
|
+
mockEmptyCalls.length = 0;
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
const render = () => {
|
|
80
|
+
let tree!: ReactTestRenderer.ReactTestRenderer;
|
|
81
|
+
ReactTestRenderer.act(() => {
|
|
82
|
+
tree = ReactTestRenderer.create(
|
|
83
|
+
React.createElement(NotificationsList, {
|
|
84
|
+
query: emptyQuery as never,
|
|
85
|
+
isNotificationFeed: false,
|
|
86
|
+
})
|
|
87
|
+
);
|
|
88
|
+
});
|
|
89
|
+
return tree;
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
it('shows the plain empty copy when nothing is filtered', () => {
|
|
93
|
+
const tree = render();
|
|
94
|
+
expect(mockEmptyCalls).toEqual([
|
|
95
|
+
expect.objectContaining({ copyKey: 'notification.empty' }),
|
|
96
|
+
]);
|
|
97
|
+
tree.unmount();
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it('shows the filtered empty copy when a type filter is active', () => {
|
|
101
|
+
mockHasFilter = true;
|
|
102
|
+
mockExcludeTypes = 'repost';
|
|
103
|
+
const tree = render();
|
|
104
|
+
expect(mockEmptyCalls).toEqual([
|
|
105
|
+
expect.objectContaining({ copyKey: 'notification.emptyFiltered' }),
|
|
106
|
+
]);
|
|
107
|
+
tree.unmount();
|
|
108
|
+
});
|
|
109
|
+
});
|
|
@@ -2,7 +2,7 @@ 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
|
+
import { useNotificationFeedFilter, useOpenpeeps } from '@openpeepshq/react';
|
|
6
6
|
import { handleScroll } from '../../lib/utils';
|
|
7
7
|
import { EmptyStateContainer } from '../custom/common/empty-state-container';
|
|
8
8
|
import { NotificationItem } from './NotificationItem';
|
|
@@ -24,8 +24,10 @@ export const NotificationsList = ({
|
|
|
24
24
|
onRefresh,
|
|
25
25
|
}: NotificationsListProps) => {
|
|
26
26
|
const { openpeepsApi } = useOpenpeeps();
|
|
27
|
+
const { hasFilter, excludeTypes } = useNotificationFeedFilter();
|
|
27
28
|
const internalQuery = openpeepsApi.useCurrentProfileNotifications({
|
|
28
29
|
limit: pageSize,
|
|
30
|
+
excludeTypes,
|
|
29
31
|
});
|
|
30
32
|
const query = externalQuery ?? internalQuery;
|
|
31
33
|
|
|
@@ -33,6 +35,8 @@ export const NotificationsList = ({
|
|
|
33
35
|
const refetchRef = React.useRef(query.refetch);
|
|
34
36
|
refetchRef.current = query.refetch;
|
|
35
37
|
|
|
38
|
+
// Hidden types are excluded server-side (`excludeTypes`), so scroll-
|
|
39
|
+
// triggered pagination pages through visible items only.
|
|
36
40
|
const allNotifications = React.useMemo(() => {
|
|
37
41
|
if (!query.data?.pages) {
|
|
38
42
|
return [];
|
|
@@ -74,8 +78,14 @@ export const NotificationsList = ({
|
|
|
74
78
|
) : (
|
|
75
79
|
<EmptyStateContainer
|
|
76
80
|
type="notifications"
|
|
77
|
-
copyKey=
|
|
78
|
-
|
|
81
|
+
copyKey={
|
|
82
|
+
hasFilter ? 'notification.emptyFiltered' : 'notification.empty'
|
|
83
|
+
}
|
|
84
|
+
defaultValue={
|
|
85
|
+
hasFilter
|
|
86
|
+
? 'No notifications of the selected types'
|
|
87
|
+
: 'No notifications'
|
|
88
|
+
}
|
|
79
89
|
/>
|
|
80
90
|
)}
|
|
81
91
|
</>
|
|
@@ -2,7 +2,7 @@ import { Pressable, View } from 'react-native';
|
|
|
2
2
|
import React from 'react';
|
|
3
3
|
import { ThemedText } from '../../ui/themed-text';
|
|
4
4
|
import { NotificationWrapper } from '../NotificationWrapper';
|
|
5
|
-
import { PublicNotification } from '@openpeepshq/common';
|
|
5
|
+
import { PublicNotification, AP_LIKE_REACTION } from '@openpeepshq/common';
|
|
6
6
|
import { profileName } from '../../../lib/utils';
|
|
7
7
|
import { useTranslation } from 'react-i18next';
|
|
8
8
|
import { MainStackParamList } from '../../navigation/types/index';
|
|
@@ -19,6 +19,10 @@ export const Reaction: React.FC<NotificationTypeProps> = ({ notification }) => {
|
|
|
19
19
|
const { t } = useTranslation();
|
|
20
20
|
const navigation =
|
|
21
21
|
useNavigation<NativeStackNavigationProp<MainStackParamList>>();
|
|
22
|
+
// Render the stored reaction (parity with the web TypedNotification); fall
|
|
23
|
+
// back to the legacy plain like for old notifications without a reaction.
|
|
24
|
+
const reaction =
|
|
25
|
+
(notification.data as { reaction?: string })?.reaction ?? AP_LIKE_REACTION;
|
|
22
26
|
|
|
23
27
|
return (
|
|
24
28
|
<NotificationWrapper
|
|
@@ -34,7 +38,7 @@ export const Reaction: React.FC<NotificationTypeProps> = ({ notification }) => {
|
|
|
34
38
|
>
|
|
35
39
|
<View className="flex w-full items-center justify-between">
|
|
36
40
|
<View className="mb-2 flex flex-row items-center gap-2 font-semibold flex-wrap">
|
|
37
|
-
<ThemedText
|
|
41
|
+
<ThemedText>{reaction}</ThemedText>
|
|
38
42
|
<ThemedText>
|
|
39
43
|
{t('notification.reaction.text', {
|
|
40
44
|
profileName: profileName(profile),
|