@oxy.so/services 14.10.1 → 14.12.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 (160) hide show
  1. package/lib/commonjs/assets/assets/fonts/icons/OxyServicesIonicons.ttf +0 -0
  2. package/lib/commonjs/assets/assets/fonts/icons/OxyServicesMaterialCommunityIcons.ttf +0 -0
  3. package/lib/commonjs/assets/assets/fonts/icons/manifest.json +5 -4
  4. package/lib/commonjs/assets/fonts/icons/OxyServicesIonicons.ttf +0 -0
  5. package/lib/commonjs/assets/fonts/icons/OxyServicesMaterialCommunityIcons.ttf +0 -0
  6. package/lib/commonjs/assets/fonts/icons/manifest.json +5 -4
  7. package/lib/commonjs/index.js +10 -0
  8. package/lib/commonjs/index.js.map +1 -1
  9. package/lib/commonjs/ui/boot/runProviderColdBoot.js +3 -1
  10. package/lib/commonjs/ui/boot/runProviderColdBoot.js.map +1 -1
  11. package/lib/commonjs/ui/components/OxyProvider.js +52 -18
  12. package/lib/commonjs/ui/components/OxyProvider.js.map +1 -1
  13. package/lib/commonjs/ui/context/OxyContext.js +15 -5
  14. package/lib/commonjs/ui/context/OxyContext.js.map +1 -1
  15. package/lib/commonjs/ui/context/OxyHostedContext.js +515 -0
  16. package/lib/commonjs/ui/context/OxyHostedContext.js.map +1 -0
  17. package/lib/commonjs/ui/context/oxyRuntimeContext.js.map +1 -1
  18. package/lib/commonjs/ui/hooks/useAuth.js +13 -2
  19. package/lib/commonjs/ui/hooks/useAuth.js.map +1 -1
  20. package/lib/commonjs/ui/hooks/useOxyEvent.js +9 -5
  21. package/lib/commonjs/ui/hooks/useOxyEvent.js.map +1 -1
  22. package/lib/commonjs/ui/icons/subsetGlyphMaps.js +1 -0
  23. package/lib/commonjs/ui/icons/subsetGlyphMaps.js.map +1 -1
  24. package/lib/commonjs/ui/screens/EditProfileFieldScreen.js +16 -63
  25. package/lib/commonjs/ui/screens/EditProfileFieldScreen.js.map +1 -1
  26. package/lib/commonjs/ui/screens/ProfileLinkForm.js +125 -0
  27. package/lib/commonjs/ui/screens/ProfileLinkForm.js.map +1 -0
  28. package/lib/commonjs/ui/screens/ProfileLinksEditor.js +85 -0
  29. package/lib/commonjs/ui/screens/ProfileLinksEditor.js.map +1 -0
  30. package/lib/commonjs/ui/screens/linkFormat.js +22 -10
  31. package/lib/commonjs/ui/screens/linkFormat.js.map +1 -1
  32. package/lib/commonjs/ui/session/hostSession.js +474 -0
  33. package/lib/commonjs/ui/session/hostSession.js.map +1 -0
  34. package/lib/module/assets/assets/fonts/icons/OxyServicesIonicons.ttf +0 -0
  35. package/lib/module/assets/assets/fonts/icons/OxyServicesMaterialCommunityIcons.ttf +0 -0
  36. package/lib/module/assets/assets/fonts/icons/manifest.json +5 -4
  37. package/lib/module/assets/fonts/icons/OxyServicesIonicons.ttf +0 -0
  38. package/lib/module/assets/fonts/icons/OxyServicesMaterialCommunityIcons.ttf +0 -0
  39. package/lib/module/assets/fonts/icons/manifest.json +5 -4
  40. package/lib/module/index.js +3 -0
  41. package/lib/module/index.js.map +1 -1
  42. package/lib/module/ui/boot/runProviderColdBoot.js +3 -1
  43. package/lib/module/ui/boot/runProviderColdBoot.js.map +1 -1
  44. package/lib/module/ui/components/OxyProvider.js +53 -19
  45. package/lib/module/ui/components/OxyProvider.js.map +1 -1
  46. package/lib/module/ui/context/OxyContext.js +15 -5
  47. package/lib/module/ui/context/OxyContext.js.map +1 -1
  48. package/lib/module/ui/context/OxyHostedContext.js +510 -0
  49. package/lib/module/ui/context/OxyHostedContext.js.map +1 -0
  50. package/lib/module/ui/context/oxyRuntimeContext.js.map +1 -1
  51. package/lib/module/ui/hooks/useAuth.js +13 -2
  52. package/lib/module/ui/hooks/useAuth.js.map +1 -1
  53. package/lib/module/ui/hooks/useOxyEvent.js +9 -5
  54. package/lib/module/ui/hooks/useOxyEvent.js.map +1 -1
  55. package/lib/module/ui/icons/subsetGlyphMaps.js +1 -0
  56. package/lib/module/ui/icons/subsetGlyphMaps.js.map +1 -1
  57. package/lib/module/ui/screens/EditProfileFieldScreen.js +17 -65
  58. package/lib/module/ui/screens/EditProfileFieldScreen.js.map +1 -1
  59. package/lib/module/ui/screens/ProfileLinkForm.js +121 -0
  60. package/lib/module/ui/screens/ProfileLinkForm.js.map +1 -0
  61. package/lib/module/ui/screens/ProfileLinksEditor.js +81 -0
  62. package/lib/module/ui/screens/ProfileLinksEditor.js.map +1 -0
  63. package/lib/module/ui/screens/linkFormat.js +21 -9
  64. package/lib/module/ui/screens/linkFormat.js.map +1 -1
  65. package/lib/module/ui/session/hostSession.js +467 -0
  66. package/lib/module/ui/session/hostSession.js.map +1 -0
  67. package/lib/typescript/commonjs/index.d.ts +1 -0
  68. package/lib/typescript/commonjs/index.d.ts.map +1 -1
  69. package/lib/typescript/commonjs/ui/boot/runProviderColdBoot.d.ts +6 -0
  70. package/lib/typescript/commonjs/ui/boot/runProviderColdBoot.d.ts.map +1 -1
  71. package/lib/typescript/commonjs/ui/components/OxyProvider.d.ts.map +1 -1
  72. package/lib/typescript/commonjs/ui/context/OxyContext.d.ts.map +1 -1
  73. package/lib/typescript/commonjs/ui/context/OxyHostedContext.d.ts +40 -0
  74. package/lib/typescript/commonjs/ui/context/OxyHostedContext.d.ts.map +1 -0
  75. package/lib/typescript/commonjs/ui/context/oxyContextTypes.d.ts +19 -2
  76. package/lib/typescript/commonjs/ui/context/oxyContextTypes.d.ts.map +1 -1
  77. package/lib/typescript/commonjs/ui/context/oxyRuntimeContext.d.ts +6 -0
  78. package/lib/typescript/commonjs/ui/context/oxyRuntimeContext.d.ts.map +1 -1
  79. package/lib/typescript/commonjs/ui/hooks/useAuth.d.ts +3 -0
  80. package/lib/typescript/commonjs/ui/hooks/useAuth.d.ts.map +1 -1
  81. package/lib/typescript/commonjs/ui/hooks/useOxyEvent.d.ts.map +1 -1
  82. package/lib/typescript/commonjs/ui/icons/Ionicons.d.ts +1 -1
  83. package/lib/typescript/commonjs/ui/icons/Ionicons.d.ts.map +1 -1
  84. package/lib/typescript/commonjs/ui/icons/subsetGlyphMaps.d.ts +1 -0
  85. package/lib/typescript/commonjs/ui/icons/subsetGlyphMaps.d.ts.map +1 -1
  86. package/lib/typescript/commonjs/ui/screens/EditProfileFieldScreen.d.ts.map +1 -1
  87. package/lib/typescript/commonjs/ui/screens/ProfileLinkForm.d.ts +18 -0
  88. package/lib/typescript/commonjs/ui/screens/ProfileLinkForm.d.ts.map +1 -0
  89. package/lib/typescript/commonjs/ui/screens/ProfileLinksEditor.d.ts +14 -0
  90. package/lib/typescript/commonjs/ui/screens/ProfileLinksEditor.d.ts.map +1 -0
  91. package/lib/typescript/commonjs/ui/screens/linkFormat.d.ts +14 -2
  92. package/lib/typescript/commonjs/ui/screens/linkFormat.d.ts.map +1 -1
  93. package/lib/typescript/commonjs/ui/session/hostSession.d.ts +69 -0
  94. package/lib/typescript/commonjs/ui/session/hostSession.d.ts.map +1 -0
  95. package/lib/typescript/commonjs/ui/types/navigation.d.ts +24 -1
  96. package/lib/typescript/commonjs/ui/types/navigation.d.ts.map +1 -1
  97. package/lib/typescript/commonjs/ui/utils/identityCrypto.d.ts +4 -0
  98. package/lib/typescript/commonjs/ui/utils/identityCrypto.d.ts.map +1 -1
  99. package/lib/typescript/module/index.d.ts +1 -0
  100. package/lib/typescript/module/index.d.ts.map +1 -1
  101. package/lib/typescript/module/ui/boot/runProviderColdBoot.d.ts +6 -0
  102. package/lib/typescript/module/ui/boot/runProviderColdBoot.d.ts.map +1 -1
  103. package/lib/typescript/module/ui/components/OxyProvider.d.ts.map +1 -1
  104. package/lib/typescript/module/ui/context/OxyContext.d.ts.map +1 -1
  105. package/lib/typescript/module/ui/context/OxyHostedContext.d.ts +40 -0
  106. package/lib/typescript/module/ui/context/OxyHostedContext.d.ts.map +1 -0
  107. package/lib/typescript/module/ui/context/oxyContextTypes.d.ts +19 -2
  108. package/lib/typescript/module/ui/context/oxyContextTypes.d.ts.map +1 -1
  109. package/lib/typescript/module/ui/context/oxyRuntimeContext.d.ts +6 -0
  110. package/lib/typescript/module/ui/context/oxyRuntimeContext.d.ts.map +1 -1
  111. package/lib/typescript/module/ui/hooks/useAuth.d.ts +3 -0
  112. package/lib/typescript/module/ui/hooks/useAuth.d.ts.map +1 -1
  113. package/lib/typescript/module/ui/hooks/useOxyEvent.d.ts.map +1 -1
  114. package/lib/typescript/module/ui/icons/Ionicons.d.ts +1 -1
  115. package/lib/typescript/module/ui/icons/Ionicons.d.ts.map +1 -1
  116. package/lib/typescript/module/ui/icons/subsetGlyphMaps.d.ts +1 -0
  117. package/lib/typescript/module/ui/icons/subsetGlyphMaps.d.ts.map +1 -1
  118. package/lib/typescript/module/ui/screens/EditProfileFieldScreen.d.ts.map +1 -1
  119. package/lib/typescript/module/ui/screens/ProfileLinkForm.d.ts +18 -0
  120. package/lib/typescript/module/ui/screens/ProfileLinkForm.d.ts.map +1 -0
  121. package/lib/typescript/module/ui/screens/ProfileLinksEditor.d.ts +14 -0
  122. package/lib/typescript/module/ui/screens/ProfileLinksEditor.d.ts.map +1 -0
  123. package/lib/typescript/module/ui/screens/linkFormat.d.ts +14 -2
  124. package/lib/typescript/module/ui/screens/linkFormat.d.ts.map +1 -1
  125. package/lib/typescript/module/ui/session/hostSession.d.ts +69 -0
  126. package/lib/typescript/module/ui/session/hostSession.d.ts.map +1 -0
  127. package/lib/typescript/module/ui/types/navigation.d.ts +24 -1
  128. package/lib/typescript/module/ui/types/navigation.d.ts.map +1 -1
  129. package/lib/typescript/module/ui/utils/identityCrypto.d.ts +4 -0
  130. package/lib/typescript/module/ui/utils/identityCrypto.d.ts.map +1 -1
  131. package/package.json +7 -7
  132. package/src/assets/fonts/icons/OxyServicesIonicons.ttf +0 -0
  133. package/src/assets/fonts/icons/OxyServicesMaterialCommunityIcons.ttf +0 -0
  134. package/src/assets/fonts/icons/manifest.json +5 -4
  135. package/src/index.ts +3 -0
  136. package/src/ui/boot/runProviderColdBoot.ts +12 -1
  137. package/src/ui/components/OxyProvider.tsx +77 -34
  138. package/src/ui/context/OxyContext.tsx +19 -4
  139. package/src/ui/context/OxyHostedContext.tsx +678 -0
  140. package/src/ui/context/oxyContextTypes.ts +21 -2
  141. package/src/ui/context/oxyRuntimeContext.ts +9 -1
  142. package/src/ui/hooks/useAuth.ts +13 -1
  143. package/src/ui/hooks/useOxyEvent.ts +8 -5
  144. package/src/ui/icons/subsetGlyphMaps.ts +1 -0
  145. package/src/ui/screens/EditProfileFieldScreen.tsx +19 -85
  146. package/src/ui/screens/ProfileLinkForm.tsx +131 -0
  147. package/src/ui/screens/ProfileLinksEditor.tsx +98 -0
  148. package/src/ui/screens/__tests__/linkFormat.test.ts +51 -8
  149. package/src/ui/screens/linkFormat.ts +28 -9
  150. package/src/ui/session/hostSession.ts +515 -0
  151. package/src/ui/types/navigation.ts +24 -1
  152. package/lib/commonjs/ui/screens/LinkListEditor.js +0 -105
  153. package/lib/commonjs/ui/screens/LinkListEditor.js.map +0 -1
  154. package/lib/module/ui/screens/LinkListEditor.js +0 -99
  155. package/lib/module/ui/screens/LinkListEditor.js.map +0 -1
  156. package/lib/typescript/commonjs/ui/screens/LinkListEditor.d.ts +0 -25
  157. package/lib/typescript/commonjs/ui/screens/LinkListEditor.d.ts.map +0 -1
  158. package/lib/typescript/module/ui/screens/LinkListEditor.d.ts +0 -25
  159. package/lib/typescript/module/ui/screens/LinkListEditor.d.ts.map +0 -1
  160. package/src/ui/screens/LinkListEditor.tsx +0 -113
