@oxyhq/services 27.0.0 → 27.1.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/lib/commonjs/index.js +41 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/ui/components/FollowButton.js +3 -5
- package/lib/commonjs/ui/components/FollowButton.js.map +1 -1
- package/lib/commonjs/ui/components/FollowTargetButton.js +323 -0
- package/lib/commonjs/ui/components/FollowTargetButton.js.map +1 -0
- package/lib/commonjs/ui/hooks/useFollowTarget.js +147 -0
- package/lib/commonjs/ui/hooks/useFollowTarget.js.map +1 -0
- package/lib/commonjs/ui/screens/AccountMembersScreen.js +49 -6
- package/lib/commonjs/ui/screens/AccountMembersScreen.js.map +1 -1
- package/lib/commonjs/ui/stores/followTargetStore.js +113 -0
- package/lib/commonjs/ui/stores/followTargetStore.js.map +1 -0
- package/lib/commonjs/ui/stores/resetSessionScopedStores.js +2 -0
- package/lib/commonjs/ui/stores/resetSessionScopedStores.js.map +1 -1
- package/lib/module/index.js +8 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/ui/components/FollowButton.js +3 -5
- package/lib/module/ui/components/FollowButton.js.map +1 -1
- package/lib/module/ui/components/FollowTargetButton.js +317 -0
- package/lib/module/ui/components/FollowTargetButton.js.map +1 -0
- package/lib/module/ui/hooks/useFollowTarget.js +143 -0
- package/lib/module/ui/hooks/useFollowTarget.js.map +1 -0
- package/lib/module/ui/screens/AccountMembersScreen.js +49 -6
- package/lib/module/ui/screens/AccountMembersScreen.js.map +1 -1
- package/lib/module/ui/stores/followTargetStore.js +107 -0
- package/lib/module/ui/stores/followTargetStore.js.map +1 -0
- package/lib/module/ui/stores/resetSessionScopedStores.js +2 -0
- package/lib/module/ui/stores/resetSessionScopedStores.js.map +1 -1
- package/lib/typescript/commonjs/index.d.ts +5 -0
- package/lib/typescript/commonjs/index.d.ts.map +1 -1
- package/lib/typescript/commonjs/ui/components/FollowButton.d.ts.map +1 -1
- package/lib/typescript/commonjs/ui/components/FollowTargetButton.d.ts +130 -0
- package/lib/typescript/commonjs/ui/components/FollowTargetButton.d.ts.map +1 -0
- package/lib/typescript/commonjs/ui/hooks/useFollowTarget.d.ts +50 -0
- package/lib/typescript/commonjs/ui/hooks/useFollowTarget.d.ts.map +1 -0
- package/lib/typescript/commonjs/ui/screens/AccountMembersScreen.d.ts.map +1 -1
- package/lib/typescript/commonjs/ui/stores/followTargetStore.d.ts +70 -0
- package/lib/typescript/commonjs/ui/stores/followTargetStore.d.ts.map +1 -0
- package/lib/typescript/commonjs/ui/stores/resetSessionScopedStores.d.ts.map +1 -1
- package/lib/typescript/module/index.d.ts +5 -0
- package/lib/typescript/module/index.d.ts.map +1 -1
- package/lib/typescript/module/ui/components/FollowButton.d.ts.map +1 -1
- package/lib/typescript/module/ui/components/FollowTargetButton.d.ts +130 -0
- package/lib/typescript/module/ui/components/FollowTargetButton.d.ts.map +1 -0
- package/lib/typescript/module/ui/hooks/useFollowTarget.d.ts +50 -0
- package/lib/typescript/module/ui/hooks/useFollowTarget.d.ts.map +1 -0
- package/lib/typescript/module/ui/screens/AccountMembersScreen.d.ts.map +1 -1
- package/lib/typescript/module/ui/stores/followTargetStore.d.ts +70 -0
- package/lib/typescript/module/ui/stores/followTargetStore.d.ts.map +1 -0
- package/lib/typescript/module/ui/stores/resetSessionScopedStores.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/index.ts +19 -0
- package/src/ui/components/FollowButton.tsx +3 -5
- package/src/ui/components/FollowTargetButton.tsx +356 -0
- package/src/ui/components/__tests__/followTargetButton.test.ts +152 -0
- package/src/ui/hooks/useFollowTarget.ts +211 -0
- package/src/ui/screens/AccountMembersScreen.tsx +62 -6
- package/src/ui/stores/__tests__/resetSessionScopedStores.test.ts +23 -0
- package/src/ui/stores/followTargetStore.ts +119 -0
- package/src/ui/stores/resetSessionScopedStores.ts +2 -0
|
@@ -0,0 +1,317 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* `FollowTargetButton` — one button for everything an Oxy user can follow.
|
|
5
|
+
*
|
|
6
|
+
* Follows a TARGET of any registered kind: a person, a topic, a channel, a
|
|
7
|
+
* store, an artist. Nothing in this file branches on what the target is, which
|
|
8
|
+
* is the property that lets an application this package has never heard of use
|
|
9
|
+
* it without a release.
|
|
10
|
+
*
|
|
11
|
+
* ## Two controls, not one
|
|
12
|
+
*
|
|
13
|
+
* The main press does the obvious thing. The chevron beside it opens the
|
|
14
|
+
* choices that a single press cannot express — follow for a while, stop showing
|
|
15
|
+
* this here without giving it up everywhere — and those belong behind a
|
|
16
|
+
* disclosure precisely because they are not what most people want most of the
|
|
17
|
+
* time. Bloom's `Menu` renders as a bottom sheet on native and a dropdown on
|
|
18
|
+
* web, so this is one component and not a platform fork.
|
|
19
|
+
*
|
|
20
|
+
* ## Verbs
|
|
21
|
+
*
|
|
22
|
+
* "Follow" is wrong for half the things in the ecosystem: you subscribe to a
|
|
23
|
+
* channel, you join a community, you watch a listing. The verb is a prop with a
|
|
24
|
+
* small vocabulary of defaults and a full override, rather than a lookup keyed
|
|
25
|
+
* on kind — a kind→verb table in this package would need a release every time
|
|
26
|
+
* an application invents a kind, which is exactly the coupling #809 removes.
|
|
27
|
+
*
|
|
28
|
+
* ## Relationship to the legacy `FollowButton`
|
|
29
|
+
*
|
|
30
|
+
* `FollowButton` follows a USER through the Mongo-backed social graph and
|
|
31
|
+
* remains the correct component for that until the user graph is migrated onto
|
|
32
|
+
* `/v2/follows`. When it is, that component is deleted and this one takes the
|
|
33
|
+
* name — not aliased, not deprecated in place.
|
|
34
|
+
*/
|
|
35
|
+
|
|
36
|
+
import { memo, useCallback, useMemo } from 'react';
|
|
37
|
+
import { View } from 'react-native';
|
|
38
|
+
import { Button } from '@oxyhq/bloom/button';
|
|
39
|
+
import { ChevronBottom_Stroke2_Corner0_Rounded as ChevronDown } from '@oxyhq/bloom/icons';
|
|
40
|
+
import { Menu, MenuContent, MenuItem, MenuItemText, MenuTrigger } from '@oxyhq/bloom/menu';
|
|
41
|
+
import { toast } from '@oxyhq/bloom/toast';
|
|
42
|
+
import { useFollowTarget } from "../hooks/useFollowTarget.js";
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* The small vocabulary of verbs the ecosystem actually uses. An application
|
|
46
|
+
* whose verb is not here passes `labels` instead — the escape hatch exists so
|
|
47
|
+
* this union never has to grow to accommodate one product's wording.
|
|
48
|
+
*/
|
|
49
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
50
|
+
const VERB_LABELS = {
|
|
51
|
+
follow: {
|
|
52
|
+
idle: 'Follow',
|
|
53
|
+
active: 'Following',
|
|
54
|
+
pending: 'Requested',
|
|
55
|
+
disabled: 'Off here'
|
|
56
|
+
},
|
|
57
|
+
subscribe: {
|
|
58
|
+
idle: 'Subscribe',
|
|
59
|
+
active: 'Subscribed',
|
|
60
|
+
pending: 'Requested',
|
|
61
|
+
disabled: 'Off here'
|
|
62
|
+
},
|
|
63
|
+
join: {
|
|
64
|
+
idle: 'Join',
|
|
65
|
+
active: 'Joined',
|
|
66
|
+
pending: 'Requested',
|
|
67
|
+
disabled: 'Off here'
|
|
68
|
+
},
|
|
69
|
+
watch: {
|
|
70
|
+
idle: 'Watch',
|
|
71
|
+
active: 'Watching',
|
|
72
|
+
pending: 'Requested',
|
|
73
|
+
disabled: 'Off here'
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
/** A timed-follow choice offered in the menu. */
|
|
78
|
+
|
|
79
|
+
const HOUR = 60 * 60;
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Defaults chosen for the cases a timed follow is actually for: a live event
|
|
83
|
+
* tonight, a story running this week. Not a general-purpose duration picker —
|
|
84
|
+
* an application that needs one passes its own.
|
|
85
|
+
*/
|
|
86
|
+
const DEFAULT_DURATIONS = [{
|
|
87
|
+
label: '24 hours',
|
|
88
|
+
seconds: 24 * HOUR
|
|
89
|
+
}, {
|
|
90
|
+
label: '72 hours',
|
|
91
|
+
seconds: 72 * HOUR
|
|
92
|
+
}, {
|
|
93
|
+
label: 'A week',
|
|
94
|
+
seconds: 7 * 24 * HOUR
|
|
95
|
+
}];
|
|
96
|
+
|
|
97
|
+
/** One line in the disclosure menu. */
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Which choices exist, given the state.
|
|
101
|
+
*
|
|
102
|
+
* Pure and exported because this is the product decision, not a rendering
|
|
103
|
+
* detail: a timed follow is only offered before following, turning it off here
|
|
104
|
+
* is only offered while following, and NEITHER is offered before the server has
|
|
105
|
+
* answered — every one of them addresses a relationship that does not exist
|
|
106
|
+
* yet, so offering them mid-write would mean sending a guessed id.
|
|
107
|
+
*/
|
|
108
|
+
/**
|
|
109
|
+
* What the main button should do for the current state.
|
|
110
|
+
*
|
|
111
|
+
* Exported because the product rule is not obvious from the label alone: a
|
|
112
|
+
* follow switched off here still reads as "following" globally, so the primary
|
|
113
|
+
* press must re-enable here — not unfollow everywhere.
|
|
114
|
+
*/
|
|
115
|
+
export function resolveFollowPrimaryAction(input) {
|
|
116
|
+
if (!input.isFollowing) return 'follow';
|
|
117
|
+
if (input.applicationMode === 'disabled') return 'enable-here';
|
|
118
|
+
return 'unfollow';
|
|
119
|
+
}
|
|
120
|
+
export function buildFollowMenuItems(input) {
|
|
121
|
+
const items = [];
|
|
122
|
+
if (!input.following) {
|
|
123
|
+
if (input.durations === false) return items;
|
|
124
|
+
for (const d of input.durations) {
|
|
125
|
+
items.push({
|
|
126
|
+
key: `for-${d.seconds}`,
|
|
127
|
+
label: `${input.idleVerb} for ${d.label.toLowerCase()}`,
|
|
128
|
+
action: {
|
|
129
|
+
type: 'follow-timed',
|
|
130
|
+
seconds: d.seconds,
|
|
131
|
+
durationLabel: d.label
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
return items;
|
|
136
|
+
}
|
|
137
|
+
if (!input.hasRelationship || input.isPending) return items;
|
|
138
|
+
items.push(input.applicationMode === 'disabled' ? {
|
|
139
|
+
key: 'enable-here',
|
|
140
|
+
label: `Show in ${input.applicationName}`,
|
|
141
|
+
action: {
|
|
142
|
+
type: 'enable-here'
|
|
143
|
+
}
|
|
144
|
+
} : {
|
|
145
|
+
key: 'disable-here',
|
|
146
|
+
label: `Don’t show in ${input.applicationName}`,
|
|
147
|
+
action: {
|
|
148
|
+
type: 'disable-here'
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
items.push({
|
|
152
|
+
// Named for what it does. "Unfollow" beside "don't show here" would read as
|
|
153
|
+
// the same action twice, and the user would pick the wrong one.
|
|
154
|
+
key: 'unfollow-everywhere',
|
|
155
|
+
label: 'Unfollow everywhere',
|
|
156
|
+
action: {
|
|
157
|
+
type: 'unfollow'
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
return items;
|
|
161
|
+
}
|
|
162
|
+
export const FollowTargetButton = /*#__PURE__*/memo(function FollowTargetButton({
|
|
163
|
+
targetId,
|
|
164
|
+
verb = 'follow',
|
|
165
|
+
labels,
|
|
166
|
+
size = 'medium',
|
|
167
|
+
style,
|
|
168
|
+
disabled = false,
|
|
169
|
+
showOptions = true,
|
|
170
|
+
durations = DEFAULT_DURATIONS,
|
|
171
|
+
applicationName,
|
|
172
|
+
onChange
|
|
173
|
+
}) {
|
|
174
|
+
const {
|
|
175
|
+
status,
|
|
176
|
+
isFollowing,
|
|
177
|
+
isUnknown,
|
|
178
|
+
isPending,
|
|
179
|
+
follow,
|
|
180
|
+
unfollow,
|
|
181
|
+
disableHere,
|
|
182
|
+
enableHere
|
|
183
|
+
} = useFollowTarget(targetId);
|
|
184
|
+
const text = useMemo(() => ({
|
|
185
|
+
...VERB_LABELS[verb],
|
|
186
|
+
...labels
|
|
187
|
+
}), [verb, labels]);
|
|
188
|
+
const label = useMemo(() => {
|
|
189
|
+
if (status.globalState === 'requested') return text.pending;
|
|
190
|
+
if (!isFollowing) return text.idle;
|
|
191
|
+
// Followed globally but switched off here. `effectiveState` reports
|
|
192
|
+
// `not_following` for this, correctly — the question it answers is "does
|
|
193
|
+
// this act here" — so the label has to be derived from the other two.
|
|
194
|
+
return status.applicationMode === 'disabled' ? text.disabled : text.active;
|
|
195
|
+
}, [isFollowing, status.globalState, status.applicationMode, text]);
|
|
196
|
+
|
|
197
|
+
// `onChange` fires ONLY when the server accepted the write.
|
|
198
|
+
//
|
|
199
|
+
// The mutations never reject — a refusal becomes error state so the button
|
|
200
|
+
// can render it — so an unconditional `onChange` after `await` reports
|
|
201
|
+
// INTENT rather than outcome. A caller mirroring the follow somewhere else
|
|
202
|
+
// (a local shelf, a ranking signal) would then mirror failures too, and the
|
|
203
|
+
// button beside it would show the server's truth while the mirror showed a
|
|
204
|
+
// press that did not happen. Same shape of trap as reading `effectiveState`
|
|
205
|
+
// as "does the user follow this".
|
|
206
|
+
const handlePrimary = useCallback(async () => {
|
|
207
|
+
switch (resolveFollowPrimaryAction({
|
|
208
|
+
isFollowing,
|
|
209
|
+
applicationMode: status.applicationMode
|
|
210
|
+
})) {
|
|
211
|
+
case 'enable-here':
|
|
212
|
+
if (await enableHere()) onChange?.(true);
|
|
213
|
+
return;
|
|
214
|
+
case 'unfollow':
|
|
215
|
+
if (await unfollow()) onChange?.(false);
|
|
216
|
+
return;
|
|
217
|
+
case 'follow':
|
|
218
|
+
if (await follow()) onChange?.(true);
|
|
219
|
+
}
|
|
220
|
+
}, [isFollowing, status.applicationMode, follow, unfollow, enableHere, onChange]);
|
|
221
|
+
const handleTimed = useCallback(async (seconds, durationLabel) => {
|
|
222
|
+
if (!(await follow({
|
|
223
|
+
expiresIn: seconds
|
|
224
|
+
}))) return;
|
|
225
|
+
onChange?.(true);
|
|
226
|
+
// The confirmation is the point: a follow that ends on its own is a
|
|
227
|
+
// promise, and a user who does not see it made will not believe it.
|
|
228
|
+
// Which is also why it must not appear when the promise was not made.
|
|
229
|
+
toast.success(`Following for ${durationLabel.toLowerCase()}`);
|
|
230
|
+
}, [follow, onChange]);
|
|
231
|
+
const menuItems = useMemo(() => buildFollowMenuItems({
|
|
232
|
+
following: isFollowing,
|
|
233
|
+
applicationMode: status.applicationMode,
|
|
234
|
+
hasRelationship: Boolean(status.relationshipId),
|
|
235
|
+
isPending,
|
|
236
|
+
durations,
|
|
237
|
+
idleVerb: text.idle,
|
|
238
|
+
applicationName: applicationName ?? 'this app'
|
|
239
|
+
}), [isFollowing, status.applicationMode, status.relationshipId, isPending, durations, text.idle, applicationName]);
|
|
240
|
+
const runItem = useCallback(item => {
|
|
241
|
+
switch (item.action.type) {
|
|
242
|
+
case 'follow-timed':
|
|
243
|
+
void handleTimed(item.action.seconds, item.action.durationLabel);
|
|
244
|
+
return;
|
|
245
|
+
case 'enable-here':
|
|
246
|
+
void enableHere();
|
|
247
|
+
return;
|
|
248
|
+
case 'disable-here':
|
|
249
|
+
void disableHere();
|
|
250
|
+
return;
|
|
251
|
+
case 'unfollow':
|
|
252
|
+
void unfollow().then(ok => {
|
|
253
|
+
if (ok) onChange?.(false);
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
}, [handleTimed, enableHere, disableHere, unfollow, onChange]);
|
|
257
|
+
const primary = /*#__PURE__*/_jsx(Button, {
|
|
258
|
+
variant: isFollowing ? 'secondary' : 'primary',
|
|
259
|
+
size: size
|
|
260
|
+
// Unknown is not "not following": the button stays inert until the first
|
|
261
|
+
// read settles rather than inviting a follow that may already exist.
|
|
262
|
+
,
|
|
263
|
+
disabled: disabled || isUnknown,
|
|
264
|
+
loading: isPending,
|
|
265
|
+
onPress: () => void handlePrimary(),
|
|
266
|
+
accessibilityLabel: label,
|
|
267
|
+
children: label
|
|
268
|
+
});
|
|
269
|
+
if (!showOptions || menuItems.length === 0) {
|
|
270
|
+
return /*#__PURE__*/_jsx(View, {
|
|
271
|
+
style: style,
|
|
272
|
+
children: primary
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
return /*#__PURE__*/_jsxs(View, {
|
|
276
|
+
style: [{
|
|
277
|
+
flexDirection: 'row',
|
|
278
|
+
alignItems: 'center',
|
|
279
|
+
gap: 4
|
|
280
|
+
}, style],
|
|
281
|
+
children: [primary, /*#__PURE__*/_jsxs(Menu, {
|
|
282
|
+
children: [/*#__PURE__*/_jsx(MenuTrigger, {
|
|
283
|
+
label: `${label} options`,
|
|
284
|
+
hint: "Opens follow options",
|
|
285
|
+
children: ({
|
|
286
|
+
props
|
|
287
|
+
}) =>
|
|
288
|
+
/*#__PURE__*/
|
|
289
|
+
// The trigger's props are mapped rather than spread: `MenuTrigger`
|
|
290
|
+
// hands back a DOM-ish bag (focus handlers, an accessibility role)
|
|
291
|
+
// and `Button` accepts a different set, so a spread would pass
|
|
292
|
+
// props it silently drops.
|
|
293
|
+
_jsx(Button, {
|
|
294
|
+
variant: "secondary",
|
|
295
|
+
size: size === 'large' ? 'large' : 'small',
|
|
296
|
+
icon: /*#__PURE__*/_jsx(ChevronDown, {
|
|
297
|
+
width: 16
|
|
298
|
+
}),
|
|
299
|
+
disabled: disabled || isUnknown,
|
|
300
|
+
onPress: props.onPress,
|
|
301
|
+
accessibilityLabel: props.accessibilityLabel,
|
|
302
|
+
accessibilityHint: props.accessibilityHint
|
|
303
|
+
})
|
|
304
|
+
}), /*#__PURE__*/_jsx(MenuContent, {
|
|
305
|
+
showCancel: true,
|
|
306
|
+
children: menuItems.map(item => /*#__PURE__*/_jsx(MenuItem, {
|
|
307
|
+
label: item.label,
|
|
308
|
+
onPress: () => runItem(item),
|
|
309
|
+
children: /*#__PURE__*/_jsx(MenuItemText, {
|
|
310
|
+
children: item.label
|
|
311
|
+
})
|
|
312
|
+
}, item.key))
|
|
313
|
+
})]
|
|
314
|
+
})]
|
|
315
|
+
});
|
|
316
|
+
});
|
|
317
|
+
//# sourceMappingURL=FollowTargetButton.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["memo","useCallback","useMemo","View","Button","ChevronBottom_Stroke2_Corner0_Rounded","ChevronDown","Menu","MenuContent","MenuItem","MenuItemText","MenuTrigger","toast","useFollowTarget","jsx","_jsx","jsxs","_jsxs","VERB_LABELS","follow","idle","active","pending","disabled","subscribe","join","watch","HOUR","DEFAULT_DURATIONS","label","seconds","resolveFollowPrimaryAction","input","isFollowing","applicationMode","buildFollowMenuItems","items","following","durations","d","push","key","idleVerb","toLowerCase","action","type","durationLabel","hasRelationship","isPending","applicationName","FollowTargetButton","targetId","verb","labels","size","style","showOptions","onChange","status","isUnknown","unfollow","disableHere","enableHere","text","globalState","handlePrimary","handleTimed","expiresIn","success","menuItems","Boolean","relationshipId","runItem","item","then","ok","primary","variant","loading","onPress","accessibilityLabel","children","length","flexDirection","alignItems","gap","hint","props","icon","width","accessibilityHint","showCancel","map"],"sourceRoot":"../../../../src","sources":["ui/components/FollowTargetButton.tsx"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAASA,IAAI,EAAEC,WAAW,EAAEC,OAAO,QAAQ,OAAO;AAGlD,SAASC,IAAI,QAAQ,cAAc;AACnC,SAASC,MAAM,QAAQ,qBAAqB;AAC5C,SAASC,qCAAqC,IAAIC,WAAW,QAAQ,oBAAoB;AACzF,SAASC,IAAI,EAAEC,WAAW,EAAEC,QAAQ,EAAEC,YAAY,EAAEC,WAAW,QAAQ,mBAAmB;AAC1F,SAASC,KAAK,QAAQ,oBAAoB;AAC1C,SAASC,eAAe,QAAQ,6BAA0B;;AAE1D;AACA;AACA;AACA;AACA;AAJA,SAAAC,GAAA,IAAAC,IAAA,EAAAC,IAAA,IAAAC,KAAA;AAkBA,MAAMC,WAA6C,GAAG;EACpDC,MAAM,EAAE;IAAEC,IAAI,EAAE,QAAQ;IAAEC,MAAM,EAAE,WAAW;IAAEC,OAAO,EAAE,W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QAAAL,QAAA,EAChEA,CAAC;UAAEM;QAAM,CAAC;QAAA;QACT;QACA;QACA;QACA;QACAxE,IAAA,CAACX,MAAM;UACLyE,OAAO,EAAC,WAAW;UACnBvB,IAAI,EAAEA,IAAI,KAAK,OAAO,GAAG,OAAO,GAAG,OAAQ;UAC3CkC,IAAI,eAAEzE,IAAA,CAACT,WAAW;YAACmF,KAAK,EAAE;UAAG,CAAE,CAAE;UACjClE,QAAQ,EAAEA,QAAQ,IAAIoC,SAAU;UAChCoB,OAAO,EAAEQ,KAAK,CAACR,OAAQ;UACvBC,kBAAkB,EAAEO,KAAK,CAACP,kBAAmB;UAC7CU,iBAAiB,EAAEH,KAAK,CAACG;QAAkB,CAC5C;MACF,CACU,CAAC,eACd3E,IAAA,CAACP,WAAW;QAACmF,UAAU;QAAAV,QAAA,EACpBZ,SAAS,CAACuB,GAAG,CAAEnB,IAAI,iBAClB1D,IAAA,CAACN,QAAQ;UAAgBoB,KAAK,EAAE4C,IAAI,CAAC5C,KAAM;UAACkD,OAAO,EAAEA,CAAA,KAAMP,OAAO,CAACC,IAAI,CAAE;UAAAQ,QAAA,eACvElE,IAAA,CAACL,YAAY;YAAAuE,QAAA,EAAER,IAAI,CAAC5C;UAAK,CAAe;QAAC,GAD5B4C,IAAI,CAAChC,GAEV,CACX;MAAC,CACS,CAAC;IAAA,CACV,CAAC;EAAA,CACH,CAAC;AAEX,CAAC,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* `useFollowTarget` — the one hook every application uses to follow anything.
|
|
5
|
+
*
|
|
6
|
+
* Wraps the `/v2/follows` SDK methods with the store above, an optimistic
|
|
7
|
+
* update, and a rollback. Nothing in here knows what kind of thing it is
|
|
8
|
+
* following, which is the property that lets an application the SDK has never
|
|
9
|
+
* heard of use it without a release of this package.
|
|
10
|
+
*
|
|
11
|
+
* ## Optimism, and its one limit
|
|
12
|
+
*
|
|
13
|
+
* A follow flips the button immediately and rolls back if the server refuses,
|
|
14
|
+
* because the round trip is long enough to feel like a bug otherwise. But an
|
|
15
|
+
* optimistic follow has no relationship id until the server answers, and every
|
|
16
|
+
* other operation addresses the relationship — so those stay disabled for the
|
|
17
|
+
* width of one request rather than being sent with a guessed id.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
import { useCallback, useEffect } from 'react';
|
|
21
|
+
import { useOxy } from "../context/OxyContext.js";
|
|
22
|
+
import { isFollowedGlobally, UNKNOWN_FOLLOW_STATUS, useFollowTargetStore, withApplicationMode } from "../stores/followTargetStore.js";
|
|
23
|
+
export function useFollowTarget(targetId, options) {
|
|
24
|
+
const {
|
|
25
|
+
oxyServices,
|
|
26
|
+
canUsePrivateApi
|
|
27
|
+
} = useOxy();
|
|
28
|
+
const status = useFollowTargetStore(useCallback(s => targetId ? s.statuses[targetId] : undefined, [targetId]));
|
|
29
|
+
const isPending = useFollowTargetStore(useCallback(s => targetId ? s.pending[targetId] ?? false : false, [targetId]));
|
|
30
|
+
const error = useFollowTargetStore(useCallback(s => targetId ? s.errors[targetId] : undefined, [targetId]));
|
|
31
|
+
const initialStatus = options?.initialStatus;
|
|
32
|
+
|
|
33
|
+
// A caller that already knows the status — a follow list, a feed payload —
|
|
34
|
+
// seeds it rather than making this hook re-ask once per rendered row.
|
|
35
|
+
useEffect(() => {
|
|
36
|
+
if (!targetId || !initialStatus) return;
|
|
37
|
+
const store = useFollowTargetStore.getState();
|
|
38
|
+
if (!store.statuses[targetId]) store.setStatus(targetId, initialStatus);
|
|
39
|
+
}, [targetId, initialStatus]);
|
|
40
|
+
const refresh = useCallback(async () => {
|
|
41
|
+
// Gated on `canUsePrivateApi`, not on `isAuthenticated`: during the session
|
|
42
|
+
// cold boot the second is true well before the first, and a read sent in
|
|
43
|
+
// that window 401s and would leave the button stuck reporting an error the
|
|
44
|
+
// user cannot act on.
|
|
45
|
+
if (!targetId || !canUsePrivateApi) return;
|
|
46
|
+
try {
|
|
47
|
+
const next = await oxyServices.getFollowTargetStatus(targetId);
|
|
48
|
+
useFollowTargetStore.getState().setStatus(targetId, next);
|
|
49
|
+
useFollowTargetStore.getState().setError(targetId, undefined);
|
|
50
|
+
} catch (e) {
|
|
51
|
+
useFollowTargetStore.getState().setError(targetId, e instanceof Error ? e.message : 'Could not read follow status');
|
|
52
|
+
}
|
|
53
|
+
}, [targetId, canUsePrivateApi, oxyServices]);
|
|
54
|
+
useEffect(() => {
|
|
55
|
+
if (!targetId || !canUsePrivateApi) return;
|
|
56
|
+
if (useFollowTargetStore.getState().statuses[targetId]) return;
|
|
57
|
+
void refresh();
|
|
58
|
+
}, [targetId, canUsePrivateApi, refresh]);
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Run a mutation optimistically: show `optimistic` at once, keep the previous
|
|
62
|
+
* value, and put it back if the server refuses. Every mutation below goes
|
|
63
|
+
* through this so the rollback cannot be forgotten in one of them.
|
|
64
|
+
*/
|
|
65
|
+
const mutate = useCallback(async (optimistic, run, failureMessage) => {
|
|
66
|
+
if (!targetId) return false;
|
|
67
|
+
const store = useFollowTargetStore.getState();
|
|
68
|
+
const previous = store.statuses[targetId];
|
|
69
|
+
store.setStatus(targetId, optimistic);
|
|
70
|
+
store.setPending(targetId, true);
|
|
71
|
+
store.setError(targetId, undefined);
|
|
72
|
+
try {
|
|
73
|
+
const settled = await run();
|
|
74
|
+
if (settled) useFollowTargetStore.getState().setStatus(targetId, settled);
|
|
75
|
+
return true;
|
|
76
|
+
} catch (e) {
|
|
77
|
+
const s = useFollowTargetStore.getState();
|
|
78
|
+
// Back to what was true, not to a guess. Clearing the entry instead
|
|
79
|
+
// would make the next render ask again and flash the wrong state.
|
|
80
|
+
if (previous) s.setStatus(targetId, previous);
|
|
81
|
+
s.setError(targetId, e instanceof Error ? e.message : failureMessage);
|
|
82
|
+
return false;
|
|
83
|
+
} finally {
|
|
84
|
+
useFollowTargetStore.getState().setPending(targetId, false);
|
|
85
|
+
}
|
|
86
|
+
}, [targetId]);
|
|
87
|
+
const current = status ?? UNKNOWN_FOLLOW_STATUS;
|
|
88
|
+
const follow = useCallback(async opts => {
|
|
89
|
+
if (!targetId) return false;
|
|
90
|
+
return mutate({
|
|
91
|
+
...withApplicationMode({
|
|
92
|
+
...current,
|
|
93
|
+
globalState: 'active'
|
|
94
|
+
}, current.applicationMode),
|
|
95
|
+
...(opts?.expiresIn ? {
|
|
96
|
+
expiresAt: new Date(Date.now() + opts.expiresIn * 1000).toISOString()
|
|
97
|
+
} : {})
|
|
98
|
+
},
|
|
99
|
+
// The server returns the whole resulting status, so store it rather
|
|
100
|
+
// than reconstructing one: `effectiveState`'s derivation lives there,
|
|
101
|
+
// and a client recomputing it is a second implementation of one rule.
|
|
102
|
+
async () => (await oxyServices.followTarget(targetId, opts)).status, 'Could not follow');
|
|
103
|
+
}, [targetId, current, mutate, oxyServices]);
|
|
104
|
+
const unfollow = useCallback(async () => {
|
|
105
|
+
const relationshipId = current.relationshipId;
|
|
106
|
+
if (!targetId || !relationshipId) return false;
|
|
107
|
+
return mutate({
|
|
108
|
+
...UNKNOWN_FOLLOW_STATUS
|
|
109
|
+
}, async () => {
|
|
110
|
+
await oxyServices.unfollowTarget(relationshipId);
|
|
111
|
+
return {
|
|
112
|
+
...UNKNOWN_FOLLOW_STATUS
|
|
113
|
+
};
|
|
114
|
+
}, 'Could not unfollow');
|
|
115
|
+
}, [targetId, current.relationshipId, mutate, oxyServices]);
|
|
116
|
+
const disableHere = useCallback(async () => {
|
|
117
|
+
const relationshipId = current.relationshipId;
|
|
118
|
+
if (!targetId || !relationshipId) return false;
|
|
119
|
+
return mutate(withApplicationMode(current, 'disabled'), async () => {
|
|
120
|
+
await oxyServices.setFollowApplicationMode(relationshipId, 'disabled');
|
|
121
|
+
}, 'Could not change this app’s setting for this follow');
|
|
122
|
+
}, [targetId, current, mutate, oxyServices]);
|
|
123
|
+
const enableHere = useCallback(async () => {
|
|
124
|
+
const relationshipId = current.relationshipId;
|
|
125
|
+
if (!targetId || !relationshipId) return false;
|
|
126
|
+
return mutate(withApplicationMode(current, 'inherit'), async () => {
|
|
127
|
+
await oxyServices.restoreFollowInheritance(relationshipId);
|
|
128
|
+
}, 'Could not change this app’s setting for this follow');
|
|
129
|
+
}, [targetId, current, mutate, oxyServices]);
|
|
130
|
+
return {
|
|
131
|
+
status: current,
|
|
132
|
+
isFollowing: isFollowedGlobally(current),
|
|
133
|
+
isUnknown: status === undefined,
|
|
134
|
+
isPending,
|
|
135
|
+
error,
|
|
136
|
+
follow,
|
|
137
|
+
unfollow,
|
|
138
|
+
disableHere,
|
|
139
|
+
enableHere,
|
|
140
|
+
refresh
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
//# sourceMappingURL=useFollowTarget.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["useCallback","useEffect","useOxy","isFollowedGlobally","UNKNOWN_FOLLOW_STATUS","useFollowTargetStore","withApplicationMode","useFollowTarget","targetId","options","oxyServices","canUsePrivateApi","status","s","statuses","undefined","isPending","pending","error","errors","initialStatus","store","getState","setStatus","refresh","next","getFollowTargetStatus","setError","e","Error","message","mutate","optimistic","run","failureMessage","previous","setPending","settled","current","follow","opts","globalState","applicationMode","expiresIn","expiresAt","Date","now","toISOString","followTarget","unfollow","relationshipId","unfollowTarget","disableHere","setFollowApplicationMode","enableHere","restoreFollowInheritance","isFollowing","isUnknown"],"sourceRoot":"../../../../src","sources":["ui/hooks/useFollowTarget.ts"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAASA,WAAW,EAAEC,SAAS,QAAQ,OAAO;AAE9C,SAASC,MAAM,QAAQ,0BAAuB;AAC9C,SACEC,kBAAkB,EAClBC,qBAAqB,EACrBC,oBAAoB,EACpBC,mBAAmB,QACd,gCAA6B;AA8BpC,OAAO,SAASC,eAAeA,CAC7BC,QAA4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F,CAAC;EACH,CAAC,EAAE,CAAC1C,QAAQ,EAAE8B,OAAO,EAAEP,MAAM,EAAErB,WAAW,CAAC,CAAC;EAE5C,OAAO;IACLE,MAAM,EAAE0B,OAAO;IACfkB,WAAW,EAAErD,kBAAkB,CAACmC,OAAO,CAAC;IACxCmB,SAAS,EAAE7C,MAAM,KAAKG,SAAS;IAC/BC,SAAS;IACTE,KAAK;IACLqB,MAAM;IACNU,QAAQ;IACRG,WAAW;IACXE,UAAU;IACV9B;EACF,CAAC;AACH","ignoreList":[]}
|
|
@@ -11,6 +11,7 @@ import { Text } from '@oxyhq/bloom/typography';
|
|
|
11
11
|
import { Button } from '@oxyhq/bloom/button';
|
|
12
12
|
import { TextField, TextFieldInput } from '@oxyhq/bloom/text-field';
|
|
13
13
|
import { Divider } from '@oxyhq/bloom/divider';
|
|
14
|
+
import { getNormalizedUserHandle } from '@oxyhq/core';
|
|
14
15
|
import { useOxy } from "../context/OxyContext.js";
|
|
15
16
|
import { useI18n } from "../hooks/useI18n.js";
|
|
16
17
|
import { useSurfaceHeader } from "../hooks/useSurfaceHeader.js";
|
|
@@ -74,10 +75,36 @@ const AccountMembersScreen = ({
|
|
|
74
75
|
enabled: canUsePrivateApi && id.length > 0 && canRead
|
|
75
76
|
});
|
|
76
77
|
const members = useMemo(() => membersQuery.data ?? [], [membersQuery.data]);
|
|
77
|
-
const
|
|
78
|
+
const memberUserIds = useMemo(() => [...new Set(members.map(member => member.memberUserId).filter(id => id.length > 0))], [members]);
|
|
79
|
+
const memberProfilesQuery = useQuery({
|
|
80
|
+
queryKey: ['users', 'by-ids', memberUserIds],
|
|
81
|
+
queryFn: () => oxyServices.getUsersByIds(memberUserIds),
|
|
82
|
+
enabled: canUsePrivateApi && memberUserIds.length > 0
|
|
83
|
+
});
|
|
84
|
+
const memberLabelByUserId = useMemo(() => {
|
|
85
|
+
const labels = new Map();
|
|
86
|
+
for (const profile of memberProfilesQuery.data ?? []) {
|
|
87
|
+
// `getNormalizedUserHandle` answers null for an actor with no resolvable
|
|
88
|
+
// handle. Leaving that entry out is what lets `memberDisplayLabel`'s own
|
|
89
|
+
// fallback run, rather than storing a null the map is not typed to hold.
|
|
90
|
+
const handle = getNormalizedUserHandle(profile);
|
|
91
|
+
if (handle) labels.set(profile.id, handle);
|
|
92
|
+
}
|
|
93
|
+
return labels;
|
|
94
|
+
}, [memberProfilesQuery.data]);
|
|
95
|
+
const memberDisplayLabel = useCallback(memberUserId => memberLabelByUserId.get(memberUserId) ?? memberUserId, [memberLabelByUserId]);
|
|
96
|
+
// DIRECT owners only. The list also carries members whose row lives on an
|
|
97
|
+
// ancestor, and the last-owner rule this count feeds is about the rows on THIS
|
|
98
|
+
// account — the server's guard counts those. Including an inherited owner
|
|
99
|
+
// would make a child that has no owner of its own look like it has exactly
|
|
100
|
+
// one, and silently disable removing anybody.
|
|
101
|
+
const ownerCount = useMemo(() => members.filter(m => m.role === 'owner' && (m.source ?? 'direct') === 'direct').length, [members]);
|
|
78
102
|
const invalidateMembers = useCallback(() => {
|
|
103
|
+
// Inherited rows on descendant rosters derive from ancestor membership
|
|
104
|
+
// tables — mirror the SDK's per-account prefix sweep so every cached member
|
|
105
|
+
// list refetches, not only the account that was mutated.
|
|
79
106
|
queryClient.invalidateQueries({
|
|
80
|
-
queryKey: ['accounts', 'members'
|
|
107
|
+
queryKey: ['accounts', 'members']
|
|
81
108
|
});
|
|
82
109
|
queryClient.invalidateQueries({
|
|
83
110
|
queryKey: ['accounts', 'detail', id]
|
|
@@ -282,9 +309,16 @@ const AccountMembersScreen = ({
|
|
|
282
309
|
children: members.map((member, index) => {
|
|
283
310
|
const isOwner = member.role === 'owner';
|
|
284
311
|
const isLastOwner = isOwner && ownerCount <= 1;
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
312
|
+
// An INHERITED entry's row lives on an ancestor account, and
|
|
313
|
+
// every member mutation is scoped to rows on the account in
|
|
314
|
+
// the path — so offering to edit, remove or promote one would
|
|
315
|
+
// be offering a request the server answers 404. The row is
|
|
316
|
+
// changed where it lives, on that ancestor's own member
|
|
317
|
+
// screen.
|
|
318
|
+
const isEditableHere = (member.source ?? 'direct') === 'direct';
|
|
319
|
+
const canEditThisRole = canUpdate && isEditableHere && !isOwner;
|
|
320
|
+
const canRemoveThisMember = canRemove && isEditableHere && !isLastOwner && (!isOwner || canTransfer);
|
|
321
|
+
const canTransferToThis = canTransfer && isEditableHere && !isOwner && member.status === 'active';
|
|
288
322
|
return /*#__PURE__*/_jsxs(View, {
|
|
289
323
|
children: [index > 0 ? /*#__PURE__*/_jsx(Divider, {
|
|
290
324
|
color: colors.border,
|
|
@@ -296,7 +330,7 @@ const AccountMembersScreen = ({
|
|
|
296
330
|
children: [/*#__PURE__*/_jsx(Text, {
|
|
297
331
|
className: "text-body font-bodyBold text-text flex-1",
|
|
298
332
|
numberOfLines: 1,
|
|
299
|
-
children: member.memberUserId
|
|
333
|
+
children: memberDisplayLabel(member.memberUserId)
|
|
300
334
|
}), isOwner ? /*#__PURE__*/_jsx(View, {
|
|
301
335
|
className: "px-space-8 py-space-4 rounded-radius-full",
|
|
302
336
|
style: {
|
|
@@ -309,6 +343,15 @@ const AccountMembersScreen = ({
|
|
|
309
343
|
},
|
|
310
344
|
children: roleLabel('owner')
|
|
311
345
|
})
|
|
346
|
+
}) : null, !isEditableHere ? /*#__PURE__*/_jsx(View, {
|
|
347
|
+
className: "px-space-8 py-space-4 rounded-radius-full",
|
|
348
|
+
style: {
|
|
349
|
+
backgroundColor: colors.card
|
|
350
|
+
},
|
|
351
|
+
children: /*#__PURE__*/_jsx(Text, {
|
|
352
|
+
className: "text-caption font-caption text-text-secondary",
|
|
353
|
+
children: t('accounts.members.inherited') || 'Inherited'
|
|
354
|
+
})
|
|
312
355
|
}) : null, member.status !== 'active' ? /*#__PURE__*/_jsx(View, {
|
|
313
356
|
className: "px-space-8 py-space-4 rounded-radius-full",
|
|
314
357
|
style: {
|