@oxy.so/services 14.11.0 → 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 (73) 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/ui/icons/subsetGlyphMaps.js +1 -0
  8. package/lib/commonjs/ui/icons/subsetGlyphMaps.js.map +1 -1
  9. package/lib/commonjs/ui/screens/EditProfileFieldScreen.js +16 -63
  10. package/lib/commonjs/ui/screens/EditProfileFieldScreen.js.map +1 -1
  11. package/lib/commonjs/ui/screens/ProfileLinkForm.js +125 -0
  12. package/lib/commonjs/ui/screens/ProfileLinkForm.js.map +1 -0
  13. package/lib/commonjs/ui/screens/ProfileLinksEditor.js +85 -0
  14. package/lib/commonjs/ui/screens/ProfileLinksEditor.js.map +1 -0
  15. package/lib/commonjs/ui/screens/linkFormat.js +22 -10
  16. package/lib/commonjs/ui/screens/linkFormat.js.map +1 -1
  17. package/lib/module/assets/assets/fonts/icons/OxyServicesIonicons.ttf +0 -0
  18. package/lib/module/assets/assets/fonts/icons/OxyServicesMaterialCommunityIcons.ttf +0 -0
  19. package/lib/module/assets/assets/fonts/icons/manifest.json +5 -4
  20. package/lib/module/assets/fonts/icons/OxyServicesIonicons.ttf +0 -0
  21. package/lib/module/assets/fonts/icons/OxyServicesMaterialCommunityIcons.ttf +0 -0
  22. package/lib/module/assets/fonts/icons/manifest.json +5 -4
  23. package/lib/module/ui/icons/subsetGlyphMaps.js +1 -0
  24. package/lib/module/ui/icons/subsetGlyphMaps.js.map +1 -1
  25. package/lib/module/ui/screens/EditProfileFieldScreen.js +17 -65
  26. package/lib/module/ui/screens/EditProfileFieldScreen.js.map +1 -1
  27. package/lib/module/ui/screens/ProfileLinkForm.js +121 -0
  28. package/lib/module/ui/screens/ProfileLinkForm.js.map +1 -0
  29. package/lib/module/ui/screens/ProfileLinksEditor.js +81 -0
  30. package/lib/module/ui/screens/ProfileLinksEditor.js.map +1 -0
  31. package/lib/module/ui/screens/linkFormat.js +21 -9
  32. package/lib/module/ui/screens/linkFormat.js.map +1 -1
  33. package/lib/typescript/commonjs/ui/icons/Ionicons.d.ts +1 -1
  34. package/lib/typescript/commonjs/ui/icons/Ionicons.d.ts.map +1 -1
  35. package/lib/typescript/commonjs/ui/icons/subsetGlyphMaps.d.ts +1 -0
  36. package/lib/typescript/commonjs/ui/icons/subsetGlyphMaps.d.ts.map +1 -1
  37. package/lib/typescript/commonjs/ui/screens/EditProfileFieldScreen.d.ts.map +1 -1
  38. package/lib/typescript/commonjs/ui/screens/ProfileLinkForm.d.ts +18 -0
  39. package/lib/typescript/commonjs/ui/screens/ProfileLinkForm.d.ts.map +1 -0
  40. package/lib/typescript/commonjs/ui/screens/ProfileLinksEditor.d.ts +14 -0
  41. package/lib/typescript/commonjs/ui/screens/ProfileLinksEditor.d.ts.map +1 -0
  42. package/lib/typescript/commonjs/ui/screens/linkFormat.d.ts +14 -2
  43. package/lib/typescript/commonjs/ui/screens/linkFormat.d.ts.map +1 -1
  44. package/lib/typescript/module/ui/icons/Ionicons.d.ts +1 -1
  45. package/lib/typescript/module/ui/icons/Ionicons.d.ts.map +1 -1
  46. package/lib/typescript/module/ui/icons/subsetGlyphMaps.d.ts +1 -0
  47. package/lib/typescript/module/ui/icons/subsetGlyphMaps.d.ts.map +1 -1
  48. package/lib/typescript/module/ui/screens/EditProfileFieldScreen.d.ts.map +1 -1
  49. package/lib/typescript/module/ui/screens/ProfileLinkForm.d.ts +18 -0
  50. package/lib/typescript/module/ui/screens/ProfileLinkForm.d.ts.map +1 -0
  51. package/lib/typescript/module/ui/screens/ProfileLinksEditor.d.ts +14 -0
  52. package/lib/typescript/module/ui/screens/ProfileLinksEditor.d.ts.map +1 -0
  53. package/lib/typescript/module/ui/screens/linkFormat.d.ts +14 -2
  54. package/lib/typescript/module/ui/screens/linkFormat.d.ts.map +1 -1
  55. package/package.json +5 -5
  56. package/src/assets/fonts/icons/OxyServicesIonicons.ttf +0 -0
  57. package/src/assets/fonts/icons/OxyServicesMaterialCommunityIcons.ttf +0 -0
  58. package/src/assets/fonts/icons/manifest.json +5 -4
  59. package/src/ui/icons/subsetGlyphMaps.ts +1 -0
  60. package/src/ui/screens/EditProfileFieldScreen.tsx +19 -85
  61. package/src/ui/screens/ProfileLinkForm.tsx +131 -0
  62. package/src/ui/screens/ProfileLinksEditor.tsx +98 -0
  63. package/src/ui/screens/__tests__/linkFormat.test.ts +51 -8
  64. package/src/ui/screens/linkFormat.ts +28 -9
  65. package/lib/commonjs/ui/screens/LinkListEditor.js +0 -105
  66. package/lib/commonjs/ui/screens/LinkListEditor.js.map +0 -1
  67. package/lib/module/ui/screens/LinkListEditor.js +0 -99
  68. package/lib/module/ui/screens/LinkListEditor.js.map +0 -1
  69. package/lib/typescript/commonjs/ui/screens/LinkListEditor.d.ts +0 -25
  70. package/lib/typescript/commonjs/ui/screens/LinkListEditor.d.ts.map +0 -1
  71. package/lib/typescript/module/ui/screens/LinkListEditor.d.ts +0 -25
  72. package/lib/typescript/module/ui/screens/LinkListEditor.d.ts.map +0 -1
  73. package/src/ui/screens/LinkListEditor.tsx +0 -113