@@ -17,6 +17,7 @@ import type {
17
17
  import type {
18
18
  AccountDialogController,
19
19
  AccountDialogView,
20
+ AuthStateStore,
20
21
  SessionClient,
21
22
  SessionMode,
22
23
  } from '@oxy.so/core/session';
@@ -39,8 +40,14 @@ import type { AccountQueriesConfig } from '../hooks/accountQueryPersistence';
39
40
  * The session is still installed on this device, and nothing about the
40
41
  * outcome may be presented as revoked. The error is also reported through
41
42
  * the provider's `onError`, as before.
43
+ * - `requested` — a platform holds the session (a session host, ADR 0058): the
44
+ * sign-out was handed to the platform, which decides whether to ask. The
45
+ * outcome arrives as the session changes; nothing is signed out yet.
42
46
  */
43
- export type LogoutResult = { status: 'signed-out' } | { status: 'failed'; error: unknown };
47
+ export type LogoutResult =
48
+ | { status: 'signed-out' }
49
+ | { status: 'failed'; error: unknown }
50
+ | { status: 'requested' };
44
51
 
45
52
  export interface OxyContextState {
46
53
  user: User | null;
@@ -169,8 +176,18 @@ export interface OxyContextState {
169
176
  storageKeyPrefix: string;
170
177
  clientId: string | null;
171
178
  oxyServices: OxyServices;
172
- /** Server-authoritative device session client. `null` before an `OxyProvider` is mounted. */
179
+ /**
180
+ * Server-authoritative device session client. `null` before an `OxyProvider`
181
+ * is mounted, and on a session host (ADR 0058), where the device is the
182
+ * platform's.
183
+ */
173
184
  sessionClient: SessionClient | null;
185
+ /**
186
+ * Subscribe to a named server-pushed socket event when the provider's socket
187
+ * is not `sessionClient`'s (a session host's user socket). `useOxyEvent`
188
+ * reads it; apps use `useOxyEvent`.
189
+ */
190
+ onServerEvent?: (event: string, listener: (payload: unknown) => void) => () => void;
174
191
  useFollow?: UseFollowHook;
175
192
  showBottomSheet?: (
176
193
  screenOrConfig: RouteName | { screen: RouteName; props?: Record<string, unknown> },
@@ -241,6 +258,8 @@ export interface OxyRuntimeProviderProps {
241
258
  onError?: (error: ApiError) => void;
242
259
  /** Storage instance owned by the public provider; internal composition seam. */
243
260
  platformStorage?: StorageInterface | null;
261
+ /** See `OxyProviderProps.authStateStore`. Read once, at mount. */
262
+ authStateStore?: AuthStateStore;
244
263
  /** See `OxyProviderProps.accountQueries`. Read once, at mount. */
245
264
  accountQueries?: AccountQueriesConfig;
246
265
  }
@@ -1,4 +1,5 @@
1
1
  import { createContext, useContext } from 'react';
2
+ import type { OxyHostRequest } from '@oxy.so/core/host';
2
3
  import type { OxyContextState } from './oxyContextTypes';
3
4
 
4
5
  export const OxyRuntimeContext = createContext<OxyContextState | null>(null);
@@ -55,7 +56,14 @@ export type OxyAuthActionsContextState = Pick<
55
56
  | 'showBottomSheet'
56
57
  | 'openAvatarPicker'
57
58
  | 'openAccountDialog'
58
- > & { ensureDeviceSessionLane: () => void | Promise<void> };
59
+ > & {
60
+ ensureDeviceSessionLane: () => void | Promise<void>;
61
+ /**
62
+ * Present only on a session host (ADR 0058): hands an action to the
63
+ * platform's own UI. `useAuth().signIn()` uses it instead of the dialog.
64
+ */
65
+ hostRequest?: (action: OxyHostRequest) => Promise<void>;
66
+ };
59
67
 
60
68
  export const OxyAuthActionsContext = createContext<OxyAuthActionsContextState | null>(null);
61
69
 
@@ -84,6 +84,9 @@ export interface AuthActions {
84
84
  * Sign in
85
85
  * - Web + native: opens the in-app Oxy account dialog (`openAccountDialog('signin')`).
86
86
  * Never navigates to auth.oxy.so — that origin is third-party OAuth only.
87
+ * - On a platform that holds the session (a session host, ADR 0058): asks
88
+ * the platform's own sign-in and resolves `dialog-opened`; the account
89
+ * arrives as the session changes.
87
90
  *
88
91
  * @param publicKey - Native: identity public key. Ignored on web.
89
92
  */
@@ -183,6 +186,7 @@ export function useAuth(): UseAuthReturn {
183
186
  openAvatarPicker,
184
187
  openAccountDialog,
185
188
  ensureDeviceSessionLane,
189
+ hostRequest,
186
190
  } = useOxyAuthActions();
187
191
 
188
192
  const bearerSubject = useKnownBearerSubject(oxyServices);
@@ -190,6 +194,12 @@ export function useAuth(): UseAuthReturn {
190
194
 
191
195
  const signIn = useCallback(
192
196
  async (publicKey?: string): Promise<SignInOutcome> => {
197
+ // A platform holds the session (ADR 0058): its own sign-in UI, never this
198
+ // app's, and never a key of this app's.
199
+ if (hostRequest) {
200
+ await hostRequest('sign_in');
201
+ return { status: 'dialog-opened' };
202
+ }
193
203
  const classification = ensureDeviceSessionLane();
194
204
  if (classification) await classification;
195
205
  // Native: sign in directly with the cryptographic identity when a public key
@@ -215,10 +225,12 @@ export function useAuth(): UseAuthReturn {
215
225
  openAccountDialog('signin');
216
226
  return { status: 'dialog-opened' };
217
227
  },
218
- [oxySignIn, hasIdentity, getPublicKey, openAccountDialog, ensureDeviceSessionLane],
228
+ [oxySignIn, hasIdentity, getPublicKey, openAccountDialog, ensureDeviceSessionLane, hostRequest],
219
229
  );
220
230
 
221
231
  const signOut = useCallback(async (): Promise<void> => {
232
+ // `requested` (a session host) resolves: the platform decides, and its
233
+ // answer arrives as the session changes.
222
234
  const result = await logout();
223
235
  if (result.status === 'failed') throw result.error;
224
236
  }, [logout]);
@@ -9,14 +9,17 @@ import { useOxy } from '../context/oxyRuntimeContext';
9
9
  * is always invoked.
10
10
  */
11
11
  export function useOxyEvent(event: string, handler: (payload: unknown) => void): void {
12
- const { sessionClient } = useOxy();
12
+ const { sessionClient, onServerEvent } = useOxy();
13
13
  const handlerRef = useRef(handler);
14
14
  handlerRef.current = handler;
15
15
 
16
16
  useEffect(() => {
17
- if (!sessionClient) return;
18
- return sessionClient.onServerEvent(event, (payload) => {
17
+ const listener = (payload: unknown) => {
19
18
  handlerRef.current(payload);
20
- });
21
- }, [sessionClient, event]);
19
+ };
20
+ // A session host's user socket, else the device session's socket.
21
+ if (onServerEvent) return onServerEvent(event, listener);
22
+ if (!sessionClient) return;
23
+ return sessionClient.onServerEvent(event, listener);
24
+ }, [sessionClient, onServerEvent, event]);
22
25
  }
@@ -111,6 +111,7 @@ export const ioniconsGlyphMap = {
111
111
  "repeat-outline": 62768,
112
112
  "resize": 62770,
113
113
  "rocket": 62791,
114
+ "save": 62800,
114
115
  "scale": 62803,
115
116
  "school-outline": 62813,
116
117
  "search": 62815,
@@ -33,17 +33,9 @@ import { useOxy } from '../context/oxyRuntimeContext';
33
33
  import { useProfileEditing } from '../hooks/useProfileEditing';
34
34
  import { toast } from '@oxy.so/bloom/toast';
35
35
  import { accountNameInvalidKey, accountNameInvalidMessage, isValidAccountName } from '@oxy.so/core';
36
- import {
37
- getLinkTitle,
38
- getLinkDescription,
39
- linkIdentity,
40
- linksToListItems,
41
- normalizeLinkInput,
42
- type LinkInputError,
43
- } from './linkFormat';
44
- import { LinkListEditor } from './LinkListEditor';
36
+ import { getLinkTitle, getLinkDescription, linksToListItems } from './linkFormat';
37
+ import { ProfileLinksEditor } from './ProfileLinksEditor';
45
38
  import type { LinkListItem } from './linkFormat';
46
- import { PROFILE_LINKS_MAX } from '@oxy.so/contracts/client';
47
39
 
48
40
  /**
49
41
  * Field types supported by EditProfileFieldScreen
@@ -221,7 +213,6 @@ const EditProfileFieldScreen: React.FC<EditProfileFieldScreenProps> = ({
221
213
  () => buildInitialProfileState(user, fieldType).listItems,
222
214
  );
223
215
  const [newItemValue, setNewItemValue] = useState('');
224
- const [linkInputError, setLinkInputError] = useState<LinkInputError | null>(null);
225
216
 
226
217
  const [phoneCountry, setPhoneCountry] = useState(() => {
227
218
  const phone = fieldValues.phone?.replace(/[\s()-]/g, '') || '';
@@ -453,32 +444,9 @@ const EditProfileFieldScreen: React.FC<EditProfileFieldScreenProps> = ({
453
444
  name: newItemValue.trim(),
454
445
  };
455
446
  setListItems((prev) => [...prev, newItem]);
456
- } else if (fieldType === 'links') {
457
- if (listItems.length >= PROFILE_LINKS_MAX) {
458
- setLinkInputError('limit');
459
- return;
460
- }
461
- const result = normalizeLinkInput(newItemValue);
462
- if ('error' in result) {
463
- setLinkInputError(result.error);
464
- return;
465
- }
466
- const identity = linkIdentity(result.url);
467
- if (listItems.some((item) => linkIdentity(String(item.url || '')) === identity)) {
468
- setLinkInputError('already-added');
469
- return;
470
- }
471
- const newItem = {
472
- id: `link-${Date.now()}`,
473
- url: result.url,
474
- title: getLinkTitle(result.url),
475
- description: getLinkDescription(result.url),
476
- };
477
- setListItems((prev) => [...prev, newItem]);
478
- setLinkInputError(null);
479
447
  }
480
448
  setNewItemValue('');
481
- }, [newItemValue, fieldType, listItems]);
449
+ }, [newItemValue, fieldType]);
482
450
 
483
451
  // Remove item from list
484
452
  const handleRemoveItem = useCallback((id: string) => {
@@ -704,36 +672,24 @@ const EditProfileFieldScreen: React.FC<EditProfileFieldScreenProps> = ({
704
672
  );
705
673
  };
706
674
 
707
- const linkInputErrorMessage = (error: LinkInputError): string => {
708
- switch (error) {
709
- case 'empty':
710
- return t('editProfile.items.links.errors.empty') || 'Enter a link.';
711
- case 'insecure':
712
- return t('editProfile.items.links.errors.insecure') || 'Links must start with https://.';
713
- case 'already-added':
714
- return (
715
- t('editProfile.items.links.errors.duplicate') || 'That link is already on your profile.'
716
- );
717
- case 'limit':
718
- return (
719
- t('editProfile.items.links.errors.limit', { count: PROFILE_LINKS_MAX }) ||
720
- `You can add up to ${PROFILE_LINKS_MAX} links.`
721
- );
722
- default:
723
- return t('editProfile.items.links.errors.invalid') || 'Enter a valid link.';
675
+ // Links are edited as chips (reorder, add, edit); locations stay a text list.
676
+ const renderListContent = () => {
677
+ if (fieldType === 'links') {
678
+ return (
679
+ <GroupedSection
680
+ title={`${t('editProfile.items.links.yourLinks') || 'Your Links'} (${listItems.length})`}
681
+ >
682
+ <ProfileLinksEditor
683
+ items={listItems as LinkListItem[]}
684
+ onChange={(items) => setListItems(items as EditableListItem[])}
685
+ disabled={isSaving}
686
+ />
687
+ </GroupedSection>
688
+ );
724
689
  }
725
- };
726
690
 
727
- // Render list content (locations or links)
728
- const renderListContent = () => {
729
- const addLabel =
730
- fieldType === 'locations'
731
- ? t('editProfile.items.locations.add') || 'Add Location'
732
- : t('editProfile.items.links.add') || 'Add Link';
733
- const listTitle =
734
- fieldType === 'locations'
735
- ? t('editProfile.items.locations.yourLocations') || 'Your Locations'
736
- : t('editProfile.items.links.yourLinks') || 'Your Links';
691
+ const addLabel = t('editProfile.items.locations.add') || 'Add Location';
692
+ const listTitle = t('editProfile.items.locations.yourLocations') || 'Your Locations';
737
693
 
738
694
  return (
739
695
  <>
@@ -749,7 +705,6 @@ const EditProfileFieldScreen: React.FC<EditProfileFieldScreenProps> = ({
749
705
  autoCorrect={false}
750
706
  onSubmitEditing={handleAddItem}
751
707
  returnKeyType="done"
752
- keyboardType={fieldType === 'links' ? 'url' : 'default'}
753
708
  />
754
709
  </TextField>
755
710
  </View>
@@ -764,27 +719,6 @@ const EditProfileFieldScreen: React.FC<EditProfileFieldScreenProps> = ({
764
719
  />
765
720
  </View>
766
721
 
767
- {fieldType === 'links' && linkInputError && (
768
- <TextFieldHint>{linkInputErrorMessage(linkInputError)}</TextFieldHint>
769
- )}
770
-
771
- {fieldType === 'links' && listItems.length > 0 && (
772
- <GroupedSection title={`${listTitle} (${listItems.length})`}>
773
- <LinkListEditor
774
- items={listItems as LinkListItem[]}
775
- onChange={(items) => setListItems(items as EditableListItem[])}
776
- disabled={isSaving}
777
- labels={{
778
- title: t('editProfile.items.links.linkTitle') || 'Title',
779
- moveUp: t('editProfile.items.links.moveUp') || 'Move up',
780
- moveDown: t('editProfile.items.links.moveDown') || 'Move down',
781
- remove: t('common.remove') || 'Remove',
782
- removeNamed: (title) => `${t('common.remove') || 'Remove'} ${title}`,
783
- }}
784
- />
785
- </GroupedSection>
786
- )}
787
-
788
722
  {fieldType === 'locations' && listItems.length > 0 && (
789
723
  <GroupedSection title={`${listTitle} (${listItems.length})`}>
790
724
  {listItems.map((item) => (
@@ -0,0 +1,131 @@
1
+ import { useState } from 'react';
2
+ import { View } from 'react-native';
3
+ import { Button } from '@oxy.so/bloom/button';
4
+ import { Card } from '@oxy.so/bloom/card';
5
+ import { Field } from '@oxy.so/bloom/field';
6
+ import type { SurfaceControls } from '@oxy.so/bloom/surfaces';
7
+ import { TextField, TextFieldInput } from '@oxy.so/bloom/text-field';
8
+ import { PROFILE_LINK_TITLE_MAX } from '@oxy.so/contracts/client';
9
+ import { useI18n } from '../hooks/useI18n';
10
+ import {
11
+ clampLinkTitle,
12
+ linkIdentity,
13
+ normalizeLinkInput,
14
+ type LinkFormResult,
15
+ type LinkInputError,
16
+ type LinkListItem,
17
+ } from './linkFormat';
18
+
19
+ interface ProfileLinkFormProps {
20
+ /** The presenting surface (from `surfaces.present`); its dismiss result is the form's answer. */
21
+ surface: SurfaceControls;
22
+ /** The link being edited. Absent when adding one. */
23
+ link?: LinkListItem;
24
+ /** The addresses already on the profile, other than this link's own. */
25
+ existingUrls: readonly string[];
26
+ }
27
+
28
+ /**
29
+ * The form for one profile link: its address and an optional title. Saving
30
+ * dismisses the surface with the link to keep; removing dismisses it with a
31
+ * remove. A blank title is left blank, so the profile shows the address.
32
+ */
33
+ export function ProfileLinkForm({ surface, link, existingUrls }: ProfileLinkFormProps) {
34
+ const { t } = useI18n();
35
+ const [input, setInput] = useState(link?.url ?? '');
36
+ const [title, setTitle] = useState(link?.title ?? '');
37
+ const [error, setError] = useState<LinkInputError | null>(null);
38
+
39
+ const errorMessage = (kind: LinkInputError): string => {
40
+ switch (kind) {
41
+ case 'empty':
42
+ return t('editProfile.items.links.errors.empty') || 'Enter a link.';
43
+ case 'insecure':
44
+ return t('editProfile.items.links.errors.insecure') || 'Links must start with https://.';
45
+ case 'already-added':
46
+ return (
47
+ t('editProfile.items.links.errors.duplicate') || 'That link is already on your profile.'
48
+ );
49
+ default:
50
+ return t('editProfile.items.links.errors.invalid') || 'Enter a valid link.';
51
+ }
52
+ };
53
+
54
+ const save = () => {
55
+ const normalized = normalizeLinkInput(input);
56
+ if ('error' in normalized) {
57
+ setError(normalized.error);
58
+ return;
59
+ }
60
+ const identity = linkIdentity(normalized.url);
61
+ if (existingUrls.some((url) => linkIdentity(url) === identity)) {
62
+ setError('already-added');
63
+ return;
64
+ }
65
+ const result: LinkFormResult = {
66
+ kind: 'save',
67
+ url: normalized.url,
68
+ title: clampLinkTitle(title.trim()),
69
+ };
70
+ surface.dismiss(result);
71
+ };
72
+
73
+ const remove = () => {
74
+ const result: LinkFormResult = { kind: 'remove' };
75
+ surface.dismiss(result);
76
+ };
77
+
78
+ return (
79
+ <Card className="gap-space-16 p-space-16">
80
+ <Field
81
+ label={t('editProfile.items.links.form.urlLabel') || 'Link'}
82
+ error={error ? errorMessage(error) : undefined}
83
+ >
84
+ <TextField>
85
+ <TextFieldInput
86
+ label={t('editProfile.items.links.form.urlLabel') || 'Link'}
87
+ placeholder={t('editProfile.items.links.placeholder') || 'Enter URL'}
88
+ value={input}
89
+ onChangeText={(value: string) => {
90
+ setInput(value);
91
+ setError(null);
92
+ }}
93
+ autoCapitalize="none"
94
+ autoCorrect={false}
95
+ keyboardType="url"
96
+ isInvalid={error !== null}
97
+ autoFocus={!link}
98
+ />
99
+ </TextField>
100
+ </Field>
101
+ <Field label={t('editProfile.items.links.form.titleLabel') || 'Title'}>
102
+ <TextField>
103
+ <TextFieldInput
104
+ label={t('editProfile.items.links.form.titleLabel') || 'Title'}
105
+ placeholder={t('editProfile.items.links.form.titlePlaceholder') || 'Optional'}
106
+ value={title}
107
+ onChangeText={(value: string) => setTitle(clampLinkTitle(value))}
108
+ maxLength={PROFILE_LINK_TITLE_MAX}
109
+ />
110
+ </TextField>
111
+ </Field>
112
+ <View className="flex-row justify-between items-center gap-space-8">
113
+ {link ? (
114
+ <Button appearance="plain" tone="danger" onPress={remove}>
115
+ {t('editProfile.items.links.form.remove') || 'Remove'}
116
+ </Button>
117
+ ) : (
118
+ <View />
119
+ )}
120
+ <View className="flex-row gap-space-8">
121
+ <Button appearance="subtle" tone="neutral" onPress={() => surface.dismiss()}>
122
+ {t('common.cancel') || 'Cancel'}
123
+ </Button>
124
+ <Button appearance="solid" tone="accent" onPress={save}>
125
+ {t('common.save') || 'Save'}
126
+ </Button>
127
+ </View>
128
+ </View>
129
+ </Card>
130
+ );
131
+ }
@@ -0,0 +1,98 @@
1
+ import { View } from 'react-native';
2
+ import { Button } from '@oxy.so/bloom/button';
3
+ import { Chip } from '@oxy.so/bloom/chip';
4
+ import { SortableChipRow } from '@oxy.so/bloom/sortable-chip-row';
5
+ import { surfaces } from '@oxy.so/bloom/surfaces';
6
+ import { PROFILE_LINKS_MAX } from '@oxy.so/contracts/client';
7
+ import { useI18n } from '../hooks/useI18n';
8
+ import { ProfileLinkForm } from './ProfileLinkForm';
9
+ import {
10
+ applyLinkFormResult,
11
+ getLinkTitle,
12
+ type LinkFormResult,
13
+ type LinkListItem,
14
+ } from './linkFormat';
15
+
16
+ interface ProfileLinksEditorProps {
17
+ items: LinkListItem[];
18
+ onChange: (items: LinkListItem[]) => void;
19
+ disabled?: boolean;
20
+ }
21
+
22
+ let linkCounter = 0;
23
+ /** A fresh id for a link added in this editing session. */
24
+ const newLinkId = (): string => {
25
+ linkCounter += 1;
26
+ return `link-new-${Date.now().toString(36)}-${linkCounter}`;
27
+ };
28
+
29
+ /** The text a link's pill shows: its title, else its address without the scheme. */
30
+ const pillLabel = (item: LinkListItem): string => item.title || getLinkTitle(item.url);
31
+
32
+ /**
33
+ * The profile's links as pills, in the order they are shown, reordered by
34
+ * dragging. Tapping a pill edits that link; "Add link" appears until the profile
35
+ * holds the maximum. Changes stay local until the profile is saved.
36
+ */
37
+ export function ProfileLinksEditor({ items, onChange, disabled = false }: ProfileLinksEditorProps) {
38
+ const { t } = useI18n();
39
+
40
+ const openForm = async (index: number | null) => {
41
+ const link = index === null ? undefined : items[index];
42
+ const result = await surfaces.present<LinkFormResult | undefined>((surface) => (
43
+ <ProfileLinkForm
44
+ surface={surface}
45
+ link={link}
46
+ existingUrls={items.filter((_, i) => i !== index).map((item) => item.url)}
47
+ />
48
+ ));
49
+ if (!result) return;
50
+ onChange(applyLinkFormResult(items, index, result, PROFILE_LINKS_MAX, newLinkId));
51
+ };
52
+
53
+ const rowItems = items.map((item, index) => ({
54
+ key: item.id,
55
+ label: pillLabel(item),
56
+ node: (
57
+ <Chip
58
+ size="md"
59
+ variant="subtle"
60
+ accessibilityLabel={t('editProfile.items.links.editLink', {
61
+ defaultValue: 'Edit {{label}}',
62
+ label: pillLabel(item),
63
+ })}
64
+ onPress={() => void openForm(index)}
65
+ disabled={disabled}
66
+ >
67
+ {pillLabel(item)}
68
+ </Chip>
69
+ ),
70
+ }));
71
+
72
+ return (
73
+ <SortableChipRow
74
+ items={rowItems}
75
+ disabled={disabled}
76
+ onReorder={(keys) => {
77
+ const byKey = new Map(items.map((item) => [item.id, item]));
78
+ onChange(keys.flatMap((key) => (byKey.has(key) ? [byKey.get(key) as LinkListItem] : [])));
79
+ }}
80
+ accessibilityLabel={t('editProfile.items.links.title') || 'Links'}
81
+ trailing={
82
+ items.length < PROFILE_LINKS_MAX ? (
83
+ <View>
84
+ <Button
85
+ appearance="outline"
86
+ tone="neutral"
87
+ size="sm"
88
+ disabled={disabled}
89
+ onPress={() => void openForm(null)}
90
+ >
91
+ {t('editProfile.items.links.form.add') || 'Add link'}
92
+ </Button>
93
+ </View>
94
+ ) : null
95
+ }
96
+ />
97
+ );
98
+ }
@@ -4,7 +4,7 @@ import {
4
4
  getLinkDescription,
5
5
  linkIdentity,
6
6
  linksToListItems,
7
- moveLinkItem,
7
+ applyLinkFormResult,
8
8
  normalizeLinkInput,
9
9
  } from '../linkFormat';
10
10
 
@@ -112,14 +112,57 @@ describe('clampLinkTitle', () => {
112
112
  });
113
113
  });
114
114
 
115
- describe('moveLinkItem', () => {
116
- it('swaps an entry with its neighbour', () => {
117
- expect(moveLinkItem(['a', 'b', 'c'], 1, -1)).toEqual(['b', 'a', 'c']);
118
- expect(moveLinkItem(['a', 'b', 'c'], 1, 1)).toEqual(['a', 'c', 'b']);
115
+ describe('applyLinkFormResult', () => {
116
+ const item = (id: string, url: string, title = '') => ({
117
+ id,
118
+ url,
119
+ title,
120
+ description: `Link to ${url}`,
119
121
  });
122
+ const existing = [item('a', 'https://a.test/'), item('b', 'https://b.test/')];
123
+ const newId = () => 'new-1';
120
124
 
121
- it('leaves the list alone at either end', () => {
122
- expect(moveLinkItem(['a', 'b'], 0, -1)).toEqual(['a', 'b']);
123
- expect(moveLinkItem(['a', 'b'], 1, 1)).toEqual(['a', 'b']);
125
+ it('appends a saved link, with its title and description', () => {
126
+ const next = applyLinkFormResult(
127
+ existing,
128
+ null,
129
+ { kind: 'save', url: 'https://c.test/', title: 'Site' },
130
+ 10,
131
+ newId,
132
+ );
133
+ expect(next[2]).toEqual({
134
+ id: 'new-1',
135
+ url: 'https://c.test/',
136
+ title: 'Site',
137
+ description: 'Link to https://c.test/',
138
+ });
139
+ });
140
+
141
+ it('replaces the link being edited and keeps its id', () => {
142
+ const next = applyLinkFormResult(
143
+ existing,
144
+ 1,
145
+ { kind: 'save', url: 'https://b2.test/', title: '' },
146
+ 10,
147
+ newId,
148
+ );
149
+ expect(next[1]).toMatchObject({ id: 'b', url: 'https://b2.test/', title: '' });
150
+ expect(next).toHaveLength(2);
151
+ });
152
+
153
+ it('refuses a new link once the profile is full', () => {
154
+ const next = applyLinkFormResult(
155
+ existing,
156
+ null,
157
+ { kind: 'save', url: 'https://c.test/', title: '' },
158
+ 2,
159
+ newId,
160
+ );
161
+ expect(next).toEqual(existing);
162
+ });
163
+
164
+ it('removes the link being edited, and nothing for a new one', () => {
165
+ expect(applyLinkFormResult(existing, 0, { kind: 'remove' }, 10, newId)).toEqual([existing[1]]);
166
+ expect(applyLinkFormResult(existing, null, { kind: 'remove' }, 10, newId)).toEqual(existing);
124
167
  });
125
168
  });
@@ -84,14 +84,33 @@ export function clampLinkTitle(title: string): string {
84
84
  return Array.from(title).slice(0, PROFILE_LINK_TITLE_MAX).join('');
85
85
  }
86
86
 
87
- /** A copy of the list with the entry at the index moved one place: -1 up, +1 down. */
88
- export function moveLinkItem<T>(items: readonly T[], index: number, delta: -1 | 1): T[] {
89
- const target = index + delta;
90
- if (index < 0 || index >= items.length || target < 0 || target >= items.length) {
91
- return [...items];
87
+ /** What the link form hands back when it is dismissed. */
88
+ export type LinkFormResult = { kind: 'save'; url: string; title: string } | { kind: 'remove' };
89
+
90
+ /**
91
+ * The list after a link form result. A save appends a new link (if the profile
92
+ * has room) or replaces the link at `index`; a remove drops it. `newId` makes
93
+ * the id of an appended link, so the caller decides how ids are minted.
94
+ */
95
+ export function applyLinkFormResult(
96
+ items: readonly LinkListItem[],
97
+ index: number | null,
98
+ result: LinkFormResult,
99
+ maxLinks: number,
100
+ newId: () => string,
101
+ ): LinkListItem[] {
102
+ if (result.kind === 'remove') {
103
+ return index === null ? [...items] : items.filter((_, i) => i !== index);
104
+ }
105
+ const title = clampLinkTitle(result.title.trim());
106
+ const saved: LinkListItem = {
107
+ id: index === null ? newId() : (items[index]?.id ?? newId()),
108
+ url: result.url,
109
+ title,
110
+ description: getLinkDescription(result.url),
111
+ };
112
+ if (index === null) {
113
+ return items.length >= maxLinks ? [...items] : [...items, saved];
92
114
  }
93
- const next = [...items];
94
- const [moved] = next.splice(index, 1);
95
- next.splice(target, 0, moved as T);
96
- return next;
115
+ return items.map((item, i) => (i === index ? saved : item));
97
116
  }