@oxy.so/services 12.5.0 → 12.7.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.
Files changed (101) hide show
  1. package/lib/commonjs/index.js.map +1 -1
  2. package/lib/commonjs/ui/client.js +13 -0
  3. package/lib/commonjs/ui/client.js.map +1 -1
  4. package/lib/commonjs/ui/components/FollowButton.js +27 -14
  5. package/lib/commonjs/ui/components/FollowButton.js.map +1 -1
  6. package/lib/commonjs/ui/components/FollowTargetButton.js +39 -51
  7. package/lib/commonjs/ui/components/FollowTargetButton.js.map +1 -1
  8. package/lib/commonjs/ui/components/OxyConsentScreen.js.map +1 -1
  9. package/lib/commonjs/ui/components/authChooser/types.js.map +1 -1
  10. package/lib/commonjs/ui/components/followButtonAccessibility.js +24 -7
  11. package/lib/commonjs/ui/components/followButtonAccessibility.js.map +1 -1
  12. package/lib/commonjs/ui/components/followLabels.js +38 -0
  13. package/lib/commonjs/ui/components/followLabels.js.map +1 -0
  14. package/lib/commonjs/ui/components/followRules.js +29 -13
  15. package/lib/commonjs/ui/components/followRules.js.map +1 -1
  16. package/lib/commonjs/ui/hooks/useAccountColor.js +56 -0
  17. package/lib/commonjs/ui/hooks/useAccountColor.js.map +1 -0
  18. package/lib/commonjs/ui/hooks/useI18n.js +2 -0
  19. package/lib/commonjs/ui/hooks/useI18n.js.map +1 -1
  20. package/lib/commonjs/ui/utils/deviceSessionTitle.js.map +1 -1
  21. package/lib/module/index.js.map +1 -1
  22. package/lib/module/ui/client.js +1 -0
  23. package/lib/module/ui/client.js.map +1 -1
  24. package/lib/module/ui/components/FollowButton.js +28 -15
  25. package/lib/module/ui/components/FollowButton.js.map +1 -1
  26. package/lib/module/ui/components/FollowTargetButton.js +39 -51
  27. package/lib/module/ui/components/FollowTargetButton.js.map +1 -1
  28. package/lib/module/ui/components/OxyConsentScreen.js.map +1 -1
  29. package/lib/module/ui/components/authChooser/types.js.map +1 -1
  30. package/lib/module/ui/components/followButtonAccessibility.js +24 -7
  31. package/lib/module/ui/components/followButtonAccessibility.js.map +1 -1
  32. package/lib/module/ui/components/followLabels.js +35 -0
  33. package/lib/module/ui/components/followLabels.js.map +1 -0
  34. package/lib/module/ui/components/followRules.js +30 -13
  35. package/lib/module/ui/components/followRules.js.map +1 -1
  36. package/lib/module/ui/hooks/useAccountColor.js +51 -0
  37. package/lib/module/ui/hooks/useAccountColor.js.map +1 -0
  38. package/lib/module/ui/hooks/useI18n.js +2 -0
  39. package/lib/module/ui/hooks/useI18n.js.map +1 -1
  40. package/lib/module/ui/utils/deviceSessionTitle.js.map +1 -1
  41. package/lib/typescript/commonjs/index.d.ts +2 -1
  42. package/lib/typescript/commonjs/index.d.ts.map +1 -1
  43. package/lib/typescript/commonjs/ui/client.d.ts +4 -1
  44. package/lib/typescript/commonjs/ui/client.d.ts.map +1 -1
  45. package/lib/typescript/commonjs/ui/components/FollowButton.d.ts +13 -0
  46. package/lib/typescript/commonjs/ui/components/FollowButton.d.ts.map +1 -1
  47. package/lib/typescript/commonjs/ui/components/FollowTargetButton.d.ts +6 -18
  48. package/lib/typescript/commonjs/ui/components/FollowTargetButton.d.ts.map +1 -1
  49. package/lib/typescript/commonjs/ui/components/OxyConsentScreen.d.ts.map +1 -1
  50. package/lib/typescript/commonjs/ui/components/authChooser/types.d.ts +1 -2
  51. package/lib/typescript/commonjs/ui/components/authChooser/types.d.ts.map +1 -1
  52. package/lib/typescript/commonjs/ui/components/followButtonAccessibility.d.ts +12 -2
  53. package/lib/typescript/commonjs/ui/components/followButtonAccessibility.d.ts.map +1 -1
  54. package/lib/typescript/commonjs/ui/components/followLabels.d.ts +28 -0
  55. package/lib/typescript/commonjs/ui/components/followLabels.d.ts.map +1 -0
  56. package/lib/typescript/commonjs/ui/components/followRules.d.ts +20 -9
  57. package/lib/typescript/commonjs/ui/components/followRules.d.ts.map +1 -1
  58. package/lib/typescript/commonjs/ui/hooks/useAccountColor.d.ts +25 -0
  59. package/lib/typescript/commonjs/ui/hooks/useAccountColor.d.ts.map +1 -0
  60. package/lib/typescript/commonjs/ui/hooks/useI18n.d.ts +3 -1
  61. package/lib/typescript/commonjs/ui/hooks/useI18n.d.ts.map +1 -1
  62. package/lib/typescript/commonjs/ui/utils/deviceSessionTitle.d.ts +1 -2
  63. package/lib/typescript/commonjs/ui/utils/deviceSessionTitle.d.ts.map +1 -1
  64. package/lib/typescript/module/index.d.ts +2 -1
  65. package/lib/typescript/module/index.d.ts.map +1 -1
  66. package/lib/typescript/module/ui/client.d.ts +4 -1
  67. package/lib/typescript/module/ui/client.d.ts.map +1 -1
  68. package/lib/typescript/module/ui/components/FollowButton.d.ts +13 -0
  69. package/lib/typescript/module/ui/components/FollowButton.d.ts.map +1 -1
  70. package/lib/typescript/module/ui/components/FollowTargetButton.d.ts +6 -18
  71. package/lib/typescript/module/ui/components/FollowTargetButton.d.ts.map +1 -1
  72. package/lib/typescript/module/ui/components/OxyConsentScreen.d.ts.map +1 -1
  73. package/lib/typescript/module/ui/components/authChooser/types.d.ts +1 -2
  74. package/lib/typescript/module/ui/components/authChooser/types.d.ts.map +1 -1
  75. package/lib/typescript/module/ui/components/followButtonAccessibility.d.ts +12 -2
  76. package/lib/typescript/module/ui/components/followButtonAccessibility.d.ts.map +1 -1
  77. package/lib/typescript/module/ui/components/followLabels.d.ts +28 -0
  78. package/lib/typescript/module/ui/components/followLabels.d.ts.map +1 -0
  79. package/lib/typescript/module/ui/components/followRules.d.ts +20 -9
  80. package/lib/typescript/module/ui/components/followRules.d.ts.map +1 -1
  81. package/lib/typescript/module/ui/hooks/useAccountColor.d.ts +25 -0
  82. package/lib/typescript/module/ui/hooks/useAccountColor.d.ts.map +1 -0
  83. package/lib/typescript/module/ui/hooks/useI18n.d.ts +3 -1
  84. package/lib/typescript/module/ui/hooks/useI18n.d.ts.map +1 -1
  85. package/lib/typescript/module/ui/utils/deviceSessionTitle.d.ts +1 -2
  86. package/lib/typescript/module/ui/utils/deviceSessionTitle.d.ts.map +1 -1
  87. package/package.json +5 -5
  88. package/src/index.ts +2 -5
  89. package/src/ui/client.ts +8 -5
  90. package/src/ui/components/FollowButton.tsx +53 -23
  91. package/src/ui/components/FollowTargetButton.tsx +39 -52
  92. package/src/ui/components/OxyConsentScreen.tsx +1 -3
  93. package/src/ui/components/__tests__/followButtonAccessibility.test.tsx +32 -6
  94. package/src/ui/components/__tests__/followTargetButton.test.ts +7 -1
  95. package/src/ui/components/authChooser/types.ts +1 -2
  96. package/src/ui/components/followButtonAccessibility.ts +38 -25
  97. package/src/ui/components/followLabels.ts +48 -0
  98. package/src/ui/components/followRules.ts +29 -13
  99. package/src/ui/hooks/useAccountColor.ts +52 -0
  100. package/src/ui/hooks/useI18n.ts +5 -3
  101. package/src/ui/utils/deviceSessionTitle.ts +1 -2