@@ -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
  }
@@ -1,105 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.LinkListEditor = LinkListEditor;
7
- var _react = _interopRequireWildcard(require("react"));
8
- var _reactNative = require("react-native");
9
- var _button = require("@oxy.so/bloom/button");
10
- var _textField = require("@oxy.so/bloom/text-field");
11
- var _typography = require("@oxy.so/bloom/typography");
12
- var _theme = require("@oxy.so/bloom/theme");
13
- var _client = require("@oxy.so/contracts/client");
14
- var _Ionicons = _interopRequireDefault(require("../icons/Ionicons.js"));
15
- var _linkFormat = require("./linkFormat.js");
16
- var _jsxRuntime = require("react/jsx-runtime");
17
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
18
- function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
19
- /**
20
- * The profile's ordered link list. Each link has an editable title and can move
21
- * up or down; order is the profile's display order, and the server stores it as
22
- * the array's index. Reordering uses buttons rather than drag: a drag gesture
23
- * would not reach a screen reader, and a button does.
24
- */
25
- function LinkListEditor({
26
- items,
27
- onChange,
28
- disabled,
29
- labels
30
- }) {
31
- const bloomTheme = (0, _theme.useTheme)();
32
- const setTitle = (0, _react.useCallback)((id, title) => {
33
- onChange(items.map(item => item.id === id ? {
34
- ...item,
35
- title: (0, _linkFormat.clampLinkTitle)(title)
36
- } : item));
37
- }, [items, onChange]);
38
- const move = (0, _react.useCallback)((index, delta) => onChange((0, _linkFormat.moveLinkItem)(items, index, delta)), [items, onChange]);
39
- const remove = (0, _react.useCallback)(id => onChange(items.filter(item => item.id !== id)), [items, onChange]);
40
- return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, {
41
- className: "gap-space-12",
42
- children: items.map((item, index) => {
43
- const shownTitle = item.title || item.url;
44
- return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.View, {
45
- className: "gap-space-8 pb-space-12 border-b border-border",
46
- children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(_textField.TextField, {
47
- disabled: disabled,
48
- children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_textField.TextFieldLabel, {
49
- children: labels.title
50
- }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_textField.TextFieldInput, {
51
- label: labels.title,
52
- value: item.title,
53
- onChangeText: value => setTitle(item.id, value),
54
- maxLength: _client.PROFILE_LINK_TITLE_MAX,
55
- autoCorrect: true
56
- })]
57
- }), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.View, {
58
- className: "flex-row items-center gap-space-8",
59
- children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_typography.Text, {
60
- className: "flex-1 text-muted-foreground",
61
- numberOfLines: 1,
62
- children: item.url
63
- }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_button.Button, {
64
- onPress: () => move(index, -1),
65
- disabled: disabled || index === 0,
66
- accessibilityLabel: labels.moveUp,
67
- icon: /*#__PURE__*/(0, _jsxRuntime.jsx)(_Ionicons.default, {
68
- name: "chevron-up",
69
- size: 18,
70
- color: bloomTheme.colors.textSecondary
71
- }),
72
- iconOnly: true,
73
- tone: "neutral",
74
- appearance: "plain"
75
- }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_button.Button, {
76
- onPress: () => move(index, 1),
77
- disabled: disabled || index === items.length - 1,
78
- accessibilityLabel: labels.moveDown,
79
- icon: /*#__PURE__*/(0, _jsxRuntime.jsx)(_Ionicons.default, {
80
- name: "chevron-down",
81
- size: 18,
82
- color: bloomTheme.colors.textSecondary
83
- }),
84
- iconOnly: true,
85
- tone: "neutral",
86
- appearance: "plain"
87
- }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_button.Button, {
88
- onPress: () => remove(item.id),
89
- disabled: disabled,
90
- accessibilityLabel: labels.removeNamed(shownTitle),
91
- icon: /*#__PURE__*/(0, _jsxRuntime.jsx)(_Ionicons.default, {
92
- name: "trash-outline",
93
- size: 18,
94
- color: bloomTheme.colors.negative
95
- }),
96
- iconOnly: true,
97
- tone: "danger",
98
- appearance: "plain"
99
- })]
100
- })]
101
- }, item.id);
102
- })
103
- });
104
- }
105
- //# sourceMappingURL=LinkListEditor.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["_react","_interopRequireWildcard","require","_reactNative","_button","_textField","_typography","_theme","_client","_Ionicons","_interopRequireDefault","_linkFormat","_jsxRuntime","e","__esModule","default","t","WeakMap","r","n","o","i","f","__proto__","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","LinkListEditor","items","onChange","disabled","labels","bloomTheme","useTheme","setTitle","useCallback","id","title","map","item","clampLinkTitle","move","index","delta","moveLinkItem","remove","filter","jsx","View","className","children","shownTitle","url","jsxs","TextField","TextFieldLabel","TextFieldInput","label","value","onChangeText","maxLength","PROFILE_LINK_TITLE_MAX","autoCorrect","Text","numberOfLines","Button","onPress","accessibilityLabel","moveUp","icon","name","size","color","colors","textSecondary","iconOnly","tone","appearance","length","moveDown","removeNamed","negative"],"sourceRoot":"../../../../src","sources":["ui/screens/LinkListEditor.tsx"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AACA,IAAAE,OAAA,GAAAF,OAAA;AACA,IAAAG,UAAA,GAAAH,OAAA;AACA,IAAAI,WAAA,GAAAJ,OAAA;AACA,IAAAK,MAAA,GAAAL,OAAA;AACA,IAAAM,OAAA,GAAAN,OAAA;AACA,IAAAO,SAAA,GAAAC,sBAAA,CAAAR,OAAA;AACA,IAAAS,WAAA,GAAAT,OAAA;AAA+E,IAAAU,WAAA,GAAAV,OAAA;AAAA,SAAAQ,uBAAAG,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAAA,SAAAZ,wBAAAY,CAAA,EAAAG,CAAA,6BAAAC,OAAA,MAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAhB,uBAAA,YAAAA,CAAAY,CAAA,EAAAG,CAAA,SAAAA,CAAA,IAAAH,CAAA,IAAAA,CAAA,CAAAC,UAAA,SAAAD,CAAA,MAAAO,CAAA,EAAAC,CAAA,EAAAC,CAAA,KAAAC,SAAA,QAAAR,OAAA,EAAAF,CAAA,iBAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,SAAAS,CAAA,MAAAF,CAAA,GAAAJ,CAAA,GAAAG,CAAA,GAAAD,CAAA,QAAAE,CAAA,CAAAI,GAAA,CAAAX,CAAA,UAAAO,CAAA,CAAAK,GAAA,CAAAZ,CAAA,GAAAO,CAAA,CAAAM,GAAA,CAAAb,CAAA,EAAAS,CAAA,gBAAAN,CAAA,IAAAH,CAAA,gBAAAG,CAAA,OAAAW,cAAA,CAAAC,IAAA,CAAAf,CAAA,EAAAG,CAAA,OAAAK,CAAA,IAAAD,CAA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