@oxyhq/services 27.0.0 → 27.1.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/lib/commonjs/index.js +29 -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 +292 -0
- package/lib/commonjs/ui/components/FollowTargetButton.js.map +1 -0
- package/lib/commonjs/ui/hooks/useFollowTarget.js +140 -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 +4 -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 +287 -0
- package/lib/module/ui/components/FollowTargetButton.js.map +1 -0
- package/lib/module/ui/hooks/useFollowTarget.js +136 -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 +119 -0
- package/lib/typescript/commonjs/ui/components/FollowTargetButton.d.ts.map +1 -0
- package/lib/typescript/commonjs/ui/hooks/useFollowTarget.d.ts +41 -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 +119 -0
- package/lib/typescript/module/ui/components/FollowTargetButton.d.ts.map +1 -0
- package/lib/typescript/module/ui/hooks/useFollowTarget.d.ts +41 -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 +11 -0
- package/src/ui/components/FollowButton.tsx +3 -5
- package/src/ui/components/FollowTargetButton.tsx +326 -0
- package/src/ui/components/__tests__/followTargetButton.test.ts +132 -0
- package/src/ui/hooks/useFollowTarget.ts +194 -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
package/lib/commonjs/index.js
CHANGED
|
@@ -39,6 +39,12 @@ Object.defineProperty(exports, "FollowButton", {
|
|
|
39
39
|
return _FollowButton.default;
|
|
40
40
|
}
|
|
41
41
|
});
|
|
42
|
+
Object.defineProperty(exports, "FollowTargetButton", {
|
|
43
|
+
enumerable: true,
|
|
44
|
+
get: function () {
|
|
45
|
+
return _FollowTargetButton.FollowTargetButton;
|
|
46
|
+
}
|
|
47
|
+
});
|
|
42
48
|
Object.defineProperty(exports, "IdentityBoundSessionError", {
|
|
43
49
|
enumerable: true,
|
|
44
50
|
get: function () {
|
|
@@ -159,6 +165,12 @@ Object.defineProperty(exports, "SurfaceHeaderAction", {
|
|
|
159
165
|
return _SurfaceHeaderAction.SurfaceHeaderAction;
|
|
160
166
|
}
|
|
161
167
|
});
|
|
168
|
+
Object.defineProperty(exports, "UNKNOWN_FOLLOW_STATUS", {
|
|
169
|
+
enumerable: true,
|
|
170
|
+
get: function () {
|
|
171
|
+
return _followTargetStore.UNKNOWN_FOLLOW_STATUS;
|
|
172
|
+
}
|
|
173
|
+
});
|
|
162
174
|
Object.defineProperty(exports, "clearedFieldsFromAccountUpdate", {
|
|
163
175
|
enumerable: true,
|
|
164
176
|
get: function () {
|
|
@@ -453,6 +465,18 @@ Object.defineProperty(exports, "useFollow", {
|
|
|
453
465
|
return _useFollow.useFollow;
|
|
454
466
|
}
|
|
455
467
|
});
|
|
468
|
+
Object.defineProperty(exports, "useFollowTarget", {
|
|
469
|
+
enumerable: true,
|
|
470
|
+
get: function () {
|
|
471
|
+
return _useFollowTarget.useFollowTarget;
|
|
472
|
+
}
|
|
473
|
+
});
|
|
474
|
+
Object.defineProperty(exports, "useFollowTargetStore", {
|
|
475
|
+
enumerable: true,
|
|
476
|
+
get: function () {
|
|
477
|
+
return _followTargetStore.useFollowTargetStore;
|
|
478
|
+
}
|
|
479
|
+
});
|
|
456
480
|
Object.defineProperty(exports, "useFollowerCounts", {
|
|
457
481
|
enumerable: true,
|
|
458
482
|
get: function () {
|
|
@@ -735,6 +759,9 @@ var _OxyOAuthCallback = require("./ui/components/OxyOAuthCallback.js");
|
|
|
735
759
|
var _OxyConsentScreen = require("./ui/components/OxyConsentScreen.js");
|
|
736
760
|
var _RequireOxyAuth = require("./ui/components/RequireOxyAuth.js");
|
|
737
761
|
var _FollowButton = _interopRequireDefault(require("./ui/components/FollowButton.js"));
|
|
762
|
+
var _FollowTargetButton = require("./ui/components/FollowTargetButton.js");
|
|
763
|
+
var _useFollowTarget = require("./ui/hooks/useFollowTarget.js");
|
|
764
|
+
var _followTargetStore = require("./ui/stores/followTargetStore.js");
|
|
738
765
|
var _OxyPayButton = _interopRequireDefault(require("./ui/components/OxyPayButton.js"));
|
|
739
766
|
var _LogoIcon = require("./ui/components/logo/LogoIcon.js");
|
|
740
767
|
var _LogoText = require("./ui/components/logo/LogoText.js");
|
|
@@ -872,6 +899,8 @@ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e
|
|
|
872
899
|
// Gates on `useOxy().canUsePrivateApi` / `isPrivateApiPending` — never flashes the
|
|
873
900
|
// wall before the device-first cold boot resolves. Opens the ONE account dialog.
|
|
874
901
|
|
|
902
|
+
// The follow graph (#809): follows anything registered, not just users.
|
|
903
|
+
|
|
875
904
|
// Sidebar account trigger. Pressing `ProfileButton` opens the unified
|
|
876
905
|
// `OxyAccountDialogScreen` (the single account switcher + sign-in surface) via
|
|
877
906
|
// `useOxy().openAccountDialog`.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_core","require","_reactNative","_OxyProvider","_interopRequireDefault","_OxyContext","_useAuth","_identityBinding","_authStore","_accountStore","_assetStore","_useAssets","_useFileDownloadUrl","_useFollow","_useStorage","_useAccountQueries","_useServicesQueries","_useSecurityQueries","_useAuthMethods","_usePaymentQueries","_useAccountMutations","_useServicesMutations","_mutationFactory","_mutationKeys","_queryKeys","_userCache","_useMutationStatus","_useOnlineStatus","_useOxyEvent","_errorHandlers","_useFileFiltering","_OxySignInButton","_oauthPopup","_OxyAuthPrompt","_OxyOAuthCallback","_OxyConsentScreen","_RequireOxyAuth","_FollowButton","_OxyPayButton","_LogoIcon","_LogoText","_ProfileButton","_OxyAuthChooser","_OxySignInRequestSurface","_useSwitchableAccounts","_ProfileScreen","_ManageAccountScreen","_NotificationsScreen","_PreferencesScreen","_ConnectedAppsScreen","_CreateAccountScreen","_AccountMembersScreen","_AccountSettingsScreen","_bottomSheetManager","_useSurfaceHeader","_SurfaceHeaderAction","_accountDialogManager","e","__esModule","default","setPlatformOS","Platform","OS"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":"
|
|
1
|
+
{"version":3,"names":["_core","require","_reactNative","_OxyProvider","_interopRequireDefault","_OxyContext","_useAuth","_identityBinding","_authStore","_accountStore","_assetStore","_useAssets","_useFileDownloadUrl","_useFollow","_useStorage","_useAccountQueries","_useServicesQueries","_useSecurityQueries","_useAuthMethods","_usePaymentQueries","_useAccountMutations","_useServicesMutations","_mutationFactory","_mutationKeys","_queryKeys","_userCache","_useMutationStatus","_useOnlineStatus","_useOxyEvent","_errorHandlers","_useFileFiltering","_OxySignInButton","_oauthPopup","_OxyAuthPrompt","_OxyOAuthCallback","_OxyConsentScreen","_RequireOxyAuth","_FollowButton","_FollowTargetButton","_useFollowTarget","_followTargetStore","_OxyPayButton","_LogoIcon","_LogoText","_ProfileButton","_OxyAuthChooser","_OxySignInRequestSurface","_useSwitchableAccounts","_ProfileScreen","_ManageAccountScreen","_NotificationsScreen","_PreferencesScreen","_ConnectedAppsScreen","_CreateAccountScreen","_AccountMembersScreen","_AccountSettingsScreen","_bottomSheetManager","_useSurfaceHeader","_SurfaceHeaderAction","_accountDialogManager","e","__esModule","default","setPlatformOS","Platform","OS"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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AAiD,oBAAA,GAAA9C,sBAAA,CAAAH,OAAA;AACA,IAAAkD,kBAAA,GAAA/C,sBAAA,CAAAH,OAAA;AACA,IAAAmD,oBAAA,GAAAhD,sBAAA,CAAAH,OAAA;AAGA,IAAAoD,oBAAA,GAAAjD,sBAAA,CAAAH,OAAA;AACA,IAAAqD,qBAAA,GAAAlD,sBAAA,CAAAH,OAAA;AACA,IAAAsD,sBAAA,GAAAnD,sBAAA,CAAAH,OAAA;AAKA,IAAAuD,mBAAA,GAAAvD,OAAA;AAMA,IAAAwD,iBAAA,GAAAxD,OAAA;AACA,IAAAyD,oBAAA,GAAAzD,OAAA;AAMA,IAAA0D,qBAAA,GAAA1D,OAAA;AAI8C,SAAAG,uBAAAwD,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AA3W9C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAIA,IAAAG,mBAAa,EAACC,qBAAQ,CAACC,EAAgB,CAAC;;AAExC;AACA;AACA;;AAMA;AACA;AACA;;AAGA;AACA;AACA;;AAgBA;AACA;AACA;;AAOA;AACA;AACA;;AAgCA;;AAeA;AACA;AACA;;AA2BA;;AAGA;AACA;AACA;AACA;AACA;AACA;;AAeA;AACA;AACA;AACA;AACA;AACA;AACA;;AAcA;;AAMA;AACA;AACA;;AASA;AACA;AACA;;AAIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAQA;AACA;AACA;AACA;;AAsBA;AACA;AACA;AACA;AACA;;AAMA;;AAeA;AACA;AACA;;AAKA;AACA;AACA;AACA;AACA;;AAIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAKA;AACA;AACA;AACA;AACA;AACA;;AAIA;;AAOA;;AAKA;AACA;AACA;;AAIA;AACA;AACA;;AAIA;AACA;AACA;AACA","ignoreList":[]}
|
|
@@ -5,10 +5,10 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = exports.FollowButton = void 0;
|
|
7
7
|
var _react = require("react");
|
|
8
|
+
var _reactNative = require("react-native");
|
|
8
9
|
var _OxyContext = require("../context/OxyContext.js");
|
|
9
10
|
var _toast = require("@oxyhq/bloom/toast");
|
|
10
11
|
var _button = require("@oxyhq/bloom/button");
|
|
11
|
-
var _loading = require("@oxyhq/bloom/loading");
|
|
12
12
|
var _useFollow = require("../hooks/useFollow.js");
|
|
13
13
|
var _followStore = require("../stores/followStore.js");
|
|
14
14
|
var _theme = require("@oxyhq/bloom/theme");
|
|
@@ -89,8 +89,7 @@ const FollowButtonInner = /*#__PURE__*/(0, _react.memo)(function FollowButtonInn
|
|
|
89
89
|
disabled: disabled || isBusy,
|
|
90
90
|
style: style,
|
|
91
91
|
textStyle: textStyle,
|
|
92
|
-
icon: showSpinner ? /*#__PURE__*/(0, _jsxRuntime.jsx)(
|
|
93
|
-
variant: "inline",
|
|
92
|
+
icon: showSpinner ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.ActivityIndicator, {
|
|
94
93
|
size: "small",
|
|
95
94
|
color: showFollowing ? colors.text : colors.primaryForeground
|
|
96
95
|
}) : undefined,
|
|
@@ -200,8 +199,7 @@ const FollowButtonMultiInner = /*#__PURE__*/(0, _react.memo)(function FollowButt
|
|
|
200
199
|
disabled: disabled || isLoading,
|
|
201
200
|
style: style,
|
|
202
201
|
textStyle: textStyle,
|
|
203
|
-
icon: showSpinner ? /*#__PURE__*/(0, _jsxRuntime.jsx)(
|
|
204
|
-
variant: "inline",
|
|
202
|
+
icon: showSpinner ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.ActivityIndicator, {
|
|
205
203
|
size: "small",
|
|
206
204
|
color: allFollowing ? colors.text : colors.primaryForeground
|
|
207
205
|
}) : undefined,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_react","require","_OxyContext","_toast","_button","
|
|
1
|
+
{"version":3,"names":["_react","require","_reactNative","_OxyContext","_toast","_button","_useFollow","_followStore","_theme","_shallow","_jsxRuntime","DEFAULT_FOLLOW_ALL_LABEL","DEFAULT_FOLLOWED_ALL_LABEL","isMultiMode","props","Array","isArray","userIds","FollowButtonInner","memo","userId","oxyServices","initiallyFollowing","size","onFollowChange","style","textStyle","disabled","showLoadingState","preventParentActions","colors","useTheme","isFollowing","isKnown","isLoading","toggleFollow","resolveStatus","useFollowForButton","handlePress","useCallback","event","preventDefault","stopPropagation","err","error","Error","String","toast","message","useEffect","isBusy","showFollowing","showSpinner","jsx","Button","variant","onPress","icon","ActivityIndicator","color","text","primaryForeground","undefined","children","FollowButtonMultiInner","initiallyAllFollowing","followAllLabel","followedAllLabel","onBulkFollow","onBulkUnfollow","follow","useFollow","followAllUsers","unfollowAllUsers","isAnyLoading","initialFollowStatuses","useFollowStore","useShallow","state","statuses","uid","Object","prototype","hasOwnProperty","call","followingUsers","hasKnownNotFollowing","some","storeAllFollowing","allFollowing","fetchAllStatuses","isSubmitting","setIsSubmitting","useState","result","allAlreadyFollowing","followedCount","results","length","every","entry","alreadyFollowing","anyFollowed","success","FollowButton","canUsePrivateApi","user","currentUser","useOxy","currentUserId","id","trim","rawUserIds","multiUserIds","useMemo","seen","Set","cleaned","raw","has","add","push","targetUserId","exports","_default","default"],"sourceRoot":"../../../../src","sources":["ui/components/FollowButton.tsx"],"mappings":";;;;;;AACA,IAAAA,MAAA,GAAAC,OAAA;AAMA,IAAAC,YAAA,GAAAD,OAAA;AACA,IAAAE,WAAA,GAAAF,OAAA;AACA,IAAAG,MAAA,GAAAH,OAAA;AACA,IAAAI,OAAA,GAAAJ,OAAA;AACA,IAAAK,UAAA,GAAAL,OAAA;AACA,IAAAM,YAAA,GAAAN,OAAA;AACA,IAAAO,M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,292 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.FollowTargetButton = void 0;
|
|
7
|
+
exports.buildFollowMenuItems = buildFollowMenuItems;
|
|
8
|
+
var _react = require("react");
|
|
9
|
+
var _reactNative = require("react-native");
|
|
10
|
+
var _button = require("@oxyhq/bloom/button");
|
|
11
|
+
var _icons = require("@oxyhq/bloom/icons");
|
|
12
|
+
var _menu = require("@oxyhq/bloom/menu");
|
|
13
|
+
var _toast = require("@oxyhq/bloom/toast");
|
|
14
|
+
var _useFollowTarget = require("../hooks/useFollowTarget.js");
|
|
15
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
16
|
+
/**
|
|
17
|
+
* `FollowTargetButton` — one button for everything an Oxy user can follow.
|
|
18
|
+
*
|
|
19
|
+
* Follows a TARGET of any registered kind: a person, a topic, a channel, a
|
|
20
|
+
* store, an artist. Nothing in this file branches on what the target is, which
|
|
21
|
+
* is the property that lets an application this package has never heard of use
|
|
22
|
+
* it without a release.
|
|
23
|
+
*
|
|
24
|
+
* ## Two controls, not one
|
|
25
|
+
*
|
|
26
|
+
* The main press does the obvious thing. The chevron beside it opens the
|
|
27
|
+
* choices that a single press cannot express — follow for a while, stop showing
|
|
28
|
+
* this here without giving it up everywhere — and those belong behind a
|
|
29
|
+
* disclosure precisely because they are not what most people want most of the
|
|
30
|
+
* time. Bloom's `Menu` renders as a bottom sheet on native and a dropdown on
|
|
31
|
+
* web, so this is one component and not a platform fork.
|
|
32
|
+
*
|
|
33
|
+
* ## Verbs
|
|
34
|
+
*
|
|
35
|
+
* "Follow" is wrong for half the things in the ecosystem: you subscribe to a
|
|
36
|
+
* channel, you join a community, you watch a listing. The verb is a prop with a
|
|
37
|
+
* small vocabulary of defaults and a full override, rather than a lookup keyed
|
|
38
|
+
* on kind — a kind→verb table in this package would need a release every time
|
|
39
|
+
* an application invents a kind, which is exactly the coupling #809 removes.
|
|
40
|
+
*
|
|
41
|
+
* ## Relationship to the legacy `FollowButton`
|
|
42
|
+
*
|
|
43
|
+
* `FollowButton` follows a USER through the Mongo-backed social graph and
|
|
44
|
+
* remains the correct component for that until the user graph is migrated onto
|
|
45
|
+
* `/v2/follows`. When it is, that component is deleted and this one takes the
|
|
46
|
+
* name — not aliased, not deprecated in place.
|
|
47
|
+
*/
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* The small vocabulary of verbs the ecosystem actually uses. An application
|
|
51
|
+
* whose verb is not here passes `labels` instead — the escape hatch exists so
|
|
52
|
+
* this union never has to grow to accommodate one product's wording.
|
|
53
|
+
*/
|
|
54
|
+
|
|
55
|
+
const VERB_LABELS = {
|
|
56
|
+
follow: {
|
|
57
|
+
idle: 'Follow',
|
|
58
|
+
active: 'Following',
|
|
59
|
+
pending: 'Requested',
|
|
60
|
+
disabled: 'Off here'
|
|
61
|
+
},
|
|
62
|
+
subscribe: {
|
|
63
|
+
idle: 'Subscribe',
|
|
64
|
+
active: 'Subscribed',
|
|
65
|
+
pending: 'Requested',
|
|
66
|
+
disabled: 'Off here'
|
|
67
|
+
},
|
|
68
|
+
join: {
|
|
69
|
+
idle: 'Join',
|
|
70
|
+
active: 'Joined',
|
|
71
|
+
pending: 'Requested',
|
|
72
|
+
disabled: 'Off here'
|
|
73
|
+
},
|
|
74
|
+
watch: {
|
|
75
|
+
idle: 'Watch',
|
|
76
|
+
active: 'Watching',
|
|
77
|
+
pending: 'Requested',
|
|
78
|
+
disabled: 'Off here'
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
/** A timed-follow choice offered in the menu. */
|
|
83
|
+
|
|
84
|
+
const HOUR = 60 * 60;
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Defaults chosen for the cases a timed follow is actually for: a live event
|
|
88
|
+
* tonight, a story running this week. Not a general-purpose duration picker —
|
|
89
|
+
* an application that needs one passes its own.
|
|
90
|
+
*/
|
|
91
|
+
const DEFAULT_DURATIONS = [{
|
|
92
|
+
label: '24 hours',
|
|
93
|
+
seconds: 24 * HOUR
|
|
94
|
+
}, {
|
|
95
|
+
label: '72 hours',
|
|
96
|
+
seconds: 72 * HOUR
|
|
97
|
+
}, {
|
|
98
|
+
label: 'A week',
|
|
99
|
+
seconds: 7 * 24 * HOUR
|
|
100
|
+
}];
|
|
101
|
+
|
|
102
|
+
/** One line in the disclosure menu. */
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Which choices exist, given the state.
|
|
106
|
+
*
|
|
107
|
+
* Pure and exported because this is the product decision, not a rendering
|
|
108
|
+
* detail: a timed follow is only offered before following, turning it off here
|
|
109
|
+
* is only offered while following, and NEITHER is offered before the server has
|
|
110
|
+
* answered — every one of them addresses a relationship that does not exist
|
|
111
|
+
* yet, so offering them mid-write would mean sending a guessed id.
|
|
112
|
+
*/
|
|
113
|
+
function buildFollowMenuItems(input) {
|
|
114
|
+
const items = [];
|
|
115
|
+
if (!input.following) {
|
|
116
|
+
if (input.durations === false) return items;
|
|
117
|
+
for (const d of input.durations) {
|
|
118
|
+
items.push({
|
|
119
|
+
key: `for-${d.seconds}`,
|
|
120
|
+
label: `${input.idleVerb} for ${d.label.toLowerCase()}`,
|
|
121
|
+
action: {
|
|
122
|
+
type: 'follow-timed',
|
|
123
|
+
seconds: d.seconds,
|
|
124
|
+
durationLabel: d.label
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
return items;
|
|
129
|
+
}
|
|
130
|
+
if (!input.hasRelationship || input.isPending) return items;
|
|
131
|
+
items.push(input.applicationMode === 'disabled' ? {
|
|
132
|
+
key: 'enable-here',
|
|
133
|
+
label: `Show in ${input.applicationName}`,
|
|
134
|
+
action: {
|
|
135
|
+
type: 'enable-here'
|
|
136
|
+
}
|
|
137
|
+
} : {
|
|
138
|
+
key: 'disable-here',
|
|
139
|
+
label: `Don’t show in ${input.applicationName}`,
|
|
140
|
+
action: {
|
|
141
|
+
type: 'disable-here'
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
items.push({
|
|
145
|
+
// Named for what it does. "Unfollow" beside "don't show here" would read as
|
|
146
|
+
// the same action twice, and the user would pick the wrong one.
|
|
147
|
+
key: 'unfollow-everywhere',
|
|
148
|
+
label: 'Unfollow everywhere',
|
|
149
|
+
action: {
|
|
150
|
+
type: 'unfollow'
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
return items;
|
|
154
|
+
}
|
|
155
|
+
const FollowTargetButton = exports.FollowTargetButton = /*#__PURE__*/(0, _react.memo)(function FollowTargetButton({
|
|
156
|
+
targetId,
|
|
157
|
+
verb = 'follow',
|
|
158
|
+
labels,
|
|
159
|
+
size = 'medium',
|
|
160
|
+
style,
|
|
161
|
+
disabled = false,
|
|
162
|
+
showOptions = true,
|
|
163
|
+
durations = DEFAULT_DURATIONS,
|
|
164
|
+
applicationName,
|
|
165
|
+
onChange
|
|
166
|
+
}) {
|
|
167
|
+
const {
|
|
168
|
+
status,
|
|
169
|
+
isFollowing,
|
|
170
|
+
isUnknown,
|
|
171
|
+
isPending,
|
|
172
|
+
follow,
|
|
173
|
+
unfollow,
|
|
174
|
+
disableHere,
|
|
175
|
+
enableHere
|
|
176
|
+
} = (0, _useFollowTarget.useFollowTarget)(targetId);
|
|
177
|
+
const text = (0, _react.useMemo)(() => ({
|
|
178
|
+
...VERB_LABELS[verb],
|
|
179
|
+
...labels
|
|
180
|
+
}), [verb, labels]);
|
|
181
|
+
const label = (0, _react.useMemo)(() => {
|
|
182
|
+
if (status.globalState === 'requested') return text.pending;
|
|
183
|
+
if (!isFollowing) return text.idle;
|
|
184
|
+
// Followed globally but switched off here. `effectiveState` reports
|
|
185
|
+
// `not_following` for this, correctly — the question it answers is "does
|
|
186
|
+
// this act here" — so the label has to be derived from the other two.
|
|
187
|
+
return status.applicationMode === 'disabled' ? text.disabled : text.active;
|
|
188
|
+
}, [isFollowing, status.globalState, status.applicationMode, text]);
|
|
189
|
+
const handlePrimary = (0, _react.useCallback)(async () => {
|
|
190
|
+
if (isFollowing) {
|
|
191
|
+
await unfollow();
|
|
192
|
+
onChange?.(false);
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
await follow();
|
|
196
|
+
onChange?.(true);
|
|
197
|
+
}, [isFollowing, follow, unfollow, onChange]);
|
|
198
|
+
const handleTimed = (0, _react.useCallback)(async (seconds, durationLabel) => {
|
|
199
|
+
await follow({
|
|
200
|
+
expiresIn: seconds
|
|
201
|
+
});
|
|
202
|
+
onChange?.(true);
|
|
203
|
+
// The confirmation is the point: a follow that ends on its own is a
|
|
204
|
+
// promise, and a user who does not see it made will not believe it.
|
|
205
|
+
_toast.toast.success(`Following for ${durationLabel.toLowerCase()}`);
|
|
206
|
+
}, [follow, onChange]);
|
|
207
|
+
const menuItems = (0, _react.useMemo)(() => buildFollowMenuItems({
|
|
208
|
+
following: isFollowing,
|
|
209
|
+
applicationMode: status.applicationMode,
|
|
210
|
+
hasRelationship: Boolean(status.relationshipId),
|
|
211
|
+
isPending,
|
|
212
|
+
durations,
|
|
213
|
+
idleVerb: text.idle,
|
|
214
|
+
applicationName: applicationName ?? 'this app'
|
|
215
|
+
}), [isFollowing, status.applicationMode, status.relationshipId, isPending, durations, text.idle, applicationName]);
|
|
216
|
+
const runItem = (0, _react.useCallback)(item => {
|
|
217
|
+
switch (item.action.type) {
|
|
218
|
+
case 'follow-timed':
|
|
219
|
+
void handleTimed(item.action.seconds, item.action.durationLabel);
|
|
220
|
+
return;
|
|
221
|
+
case 'enable-here':
|
|
222
|
+
void enableHere();
|
|
223
|
+
return;
|
|
224
|
+
case 'disable-here':
|
|
225
|
+
void disableHere();
|
|
226
|
+
return;
|
|
227
|
+
case 'unfollow':
|
|
228
|
+
void unfollow();
|
|
229
|
+
onChange?.(false);
|
|
230
|
+
}
|
|
231
|
+
}, [handleTimed, enableHere, disableHere, unfollow, onChange]);
|
|
232
|
+
const primary = /*#__PURE__*/(0, _jsxRuntime.jsx)(_button.Button, {
|
|
233
|
+
variant: isFollowing ? 'secondary' : 'primary',
|
|
234
|
+
size: size
|
|
235
|
+
// Unknown is not "not following": the button stays inert until the first
|
|
236
|
+
// read settles rather than inviting a follow that may already exist.
|
|
237
|
+
,
|
|
238
|
+
disabled: disabled || isUnknown,
|
|
239
|
+
loading: isPending,
|
|
240
|
+
onPress: () => void handlePrimary(),
|
|
241
|
+
accessibilityLabel: label,
|
|
242
|
+
children: label
|
|
243
|
+
});
|
|
244
|
+
if (!showOptions || menuItems.length === 0) {
|
|
245
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, {
|
|
246
|
+
style: style,
|
|
247
|
+
children: primary
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.View, {
|
|
251
|
+
style: [{
|
|
252
|
+
flexDirection: 'row',
|
|
253
|
+
alignItems: 'center',
|
|
254
|
+
gap: 4
|
|
255
|
+
}, style],
|
|
256
|
+
children: [primary, /*#__PURE__*/(0, _jsxRuntime.jsxs)(_menu.Menu, {
|
|
257
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_menu.MenuTrigger, {
|
|
258
|
+
label: `${label} options`,
|
|
259
|
+
hint: "Opens follow options",
|
|
260
|
+
children: ({
|
|
261
|
+
props
|
|
262
|
+
}) =>
|
|
263
|
+
/*#__PURE__*/
|
|
264
|
+
// The trigger's props are mapped rather than spread: `MenuTrigger`
|
|
265
|
+
// hands back a DOM-ish bag (focus handlers, an accessibility role)
|
|
266
|
+
// and `Button` accepts a different set, so a spread would pass
|
|
267
|
+
// props it silently drops.
|
|
268
|
+
(0, _jsxRuntime.jsx)(_button.Button, {
|
|
269
|
+
variant: "secondary",
|
|
270
|
+
size: size === 'large' ? 'large' : 'small',
|
|
271
|
+
icon: /*#__PURE__*/(0, _jsxRuntime.jsx)(_icons.ChevronBottom_Stroke2_Corner0_Rounded, {
|
|
272
|
+
width: 16
|
|
273
|
+
}),
|
|
274
|
+
disabled: disabled || isUnknown,
|
|
275
|
+
onPress: props.onPress,
|
|
276
|
+
accessibilityLabel: props.accessibilityLabel,
|
|
277
|
+
accessibilityHint: props.accessibilityHint
|
|
278
|
+
})
|
|
279
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_menu.MenuContent, {
|
|
280
|
+
showCancel: true,
|
|
281
|
+
children: menuItems.map(item => /*#__PURE__*/(0, _jsxRuntime.jsx)(_menu.MenuItem, {
|
|
282
|
+
label: item.label,
|
|
283
|
+
onPress: () => runItem(item),
|
|
284
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_menu.MenuItemText, {
|
|
285
|
+
children: item.label
|
|
286
|
+
})
|
|
287
|
+
}, item.key))
|
|
288
|
+
})]
|
|
289
|
+
})]
|
|
290
|
+
});
|
|
291
|
+
});
|
|
292
|
+
//# sourceMappingURL=FollowTargetButton.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_react","require","_reactNative","_button","_icons","_menu","_toast","_useFollowTarget","_jsxRuntime","VERB_LABELS","follow","idle","active","pending","disabled","subscribe","join","watch","HOUR","DEFAULT_DURATIONS","label","seconds","buildFollowMenuItems","input","items","following","durations","d","push","key","idleVerb","toLowerCase","action","type","durationLabel","hasRelationship","isPending","applicationMode","applicationName","FollowTargetButton","exports","memo","targetId","verb","labels","size","style","showOptions","onChange","status","isFollowing","isUnknown","unfollow","disableHere","enableHere","useFollowTarget","text","useMemo","globalState","handlePrimary","useCallback","handleTimed","expiresIn","toast","success","menuItems","Boolean","relationshipId","runItem","item","primary","jsx","Button","variant","loading","onPress","accessibilityLabel","children","length","View","jsxs","flexDirection","alignItems","gap","Menu","MenuTrigger","hint","props","icon","ChevronBottom_Stroke2_Corner0_Rounded","width","accessibilityHint","MenuContent","showCancel","map","MenuItem","MenuItemText"],"sourceRoot":"../../../../src","sources":["ui/components/FollowTargetButton.tsx"],"mapp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List":[]}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.useFollowTarget = useFollowTarget;
|
|
7
|
+
var _react = require("react");
|
|
8
|
+
var _OxyContext = require("../context/OxyContext.js");
|
|
9
|
+
var _followTargetStore = require("../stores/followTargetStore.js");
|
|
10
|
+
/**
|
|
11
|
+
* `useFollowTarget` — the one hook every application uses to follow anything.
|
|
12
|
+
*
|
|
13
|
+
* Wraps the `/v2/follows` SDK methods with the store above, an optimistic
|
|
14
|
+
* update, and a rollback. Nothing in here knows what kind of thing it is
|
|
15
|
+
* following, which is the property that lets an application the SDK has never
|
|
16
|
+
* heard of use it without a release of this package.
|
|
17
|
+
*
|
|
18
|
+
* ## Optimism, and its one limit
|
|
19
|
+
*
|
|
20
|
+
* A follow flips the button immediately and rolls back if the server refuses,
|
|
21
|
+
* because the round trip is long enough to feel like a bug otherwise. But an
|
|
22
|
+
* optimistic follow has no relationship id until the server answers, and every
|
|
23
|
+
* other operation addresses the relationship — so those stay disabled for the
|
|
24
|
+
* width of one request rather than being sent with a guessed id.
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
function useFollowTarget(targetId, options) {
|
|
28
|
+
const {
|
|
29
|
+
oxyServices,
|
|
30
|
+
canUsePrivateApi
|
|
31
|
+
} = (0, _OxyContext.useOxy)();
|
|
32
|
+
const status = (0, _followTargetStore.useFollowTargetStore)((0, _react.useCallback)(s => targetId ? s.statuses[targetId] : undefined, [targetId]));
|
|
33
|
+
const isPending = (0, _followTargetStore.useFollowTargetStore)((0, _react.useCallback)(s => targetId ? s.pending[targetId] ?? false : false, [targetId]));
|
|
34
|
+
const error = (0, _followTargetStore.useFollowTargetStore)((0, _react.useCallback)(s => targetId ? s.errors[targetId] : undefined, [targetId]));
|
|
35
|
+
const initialStatus = options?.initialStatus;
|
|
36
|
+
|
|
37
|
+
// A caller that already knows the status — a follow list, a feed payload —
|
|
38
|
+
// seeds it rather than making this hook re-ask once per rendered row.
|
|
39
|
+
(0, _react.useEffect)(() => {
|
|
40
|
+
if (!targetId || !initialStatus) return;
|
|
41
|
+
const store = _followTargetStore.useFollowTargetStore.getState();
|
|
42
|
+
if (!store.statuses[targetId]) store.setStatus(targetId, initialStatus);
|
|
43
|
+
}, [targetId, initialStatus]);
|
|
44
|
+
const refresh = (0, _react.useCallback)(async () => {
|
|
45
|
+
// Gated on `canUsePrivateApi`, not on `isAuthenticated`: during the session
|
|
46
|
+
// cold boot the second is true well before the first, and a read sent in
|
|
47
|
+
// that window 401s and would leave the button stuck reporting an error the
|
|
48
|
+
// user cannot act on.
|
|
49
|
+
if (!targetId || !canUsePrivateApi) return;
|
|
50
|
+
try {
|
|
51
|
+
const next = await oxyServices.getFollowTargetStatus(targetId);
|
|
52
|
+
_followTargetStore.useFollowTargetStore.getState().setStatus(targetId, next);
|
|
53
|
+
_followTargetStore.useFollowTargetStore.getState().setError(targetId, undefined);
|
|
54
|
+
} catch (e) {
|
|
55
|
+
_followTargetStore.useFollowTargetStore.getState().setError(targetId, e instanceof Error ? e.message : 'Could not read follow status');
|
|
56
|
+
}
|
|
57
|
+
}, [targetId, canUsePrivateApi, oxyServices]);
|
|
58
|
+
(0, _react.useEffect)(() => {
|
|
59
|
+
if (!targetId || !canUsePrivateApi) return;
|
|
60
|
+
if (_followTargetStore.useFollowTargetStore.getState().statuses[targetId]) return;
|
|
61
|
+
void refresh();
|
|
62
|
+
}, [targetId, canUsePrivateApi, refresh]);
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Run a mutation optimistically: show `optimistic` at once, keep the previous
|
|
66
|
+
* value, and put it back if the server refuses. Every mutation below goes
|
|
67
|
+
* through this so the rollback cannot be forgotten in one of them.
|
|
68
|
+
*/
|
|
69
|
+
const mutate = (0, _react.useCallback)(async (optimistic, run, failureMessage) => {
|
|
70
|
+
if (!targetId) return;
|
|
71
|
+
const store = _followTargetStore.useFollowTargetStore.getState();
|
|
72
|
+
const previous = store.statuses[targetId];
|
|
73
|
+
store.setStatus(targetId, optimistic);
|
|
74
|
+
store.setPending(targetId, true);
|
|
75
|
+
store.setError(targetId, undefined);
|
|
76
|
+
try {
|
|
77
|
+
const settled = await run();
|
|
78
|
+
if (settled) _followTargetStore.useFollowTargetStore.getState().setStatus(targetId, settled);
|
|
79
|
+
} catch (e) {
|
|
80
|
+
const s = _followTargetStore.useFollowTargetStore.getState();
|
|
81
|
+
// Back to what was true, not to a guess. Clearing the entry instead
|
|
82
|
+
// would make the next render ask again and flash the wrong state.
|
|
83
|
+
if (previous) s.setStatus(targetId, previous);
|
|
84
|
+
s.setError(targetId, e instanceof Error ? e.message : failureMessage);
|
|
85
|
+
} finally {
|
|
86
|
+
_followTargetStore.useFollowTargetStore.getState().setPending(targetId, false);
|
|
87
|
+
}
|
|
88
|
+
}, [targetId]);
|
|
89
|
+
const current = status ?? _followTargetStore.UNKNOWN_FOLLOW_STATUS;
|
|
90
|
+
const follow = (0, _react.useCallback)(async opts => {
|
|
91
|
+
if (!targetId) return;
|
|
92
|
+
await mutate({
|
|
93
|
+
...(0, _followTargetStore.withApplicationMode)({
|
|
94
|
+
...current,
|
|
95
|
+
globalState: 'active'
|
|
96
|
+
}, current.applicationMode),
|
|
97
|
+
...(opts?.expiresIn ? {
|
|
98
|
+
expiresAt: new Date(Date.now() + opts.expiresIn * 1000).toISOString()
|
|
99
|
+
} : {})
|
|
100
|
+
},
|
|
101
|
+
// The server returns the whole resulting status, so store it rather
|
|
102
|
+
// than reconstructing one: `effectiveState`'s derivation lives there,
|
|
103
|
+
// and a client recomputing it is a second implementation of one rule.
|
|
104
|
+
async () => (await oxyServices.followTarget(targetId, opts)).status, 'Could not follow');
|
|
105
|
+
}, [targetId, current, mutate, oxyServices]);
|
|
106
|
+
const unfollow = (0, _react.useCallback)(async () => {
|
|
107
|
+
const relationshipId = current.relationshipId;
|
|
108
|
+
if (!targetId || !relationshipId) return;
|
|
109
|
+
await mutate({
|
|
110
|
+
..._followTargetStore.UNKNOWN_FOLLOW_STATUS
|
|
111
|
+
}, async () => {
|
|
112
|
+
await oxyServices.unfollowTarget(relationshipId);
|
|
113
|
+
return {
|
|
114
|
+
..._followTargetStore.UNKNOWN_FOLLOW_STATUS
|
|
115
|
+
};
|
|
116
|
+
}, 'Could not unfollow');
|
|
117
|
+
}, [targetId, current.relationshipId, mutate, oxyServices]);
|
|
118
|
+
const setMode = (0, _react.useCallback)(async mode => {
|
|
119
|
+
const relationshipId = current.relationshipId;
|
|
120
|
+
if (!targetId || !relationshipId) return;
|
|
121
|
+
await mutate((0, _followTargetStore.withApplicationMode)(current, mode), async () => {
|
|
122
|
+
await oxyServices.setFollowApplicationMode(relationshipId, mode);
|
|
123
|
+
}, 'Could not change this app’s setting for this follow');
|
|
124
|
+
}, [targetId, current, mutate, oxyServices]);
|
|
125
|
+
const disableHere = (0, _react.useCallback)(() => setMode('disabled'), [setMode]);
|
|
126
|
+
const enableHere = (0, _react.useCallback)(() => setMode('enabled'), [setMode]);
|
|
127
|
+
return {
|
|
128
|
+
status: current,
|
|
129
|
+
isFollowing: (0, _followTargetStore.isFollowedGlobally)(current),
|
|
130
|
+
isUnknown: status === undefined,
|
|
131
|
+
isPending,
|
|
132
|
+
error,
|
|
133
|
+
follow,
|
|
134
|
+
unfollow,
|
|
135
|
+
disableHere,
|
|
136
|
+
enableHere,
|
|
137
|
+
refresh
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
//# sourceMappingURL=useFollowTarget.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_react","require","_OxyContext","_followTargetStore","useFollowTarget","targetId","options","oxyServices","canUsePrivateApi","useOxy","status","useFollowTargetStore","useCallback","s","statuses","undefined","isPending","pending","error","errors","initialStatus","useEffect","store","getState","setStatus","refresh","next","getFollowTargetStatus","setError","e","Error","message","mutate","optimistic","run","failureMessage","previous","setPending","settled","current","UNKNOWN_FOLLOW_STATUS","follow","opts","withApplicationMode","globalState","applicationMode","expiresIn","expiresAt","Date","now","toISOString","followTarget","unfollow","relationshipId","unfollowTarget","setMode","mode","setFollowApplicationMode","disableHere","enableHere","isFollowing","isFollowedGlobally","isUnknown"],"sourceRoot":"../../../../src","sources":["ui/hooks/useFollowTarget.ts"],"mappings":";;;;;;AAiBA,IAAAA,MAAA,GAAAC,OAAA;AAEA,IAAAC,WAAA,GAAAD,OAAA;AACA,IAAAE,kBAAA,GAAAF,OAAA;AApBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AA+BO,SAASG,eAAeA,CAC7BC,QAA4B,EAC5BC,OAA0C,EACnB;EACvB,MAAM;IAAEC,WAAW;IAAEC;EAAiB,CAAC,GAAG,IAAAC,kBAAM,EAAC,CAAC;EAElD,MAAMC,MAAM,GAAG,IAAAC,uCAAoB,EACjC,IAAAC,kBAAW,EAAEC,CAAC,IAAMR,QAAQ,GAAGQ,CAAC,CAACC,QAAQ,CAACT,QAAQ,CAAC,GAAGU,SAAU,EAAE,CAACV,QAAQ,CAAC,CAC9E,CAAC;EACD,MAAMW,SAAS,GAAG,IAAAL,uCAAoB,EACpC,IAAAC,kBAAW,EAAEC,CAAC,IAAMR,QAAQ,GAAIQ,CAAC,CAACI,OAAO,CAACZ,QAAQ,CAAC,IAAI,KAAK,GAAI,KAAM,EAAE,CAACA,QAAQ,CAAC,CACpF,CAAC;EACD,MAAMa,KAAK,GAAG,IAAAP,uCAAoB,EAChC,IAAAC,kBAAW,EAAEC,CAAC,IAAMR,QAAQ,GAAGQ,CAAC,CAACM,MAAM,CAACd,QAAQ,CAAC,GAAGU,SAAU,EAAE,CAACV,QAAQ,CAAC,CAC5E,CAAC;EAED,MAAMe,aAAa,GAAGd,OAAO,EAAEc,aAAa;;EAE5C;EACA;EACA,IAAAC,gBAAS,EAAC,MAAM;IACd,IAAI,CAAChB,QAAQ,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