@@ -22,6 +22,8 @@
22
22
  * small vocabulary of defaults and a full override, rather than a lookup keyed
23
23
  * on kind — a kind→verb table in this package would need a release every time
24
24
  * an application invents a kind, which is exactly the coupling #809 removes.
25
+ * The vocabulary and its translated words live in `followLabels`, shared with
26
+ * `FollowButton`.
25
27
  *
26
28
  * ## Relationship to the legacy `FollowButton`
27
29
  *
@@ -58,55 +60,28 @@ import {
58
60
  type FollowDuration,
59
61
  type FollowMenuItem,
60
62
  } from './followRules';
61
-
62
- /**
63
- * The small vocabulary of verbs the ecosystem actually uses. An application
64
- * whose verb is not here passes `labels` instead — the escape hatch exists so
65
- * this union never has to grow to accommodate one product's wording.
66
- */
67
- export type FollowVerb = 'follow' | 'subscribe' | 'join' | 'watch';
68
-
69
- export interface FollowLabels {
70
- /** Not following yet. */
71
- idle: string;
72
- /** Following, and this application acts on it. */
73
- active: string;
74
- /** Asked, waiting for the other side to accept. */
75
- pending: string;
76
- /** Following globally, but switched off in this application. */
77
- disabled: string;
78
- }
79
-
80
- const VERB_LABELS: Record<FollowVerb, FollowLabels> = {
81
- follow: { idle: 'Follow', active: 'Following', pending: 'Requested', disabled: 'Off here' },
82
- subscribe: {
83
- idle: 'Subscribe',
84
- active: 'Subscribed',
85
- pending: 'Requested',
86
- disabled: 'Off here',
87
- },
88
- join: { idle: 'Join', active: 'Joined', pending: 'Requested', disabled: 'Off here' },
89
- watch: { idle: 'Watch', active: 'Watching', pending: 'Requested', disabled: 'Off here' },
90
- };
63
+ import { type FollowLabels, type FollowVerb, useFollowLabels } from './followLabels';
64
+ import { useI18n } from '../hooks/useI18n';
91
65
 
92
66
  const HOUR = 60 * 60;
93
67
 
94
68
  /**
95
69
  * Defaults chosen for the cases a timed follow is actually for: a live event
96
70
  * tonight, a story running this week. Not a general-purpose duration picker —
97
- * an application that needs one passes its own.
71
+ * an application that needs one passes its own. Labels are catalog keys, read
72
+ * at render in the app's language.
98
73
  */
99
- const DEFAULT_DURATIONS: FollowDuration[] = [
100
- { label: '24 hours', seconds: 24 * HOUR },
101
- { label: '72 hours', seconds: 72 * HOUR },
102
- { label: 'A week', seconds: 7 * 24 * HOUR },
103
- ];
74
+ const DEFAULT_DURATIONS = [
75
+ { key: 'follow.durations.day', seconds: 24 * HOUR },
76
+ { key: 'follow.durations.threeDays', seconds: 72 * HOUR },
77
+ { key: 'follow.durations.week', seconds: 7 * 24 * HOUR },
78
+ ] as const;
104
79
 
105
80
  export interface FollowTargetButtonProps {
106
81
  /** The registered target's id. Registration is separate — see the SDK. */
107
82
  targetId: string;
108
83
  verb?: FollowVerb;
109
- /** Full override, for a verb the vocabulary above does not carry. */
84
+ /** Full override, for a verb the vocabulary does not carry. */
110
85
  labels?: Partial<FollowLabels>;
111
86
  size?: 'sm' | 'md' | 'lg';
112
87
  style?: StyleProp<ViewStyle>;
@@ -118,7 +93,8 @@ export interface FollowTargetButtonProps {
118
93
  showOptions?: boolean;
119
94
  /**
120
95
  * Offer timed follows. Pass `false` where a temporary follow makes no sense —
121
- * a store you buy from, an account you know.
96
+ * a store you buy from, an account you know. Default: 24 hours, 72 hours and
97
+ * a week, translated.
122
98
  */
123
99
  durations?: FollowDuration[] | false;
124
100
  /**
@@ -156,7 +132,7 @@ export const FollowTargetButton = memo(function FollowTargetButton({
156
132
  style,
157
133
  disabled = false,
158
134
  showOptions = true,
159
- durations = DEFAULT_DURATIONS,
135
+ durations,
160
136
  applicationName,
161
137
  initialStatus,
162
138
  onChange,
@@ -164,13 +140,18 @@ export const FollowTargetButton = memo(function FollowTargetButton({
164
140
  const { status, isFollowing, isUnknown, isPending, follow, unfollow, disableHere, enableHere } =
165
141
  useFollowTarget(targetId, { initialStatus });
166
142
 
143
+ const { t } = useI18n();
144
+ const text = useFollowLabels(verb, labels);
145
+
146
+ const timedChoices = useMemo<FollowDuration[] | false>(
147
+ () => durations ?? DEFAULT_DURATIONS.map(({ key, seconds }) => ({ label: t(key), seconds })),
148
+ [durations, t],
149
+ );
150
+
167
151
  const reportMutationFailure = useCallback(() => {
168
- const message =
169
- useFollowTargetStore.getState().errors[targetId] ?? 'Could not update follow status';
152
+ const message = useFollowTargetStore.getState().errors[targetId] ?? t('follow.errors.update');
170
153
  toast.error(message);
171
- }, [targetId]);
172
-
173
- const text = useMemo(() => ({ ...VERB_LABELS[verb], ...labels }), [verb, labels]);
154
+ }, [targetId, t]);
174
155
 
175
156
  const label = useMemo(() => {
176
157
  if (status.globalState === 'requested') return text.pending;
@@ -224,9 +205,9 @@ export const FollowTargetButton = memo(function FollowTargetButton({
224
205
  // The confirmation is the point: a follow that ends on its own is a
225
206
  // promise, and a user who does not see it made will not believe it.
226
207
  // Which is also why it must not appear when the promise was not made.
227
- toast.success(`Following for ${durationLabel.toLowerCase()}`);
208
+ toast.success(t('follow.menu.forDuration', { label: text.active, duration: durationLabel }));
228
209
  },
229
- [follow, onChange, reportMutationFailure],
210
+ [follow, onChange, reportMutationFailure, t, text.active],
230
211
  );
231
212
 
232
213
  const menuItems = useMemo(
@@ -236,18 +217,22 @@ export const FollowTargetButton = memo(function FollowTargetButton({
236
217
  applicationMode: status.applicationMode,
237
218
  hasRelationship: Boolean(status.relationshipId),
238
219
  isPending,
239
- durations,
220
+ durations: timedChoices,
240
221
  idleVerb: text.idle,
241
- applicationName: applicationName ?? 'this app',
222
+ applicationName: applicationName ?? t('follow.menu.thisApp'),
223
+ verb,
224
+ t,
242
225
  }),
243
226
  [
244
227
  isFollowing,
245
228
  status.applicationMode,
246
229
  status.relationshipId,
247
230
  isPending,
248
- durations,
231
+ timedChoices,
249
232
  text.idle,
250
233
  applicationName,
234
+ verb,
235
+ t,
251
236
  ],
252
237
  );
253
238
 
@@ -304,6 +289,8 @@ export const FollowTargetButton = memo(function FollowTargetButton({
304
289
  return <View style={style}>{primary}</View>;
305
290
  }
306
291
 
292
+ const optionsLabel = t('follow.menu.options', { label });
293
+
307
294
  return (
308
295
  <View style={[{ flexDirection: 'row', alignItems: 'center', gap: 4 }, style]}>
309
296
  {primary}
@@ -321,11 +308,11 @@ export const FollowTargetButton = memo(function FollowTargetButton({
321
308
  size={size === 'lg' ? 'lg' : 'sm'}
322
309
  icon={<ChevronDown width={16} />}
323
310
  disabled={disabled || isUnknown}
324
- accessibilityLabel={`${label} options`}
325
- accessibilityHint="Opens follow options"
311
+ accessibilityLabel={optionsLabel}
312
+ accessibilityHint={t('follow.menu.optionsHint')}
326
313
  />
327
314
  </DropdownMenuTrigger>
328
- <DropdownMenuContent label={`${label} options`}>
315
+ <DropdownMenuContent label={optionsLabel}>
329
316
  {menuItems.map((item) => (
330
317
  <DropdownMenuItem key={item.key} onPress={() => runItem(item)}>
331
318
  {item.label}
@@ -27,7 +27,7 @@ import { Avatar } from '@oxy.so/bloom/avatar';
27
27
  import { Button, LinkButton } from '@oxy.so/bloom/button';
28
28
  import { Text } from '@oxy.so/bloom/typography';
29
29
  import { useTheme } from '@oxy.so/bloom/theme';
30
- import { useI18n } from '../hooks/useI18n';
30
+ import { type Translate, useI18n } from '../hooks/useI18n';
31
31
  import { LogoIcon } from './logo/LogoIcon';
32
32
 
33
33
  /** The requesting application, resolved by the caller (never user-supplied raw). */
@@ -133,8 +133,6 @@ const SCOPE_LABEL_KEYS: Readonly<Record<string, string>> = {
133
133
  'federation:write': 'consent.scopes.federationWrite',
134
134
  };
135
135
 
136
- type Translate = ReturnType<typeof useI18n>['t'];
137
-
138
136
  /** One permission row of the "Permissions requested" list. */
139
137
  interface PermissionRow {
140
138
  /** Stable list key / testID suffix — the first scope that produced this row. */
@@ -9,6 +9,7 @@
9
9
  */
10
10
  import React from 'react';
11
11
  import { render } from '@testing-library/react';
12
+ import { translate } from '@oxy.so/core';
12
13
  import {
13
14
  describeFollowAllButton,
14
15
  describeFollowButton,
@@ -52,6 +53,7 @@ jest.mock('../../hooks/useFollow', () => ({
52
53
 
53
54
  jest.mock('../../context/oxyRuntimeContext', () => ({
54
55
  useOxy: () => ({ oxyServices: {}, canUsePrivateApi: true, user: { id: 'viewer' } }),
56
+ useOptionalOxy: () => null,
55
57
  }));
56
58
 
57
59
  let mockTarget = {
@@ -73,8 +75,16 @@ jest.mock('../../hooks/useFollowTarget', () => ({
73
75
  import { FollowButton } from '../FollowButton';
74
76
  import { FollowTargetButton } from '../FollowTargetButton';
75
77
 
78
+ const t = (key: string, vars?: Record<string, string | number>) => translate('en-US', key, vars);
79
+
76
80
  describe('describeFollowButton', () => {
77
- const known = { isKnown: true, isPending: false, username: 'nate' };
81
+ const known = {
82
+ isKnown: true,
83
+ isPending: false,
84
+ username: 'nate',
85
+ verb: 'follow' as const,
86
+ labels: { idle: 'Follow', active: 'Following' },
87
+ };
78
88
 
79
89
  it.each([
80
90
  [{ ...known, isFollowing: true }, 'Following @nate', 'Unfollows @nate'],
@@ -94,7 +104,7 @@ describe('describeFollowButton', () => {
94
104
  undefined,
95
105
  ],
96
106
  ])('%o reads "%s"', (input, label, hint) => {
97
- expect(describeFollowButton(input)).toEqual(
107
+ expect(describeFollowButton(input, t)).toEqual(
98
108
  hint ? { accessibilityLabel: label, accessibilityHint: hint } : { accessibilityLabel: label },
99
109
  );
100
110
  });
@@ -112,22 +122,22 @@ describe('describeFollowAllButton', () => {
112
122
 
113
123
  it('names the state and counts the accounts in the hint', () => {
114
124
  expect(
115
- describeFollowAllButton({ ...labels, allFollowing: false, isPending: false, count: 3 }),
125
+ describeFollowAllButton({ ...labels, allFollowing: false, isPending: false, count: 3 }, t),
116
126
  ).toEqual({
117
127
  accessibilityLabel: 'Follow all',
118
128
  accessibilityHint: 'Follows all 3 accounts',
119
129
  });
120
130
  expect(
121
- describeFollowAllButton({ ...labels, allFollowing: true, isPending: false, count: 1 }),
131
+ describeFollowAllButton({ ...labels, allFollowing: true, isPending: false, count: 1 }, t),
122
132
  ).toEqual({
123
133
  accessibilityLabel: 'Following',
124
- accessibilityHint: 'Unfollows all 1 account',
134
+ accessibilityHint: 'Unfollows 1 account',
125
135
  });
126
136
  });
127
137
 
128
138
  it('drops the hint while the bulk write is in flight', () => {
129
139
  expect(
130
- describeFollowAllButton({ ...labels, allFollowing: true, isPending: true, count: 3 }),
140
+ describeFollowAllButton({ ...labels, allFollowing: true, isPending: true, count: 3 }, t),
131
141
  ).toEqual({
132
142
  accessibilityLabel: 'Following',
133
143
  });
@@ -178,6 +188,22 @@ describe('FollowButton hands Bloom a name that follows the state', () => {
178
188
  });
179
189
  });
180
190
 
191
+ it('reads its verb: "Join" and "Joined", named and hinted to match', () => {
192
+ mockFollowState = { isFollowing: false, isKnown: true, isLoading: false };
193
+ render(<FollowButton userId="c-id" username="fediverse" verb="join" />);
194
+ expect(lastBloomProps()).toMatchObject({
195
+ label: 'Join',
196
+ followingLabel: 'Joined',
197
+ accessibilityLabel: 'Join @fediverse',
198
+ });
199
+ mockFollowState = { isFollowing: true, isKnown: true, isLoading: false };
200
+ render(<FollowButton userId="c-id" username="fediverse" verb="join" />);
201
+ expect(lastBloomProps()).toMatchObject({
202
+ accessibilityLabel: 'Joined @fediverse',
203
+ accessibilityHint: 'Leaves @fediverse',
204
+ });
205
+ });
206
+
181
207
  it('names the "Follow all" button by its state too', () => {
182
208
  mockMulti = { allFollowing: true, isAnyLoading: false };
183
209
  render(<FollowButton userIds={['a', 'b']} />);
@@ -28,7 +28,7 @@ import {
28
28
 
29
29
  const DURATIONS = [
30
30
  { label: '24 hours', seconds: 86400 },
31
- { label: 'A week', seconds: 604800 },
31
+ { label: 'a week', seconds: 604800 },
32
32
  ];
33
33
 
34
34
  const base = {
@@ -97,6 +97,12 @@ describe('buildFollowMenuItems', () => {
97
97
  expect(buildFollowMenuItems(following)[0].label).toBe('Don’t show in Mention');
98
98
  });
99
99
 
100
+ it('words "everywhere" with the button’s verb', () => {
101
+ expect(buildFollowMenuItems({ ...following, verb: 'join' })[1].label).toBe(
102
+ 'Leave everywhere',
103
+ );
104
+ });
105
+
100
106
  it('offers turning it back on once it is off here', () => {
101
107
  const items = buildFollowMenuItems({ ...following, applicationMode: 'disabled' });
102
108
  expect(keys(items)).toEqual(['enable-here', 'unfollow-everywhere']);
@@ -11,10 +11,9 @@ import { APP_COLOR_NAMES } from '@oxy.so/bloom/color-presets';
11
11
  import type { AccountStorageUsageResponse } from '@oxy.so/core';
12
12
  import { APP_COLOR_PRESETS, type useTheme } from '@oxy.so/bloom/theme';
13
13
  import type { AccountDialogMenuSection } from '../../navigation/accountDialogManager';
14
- import type { useI18n } from '../../hooks/useI18n';
15
14
 
16
15
  export type Theme = ReturnType<typeof useTheme>;
17
- export type Translate = ReturnType<typeof useI18n>['t'];
16
+ export type { Translate } from '../../hooks/useI18n';
18
17
 
19
18
  /**
20
19
  * One SUBORDINATE action on a sign-in surface — an alternative revealed behind
@@ -8,10 +8,16 @@
8
8
  * (OxyHQ/oxy#1375 item 22). The name now says the state, and who it is for
9
9
  * when the caller knows the handle.
10
10
  *
11
+ * The words follow the button's verb ("Joined @fediverse", hinted "Leaves
12
+ * @fediverse") and its language: every string is `@oxy.so/core`'s `follow.*`.
13
+ *
11
14
  * Pure, and kept apart from the components, so every state is pinned by a
12
15
  * table test rather than by a render that can only see one state at a time.
13
16
  */
14
17
 
18
+ import type { Translate } from '../hooks/useI18n';
19
+ import type { FollowLabels, FollowVerb } from './followLabels';
20
+
15
21
  export interface FollowButtonAccessibility {
16
22
  accessibilityLabel: string;
17
23
  accessibilityHint?: string;
@@ -33,36 +39,40 @@ export function formatHandle(username: string | undefined): string | undefined {
33
39
  * because a press does nothing until the write settles.
34
40
  * - Following: "Following @nate", hinted "Unfollows @nate", because pressing
35
41
  * it unfollows, which the visible "Following" does not say.
42
+ *
43
+ * The name is the visible label (the caller's, when it passed `labels`) beside
44
+ * the handle; the checking line and the hint are the verb's.
36
45
  */
37
- export function describeFollowButton(input: {
38
- isKnown: boolean;
39
- isFollowing: boolean;
40
- isPending: boolean;
41
- username?: string;
42
- }): FollowButtonAccessibility {
46
+ export function describeFollowButton(
47
+ input: {
48
+ isKnown: boolean;
49
+ isFollowing: boolean;
50
+ isPending: boolean;
51
+ username?: string;
52
+ verb: FollowVerb;
53
+ labels: Pick<FollowLabels, 'idle' | 'active'>;
54
+ },
55
+ t: Translate,
56
+ ): FollowButtonAccessibility {
43
57
  const handle = formatHandle(input.username);
58
+ const words = `follow.verbs.${input.verb}`;
44
59
 
45
60
  if (!input.isKnown) {
46
61
  return {
47
62
  accessibilityLabel: handle
48
- ? `Checking whether you follow ${handle}`
49
- : 'Checking follow status',
63
+ ? t(`${words}.checkingNamed`, { name: handle })
64
+ : t(`${words}.checking`),
50
65
  };
51
66
  }
52
67
 
53
- const accessibilityLabel = input.isFollowing
54
- ? handle
55
- ? `Following ${handle}`
56
- : 'Following'
57
- : handle
58
- ? `Follow ${handle}`
59
- : 'Follow';
68
+ const label = input.isFollowing ? input.labels.active : input.labels.idle;
69
+ const accessibilityLabel = handle ? t('follow.named', { label, name: handle }) : label;
60
70
 
61
71
  if (input.isPending || !input.isFollowing) return { accessibilityLabel };
62
72
 
63
73
  return {
64
74
  accessibilityLabel,
65
- accessibilityHint: handle ? `Unfollows ${handle}` : 'Unfollows this account',
75
+ accessibilityHint: handle ? t(`${words}.undoNamed`, { name: handle }) : t(`${words}.undo`),
66
76
  };
67
77
  }
68
78
 
@@ -70,18 +80,21 @@ export function describeFollowButton(input: {
70
80
  * The "Follow all" button. The labels are the caller's, since a starter pack
71
81
  * and a feed's member list word it differently; the hint carries the count.
72
82
  */
73
- export function describeFollowAllButton(input: {
74
- allFollowing: boolean;
75
- isPending: boolean;
76
- count: number;
77
- followAllLabel: string;
78
- followedAllLabel: string;
79
- }): FollowButtonAccessibility {
83
+ export function describeFollowAllButton(
84
+ input: {
85
+ allFollowing: boolean;
86
+ isPending: boolean;
87
+ count: number;
88
+ followAllLabel: string;
89
+ followedAllLabel: string;
90
+ },
91
+ t: Translate,
92
+ ): FollowButtonAccessibility {
80
93
  const accessibilityLabel = input.allFollowing ? input.followedAllLabel : input.followAllLabel;
81
94
  if (input.isPending) return { accessibilityLabel };
82
- const accounts = input.count === 1 ? '1 account' : `${input.count} accounts`;
95
+ const hint = input.allFollowing ? 'follow.all.undoHint' : 'follow.all.hint';
83
96
  return {
84
97
  accessibilityLabel,
85
- accessibilityHint: input.allFollowing ? `Unfollows all ${accounts}` : `Follows all ${accounts}`,
98
+ accessibilityHint: t(input.count === 1 ? `${hint}One` : hint, { count: input.count }),
86
99
  };
87
100
  }
@@ -0,0 +1,48 @@
1
+ /**
2
+ * The words on a follow button, for every verb the ecosystem uses.
3
+ *
4
+ * "Follow" is wrong for half the things an Oxy user can follow: you subscribe
5
+ * to a channel, you join a community, you watch a listing. Both follow buttons
6
+ * read their words here, translated through `@oxy.so/core`'s `follow.*`
7
+ * strings, so a verb reads the same — and in the same language — wherever it is
8
+ * drawn.
9
+ */
10
+
11
+ import { useMemo } from 'react';
12
+ import { useI18n } from '../hooks/useI18n';
13
+
14
+ /**
15
+ * The small vocabulary of verbs the ecosystem actually uses. An application
16
+ * whose verb is not here passes `labels` instead — the escape hatch exists so
17
+ * this union never has to grow to accommodate one product's wording.
18
+ */
19
+ export type FollowVerb = 'follow' | 'subscribe' | 'join' | 'watch';
20
+
21
+ export interface FollowLabels {
22
+ /** Not following yet. */
23
+ idle: string;
24
+ /** Following, and this application acts on it. */
25
+ active: string;
26
+ /** Asked, waiting for the other side to accept. */
27
+ pending: string;
28
+ /** Following globally, but switched off in this application. */
29
+ disabled: string;
30
+ }
31
+
32
+ /** The labels for `verb` in the current language, with the caller's `overrides` on top. */
33
+ export function useFollowLabels(
34
+ verb: FollowVerb = 'follow',
35
+ overrides?: Partial<FollowLabels>,
36
+ ): FollowLabels {
37
+ const { t } = useI18n();
38
+ return useMemo(
39
+ () => ({
40
+ idle: t(`follow.verbs.${verb}.idle`),
41
+ active: t(`follow.verbs.${verb}.active`),
42
+ pending: t('follow.pending'),
43
+ disabled: t('follow.disabled'),
44
+ ...overrides,
45
+ }),
46
+ [t, verb, overrides],
47
+ );
48
+ }
@@ -5,16 +5,26 @@
5
5
  * application drawing its own affordance (a chip grid, a compact row) imports
6
6
  * them from here — through `@oxy.so/services/ui/client` — without paying for the
7
7
  * button's dropdown menu.
8
+ *
9
+ * The menu's words are `@oxy.so/core`'s `follow.*` strings, read through the
10
+ * caller's `t`; without one they are English.
8
11
  */
9
12
 
10
13
  import type { FollowApplicationMode } from '@oxy.so/contracts';
14
+ import { translate } from '@oxy.so/core';
15
+ import type { Translate } from '../hooks/useI18n';
16
+ import type { FollowVerb } from './followLabels';
11
17
 
12
18
  /** A timed-follow choice offered in the menu. */
13
19
  export interface FollowDuration {
20
+ /** The duration as it reads inside a sentence: "24 hours", "a week". */
14
21
  label: string;
15
22
  seconds: number;
16
23
  }
17
24
 
25
+ /** The fallback language for a caller that passes no translator. */
26
+ const english: Translate = (key, vars) => translate(undefined, key, vars);
27
+
18
28
  /**
19
29
  * Whether an action leaves the target ACTIVE in this application.
20
30
  *
@@ -50,15 +60,6 @@ export interface FollowMenuItem {
50
60
  | { type: 'unfollow' };
51
61
  }
52
62
 
53
- /**
54
- * Which choices exist, given the state.
55
- *
56
- * Pure and exported because this is the product decision, not a rendering
57
- * detail: a timed follow is only offered before following, turning it off here
58
- * is only offered while following, and NEITHER is offered before the server has
59
- * answered — every one of them addresses a relationship that does not exist
60
- * yet, so offering them mid-write would mean sending a guessed id.
61
- */
62
63
  /**
63
64
  * What the main button should do for the current state.
64
65
  *
@@ -75,15 +76,30 @@ export function resolveFollowPrimaryAction(input: {
75
76
  return 'unfollow';
76
77
  }
77
78
 
79
+ /**
80
+ * Which choices exist, given the state.
81
+ *
82
+ * Pure and exported because this is the product decision, not a rendering
83
+ * detail: a timed follow is only offered before following, turning it off here
84
+ * is only offered while following, and NEITHER is offered before the server has
85
+ * answered — every one of them addresses a relationship that does not exist
86
+ * yet, so offering them mid-write would mean sending a guessed id.
87
+ */
78
88
  export function buildFollowMenuItems(input: {
79
89
  following: boolean;
80
90
  applicationMode: FollowApplicationMode;
81
91
  hasRelationship: boolean;
82
92
  isPending: boolean;
83
93
  durations: FollowDuration[] | false;
94
+ /** The button's idle label, which a timed choice starts with: "Follow for 24 hours". */
84
95
  idleVerb: string;
85
96
  applicationName: string;
97
+ /** Words the "everywhere" line with this verb: "Leave everywhere". Default `follow`. */
98
+ verb?: FollowVerb;
99
+ /** `useI18n().t`, for the menu in the app's language. Default English. */
100
+ t?: Translate;
86
101
  }): FollowMenuItem[] {
102
+ const t = input.t ?? english;
87
103
  const items: FollowMenuItem[] = [];
88
104
 
89
105
  if (!input.following) {
@@ -91,7 +107,7 @@ export function buildFollowMenuItems(input: {
91
107
  for (const d of input.durations) {
92
108
  items.push({
93
109
  key: `for-${d.seconds}`,
94
- label: `${input.idleVerb} for ${d.label.toLowerCase()}`,
110
+ label: t('follow.menu.forDuration', { label: input.idleVerb, duration: d.label }),
95
111
  action: { type: 'follow-timed', seconds: d.seconds, durationLabel: d.label },
96
112
  });
97
113
  }
@@ -104,12 +120,12 @@ export function buildFollowMenuItems(input: {
104
120
  input.applicationMode === 'disabled'
105
121
  ? {
106
122
  key: 'enable-here',
107
- label: `Show in ${input.applicationName}`,
123
+ label: t('follow.menu.showIn', { app: input.applicationName }),
108
124
  action: { type: 'enable-here' },
109
125
  }
110
126
  : {
111
127
  key: 'disable-here',
112
- label: `Don’t show in ${input.applicationName}`,
128
+ label: t('follow.menu.hideIn', { app: input.applicationName }),
113
129
  action: { type: 'disable-here' },
114
130
  },
115
131
  );
@@ -117,7 +133,7 @@ export function buildFollowMenuItems(input: {
117
133
  // Named for what it does. "Unfollow" beside "don't show here" would read as
118
134
  // the same action twice, and the user would pick the wrong one.
119
135
  key: 'unfollow-everywhere',
120
- label: 'Unfollow everywhere',
136
+ label: t(`follow.verbs.${input.verb ?? 'follow'}.everywhere`),
121
137
  action: { type: 'unfollow' },
122
138
  });
123
139
 
@@ -0,0 +1,52 @@
1
+ /**
2
+ * useAccountColor
3
+ *
4
+ * The account's colour is one value that every Oxy app wears: `users.color`, a
5
+ * Bloom preset NAME the API only stores after its entitlement check (`oxy` and
6
+ * `faircoin` belong to the account with that handle, `mono` to an active
7
+ * benefit). This hook is the single place an app turns that stored name into its
8
+ * Bloom theme, so two apps cannot disagree about which field wins.
9
+ *
10
+ * The portable `themePreference.colorPreset` is the fallback for an account that
11
+ * has no `color` yet. Mode (light/dark) is deliberately out of scope: whether to
12
+ * follow the account's mode is each app's own choice, the colour is not.
13
+ *
14
+ * An app with a stricter rule of its own (a plan the SDK cannot see) passes
15
+ * `canUse`; a name it refuses is simply not applied, so the app keeps its own
16
+ * default instead of a colour the viewer is not entitled to.
17
+ */
18
+
19
+ import { useEffect } from 'react';
20
+ import type { User } from '@oxy.so/core';
21
+ import { APP_COLOR_PRESETS, useBloomTheme, type AppColorName } from '@oxy.so/bloom/theme';
22
+ import { useAuth } from './useAuth';
23
+
24
+ function isAppColorName(value: unknown): value is AppColorName {
25
+ return (
26
+ typeof value === 'string' && Object.prototype.hasOwnProperty.call(APP_COLOR_PRESETS, value)
27
+ );
28
+ }
29
+
30
+ /** The preset an account wears, or `null` when it has none Bloom knows. */
31
+ export function resolveAccountColor(
32
+ user: Pick<User, 'color' | 'themePreference'> | null | undefined,
33
+ ): AppColorName | null {
34
+ const stored = user?.color ?? user?.themePreference?.colorPreset;
35
+ return isAppColorName(stored) ? stored : null;
36
+ }
37
+
38
+ export function useAccountColor({
39
+ canUse,
40
+ }: {
41
+ canUse?: (name: AppColorName) => boolean;
42
+ } = {}): void {
43
+ const { isAuthenticated, user } = useAuth();
44
+ const { colorPreset, setColorPreset } = useBloomTheme();
45
+ const accountColor = resolveAccountColor(user);
46
+ const allowed = accountColor !== null && (canUse?.(accountColor) ?? true);
47
+
48
+ useEffect(() => {
49
+ if (!isAuthenticated || !accountColor || !allowed || accountColor === colorPreset) return;
50
+ setColorPreset(accountColor);
51
+ }, [isAuthenticated, accountColor, allowed, colorPreset, setColorPreset]);
52
+ }
@@ -9,6 +9,9 @@ import { getLocalesVersion, subscribeLocales, translate } from '@oxy.so/core';
9
9
  */
10
10
  const FALLBACK_LOCALE = 'en-US';
11
11
 
12
+ /** `useI18n().t`: a key and its `{{placeholders}}` in, the current language's text out. */
13
+ export type Translate = (key: string, vars?: Record<string, string | number>) => string;
14
+
12
15
  /**
13
16
  * Display copy for SDK surfaces.
14
17
  *
@@ -32,9 +35,8 @@ export function useI18n() {
32
35
  getLocalesVersion,
33
36
  );
34
37
  // biome-ignore lint/correctness/useExhaustiveDependencies: `localesVersion` is the re-translate signal — a new `t` makes consumers re-render once a dictionary lands.
35
- const t = useMemo(() => {
36
- return (key: string, vars?: Record<string, string | number>) =>
37
- translate(currentLanguage, key, vars);
38
+ const t = useMemo<Translate>(() => {
39
+ return (key, vars) => translate(currentLanguage, key, vars);
38
40
  }, [currentLanguage, localesVersion]);
39
41
  return { t, locale: currentLanguage };
40
42
  }
@@ -1,6 +1,5 @@
1
1
  import { getNormalizedUserHandle, type DeviceLinkedSession } from '@oxy.so/core';
2
-
3
- type Translate = (key: string, vars?: Record<string, string | number>) => string;
2
+ import type { Translate } from '../hooks/useI18n';
4
3
 
5
4
  /**
6
5
  * The title of one row in "Sessions & devices".