@hadoku/task-ui-components 4.22.3 → 4.22.4

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.
@@ -8,6 +8,10 @@
8
8
  * - global content-visibility level (tiered pill → PUT /prefs/api/v1/content-level)
9
9
  * - switch key (an inline sign-in form, on the site's own sign-in client)
10
10
  *
11
+ * Those are grouped into tabs (Profile, Content, Account), followed by the
12
+ * app's own: `children` as one "App" tab, `appTabs` as one tab each. The open
13
+ * tab is remembered per user and per app (useSettingsTab, @wolffm/themes).
14
+ *
11
15
  * "Connected" (parallel to ConnectedThemePicker): it self-wires to the
12
16
  * hadoku.me edge-router via same-origin fetches (see lib/settingsClient), so
13
17
  * dropping `<ConnectedSettings />` into any app under hadoku.me needs zero
@@ -25,7 +29,8 @@
25
29
  * maxLevel comes from the server so the tier ceiling is never trusted from the
26
30
  * client.
27
31
  */
28
- import React, { useCallback, useEffect, useRef, useState } from 'react'
32
+ import React, { useCallback, useEffect, useId, useRef, useState } from 'react'
33
+ import { useSettingsTab } from '@wolffm/themes'
29
34
  import { SettingsIcon } from './ThemeIcons'
30
35
  import { AvatarPicker } from './AvatarPicker'
31
36
  import {
@@ -56,14 +61,24 @@ export interface ConnectedSettingsProps {
56
61
  name?: string | null
57
62
  /** Notify the host (e.g. a "Signed in as …" label) of a rename. */
58
63
  onNameChange?: (name: string | null) => void
59
- /** App-specific settings rendered as a final section in the same popout, so
60
- * an app with its own preferences keeps ONE unified gear instead of a second
61
- * control. Shown under an "App preferences" divider.
64
+ /** App-specific settings as ONE tab, labelled "App", after the site's own
65
+ * tabs — so an app with its own preferences keeps one unified gear instead
66
+ * of a second control. For more than one section, use `appTabs`.
62
67
  *
63
68
  * This slot is deliberately unconstrained — put whatever the app needs in
64
- * it. The constraint is only that it lands AFTER the four canonical rows and
65
- * cannot change them. */
69
+ * it. The constraint is only that it cannot change the site's tabs. */
66
70
  children?: React.ReactNode
71
+ /** App-specific settings as tabs of their own, after `children`'s "App" tab
72
+ * if both are given. `id` is stable and unique within the app: the last-open
73
+ * tab is remembered by it. `render` runs only while its tab is open. */
74
+ appTabs?: AppSettingsTab[]
75
+ }
76
+
77
+ /** One app-contributed tab in the settings popout. */
78
+ export interface AppSettingsTab {
79
+ id: string
80
+ label: string
81
+ render: () => React.ReactNode
67
82
  }
68
83
 
69
84
  /** Rejects once `signal` aborts, so a call that ignores the signal (an older
@@ -105,7 +120,6 @@ const PASSKEY_DOT: React.CSSProperties = {
105
120
  * inline, so the rule is injected once into the document instead, for the
106
121
  * same reason PASSKEY_DOT is inline. */
107
122
  const PASSKEY_PULSE_CLASS = 'settings-popout__btn--pulse'
108
- const PASSKEY_PULSE_STYLE_ID = 'settings-passkey-pulse'
109
123
  const PASSKEY_PULSE_CSS = `
110
124
  @keyframes settings-passkey-pulse {
111
125
  0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--color-primary) 70%, transparent); }
@@ -119,14 +133,72 @@ const PASSKEY_PULSE_CSS = `
119
133
  }
120
134
  `
121
135
 
122
- function usePasskeyPulseStyle(active: boolean) {
136
+ /** The tab strip and its panels. Injected for the same reason as the pulse:
137
+ * an app's copy of app-header.css predates the tabs until it rebuilds. The
138
+ * strip stays pinned while a long tab scrolls, and scrolls sideways itself
139
+ * when the tabs outgrow a phone-width panel. */
140
+ const TABS_CSS = `
141
+ .settings-popout__top {
142
+ position: sticky;
143
+ top: -16px;
144
+ z-index: 1;
145
+ display: flex;
146
+ flex-direction: column;
147
+ gap: 10px;
148
+ margin: -16px -16px 0;
149
+ padding: 16px 16px 0;
150
+ background: var(--color-bg-card);
151
+ border-bottom: 1px solid var(--color-border);
152
+ }
153
+ .settings-popout__tabs {
154
+ display: flex;
155
+ gap: 2px;
156
+ margin: 0 -16px -1px;
157
+ padding: 0 16px;
158
+ overflow-x: auto;
159
+ scrollbar-width: thin;
160
+ }
161
+ .settings-popout__tab {
162
+ position: relative;
163
+ flex: none;
164
+ padding: 6px 10px;
165
+ border: 0;
166
+ border-bottom: 2px solid transparent;
167
+ background: transparent;
168
+ color: var(--color-text-secondary);
169
+ font: inherit;
170
+ font-size: 0.8rem;
171
+ font-weight: 600;
172
+ white-space: nowrap;
173
+ cursor: pointer;
174
+ }
175
+ .settings-popout__tab:hover {
176
+ color: var(--color-text);
177
+ }
178
+ .settings-popout__tab[aria-selected='true'] {
179
+ color: var(--color-text);
180
+ border-bottom-color: var(--color-primary);
181
+ }
182
+ .settings-popout__tab:focus-visible {
183
+ outline: 2px solid var(--color-primary);
184
+ outline-offset: -2px;
185
+ border-radius: 6px 6px 0 0;
186
+ }
187
+ .settings-popout__tabpanel {
188
+ display: flex;
189
+ flex-direction: column;
190
+ gap: 14px;
191
+ }
192
+ `
193
+
194
+ function useInjectedStyle(id: string, css: string, active: boolean) {
123
195
  useEffect(() => {
124
- if (!active || document.getElementById(PASSKEY_PULSE_STYLE_ID)) return
196
+ if (!active || document.getElementById(id)) return
125
197
  const el = document.createElement('style')
126
- el.id = PASSKEY_PULSE_STYLE_ID
127
- el.textContent = PASSKEY_PULSE_CSS
198
+ el.id = id
199
+ el.textContent = css
128
200
  document.head.appendChild(el)
129
- }, [active])
201
+ }, [id, css, active])
130
202
  }
131
203
 
132
204
  const TIER_LABEL: Record<Tier, string> = {
@@ -142,10 +214,16 @@ export function ConnectedSettings({
142
214
  userType: userTypeProp,
143
215
  name: nameProp,
144
216
  onNameChange,
145
- children
217
+ children,
218
+ appTabs
146
219
  }: ConnectedSettingsProps) {
147
220
  const [open, setOpen] = useState(false)
148
221
  const rootRef = useRef<HTMLDivElement>(null)
222
+ const tabIdBase = useId()
223
+ const tabRefs = useRef(new Map<string, HTMLButtonElement>())
224
+ const [savedTab, saveTab] = useSettingsTab()
225
+ // This visit's pick; wins over the saved one while it is still offered.
226
+ const [pickedTab, setPickedTab] = useState<string | null>(null)
149
227
 
150
228
  // Identity — from props if supplied, else resolved lazily via whoami().
151
229
  const [userType, setUserType] = useState<Tier>(userTypeProp ?? 'public')
@@ -210,7 +288,64 @@ export function ConnectedSettings({
210
288
  passkeyCount === 0 &&
211
289
  !passkeySaved &&
212
290
  passkeysSupported()
213
- usePasskeyPulseStyle(needsPasskey)
291
+ useInjectedStyle('settings-passkey-pulse', PASSKEY_PULSE_CSS, needsPasskey)
292
+ useInjectedStyle('settings-tabs', TABS_CSS, open)
293
+
294
+ // The site's own groups first, then the app's. App ids are namespaced so an
295
+ // app tab called "account" can never collide with the site's.
296
+ const tabs: { id: string; label: string; dot?: boolean }[] = [
297
+ { id: 'profile', label: 'Profile' },
298
+ ...(!resolving && showContentPill ? [{ id: 'content', label: 'Content' }] : []),
299
+ // The gear's dot asks for a passkey; this one says where Save passkey is.
300
+ { id: 'account', label: 'Account', dot: needsPasskey },
301
+ ...(children ? [{ id: 'app:', label: 'App' }] : []),
302
+ ...(appTabs ?? []).map(t => ({ id: `app:${t.id}`, label: t.label }))
303
+ ]
304
+ const tabIds = tabs.map(t => t.id)
305
+ // Nothing remembered: open on the app's first tab, which is usually why the
306
+ // gear was clicked inside an app.
307
+ const defaultTab = tabIds.find(id => id.startsWith('app:')) ?? 'profile'
308
+ const activeTab =
309
+ [pickedTab, savedTab].find((id): id is string => id !== null && tabIds.includes(id)) ??
310
+ defaultTab
311
+ const appTab = appTabs?.find(t => `app:${t.id}` === activeTab)
312
+ const tabDomId = (id: string) => `${tabIdBase}tab-${id}`
313
+ const panelDomId = `${tabIdBase}panel`
314
+
315
+ const selectTab = useCallback(
316
+ (id: string) => {
317
+ setPickedTab(id)
318
+ saveTab(id)
319
+ },
320
+ [saveTab]
321
+ )
322
+
323
+ // Arrow keys, Home and End move between tabs and open the one they land on
324
+ // (the ARIA tablist pattern with automatic activation).
325
+ const onTabKey = (e: React.KeyboardEvent) => {
326
+ const i = tabIds.indexOf(activeTab)
327
+ const n = tabIds.length
328
+ const next =
329
+ e.key === 'ArrowRight'
330
+ ? tabIds[(i + 1) % n]
331
+ : e.key === 'ArrowLeft'
332
+ ? tabIds[(i - 1 + n) % n]
333
+ : e.key === 'Home'
334
+ ? tabIds[0]
335
+ : e.key === 'End'
336
+ ? tabIds[n - 1]
337
+ : undefined
338
+ if (next === undefined) return
339
+ e.preventDefault()
340
+ selectTab(next)
341
+ tabRefs.current.get(next)?.focus()
342
+ }
343
+
344
+ // A remembered tab past the edge of a narrow strip is scrolled into sight.
345
+ useEffect(() => {
346
+ if (open)
347
+ tabRefs.current.get(activeTab)?.scrollIntoView({ block: 'nearest', inline: 'nearest' })
348
+ }, [open, activeTab])
214
349
 
215
350
  // Keep local identity in sync when the host controls it via props.
216
351
  useEffect(() => {
@@ -419,7 +554,7 @@ export function ConnectedSettings({
419
554
  // No caller-supplied class on the root. The four rows below are the
420
555
  // platform's, not the app's, and a className here is enough to restyle or
421
556
  // hide any of them — which is the drift this component exists to prevent.
422
- // Apps extend via `children`, never by reaching into this markup.
557
+ // Apps extend via `children` and `appTabs`, never by reaching into this markup.
423
558
  return (
424
559
  <div className="settings-popout" ref={rootRef}>
425
560
  <button
@@ -440,364 +575,417 @@ export function ConnectedSettings({
440
575
 
441
576
  {open && (
442
577
  <div className="settings-popout__panel" role="dialog" aria-label="User settings">
443
- <div className="settings-popout__header">Settings</div>
444
-
445
- {/* Access tier. While resolving, the state still says 'public' —
446
- rendering "Guest" there would be a wrong answer that corrects
447
- itself a moment later, which reads exactly like the lag this
448
- placeholder exists to remove. */}
449
- <section className="settings-popout__row">
450
- <span className="settings-popout__label">Access tier</span>
451
- {resolving ? (
452
- <span className="settings-popout__value">…</span>
453
- ) : (
454
- <span className={`settings-popout__tier settings-popout__tier--${userType}`}>
455
- {TIER_LABEL[userType]}
456
- </span>
457
- )}
458
- </section>
459
-
460
- {/* Display name */}
461
- <section className="settings-popout__row">
462
- <span className="settings-popout__label">Display name</span>
463
- {resolving ? (
464
- <span className="settings-popout__value">…</span>
465
- ) : editingName ? (
466
- <span className="settings-popout__inline">
467
- <input
468
- className="settings-popout__input"
469
- value={nameDraft}
470
- maxLength={64}
471
- autoFocus
472
- disabled={nameSaving}
473
- aria-invalid={nameError !== null}
474
- aria-describedby={nameError ? 'settings-popout-name-error' : undefined}
475
- onChange={e => {
476
- setNameDraft(e.target.value)
477
- setNameError(null)
478
- }}
479
- onKeyDown={e => {
480
- if (e.key === 'Enter') {
481
- saveName().catch(reportErr)
482
- }
483
- if (e.key === 'Escape') {
484
- // The edit's Escape, not the popout's (window listener).
485
- e.stopPropagation()
486
- setEditingName(false)
487
- setNameError(null)
488
- setNameDraft(displayName ?? '')
489
- }
490
- }}
491
- />
578
+ <div className="settings-popout__top">
579
+ <div className="settings-popout__header">Settings</div>
580
+ <div
581
+ className="settings-popout__tabs"
582
+ role="tablist"
583
+ aria-label="Settings sections"
584
+ onKeyDown={onTabKey}
585
+ >
586
+ {tabs.map(t => (
492
587
  <button
493
- type="button"
494
- className="settings-popout__btn settings-popout__btn--primary"
495
- disabled={nameSaving}
496
- onClick={() => {
497
- saveName().catch(reportErr)
588
+ key={t.id}
589
+ ref={el => {
590
+ if (el) tabRefs.current.set(t.id, el)
591
+ else tabRefs.current.delete(t.id)
498
592
  }}
499
- >
500
- {nameSaving ? '…' : 'Save'}
501
- </button>
502
- {nameError && (
503
- <span
504
- id="settings-popout-name-error"
505
- className="settings-popout__error"
506
- role="alert"
507
- >
508
- {nameError}
509
- </span>
510
- )}
511
- </span>
512
- ) : (
513
- <button
514
- type="button"
515
- className="settings-popout__value settings-popout__value--editable"
516
- aria-label="Edit display name"
517
- onClick={() => {
518
- setNameDraft(displayName ?? '')
519
- setEditingName(true)
520
- }}
521
- >
522
- {displayName || 'Unnamed'}
523
- </button>
524
- )}
525
- </section>
526
-
527
- {/* Avatar: picture and character, chosen in place (AvatarPicker).
528
- Collapsed until Change, so opening the gear costs no request and no
529
- page load reads the avatar. Hidden for public callers, like the
530
- content pill: an avatar needs a session. */}
531
- {!resolving && userType !== 'public' && (
532
- <section className="settings-popout__row settings-popout__row--stack">
533
- <span className="settings-popout__inline">
534
- <span className="settings-popout__label settings-popout__label--grow">Avatar</span>
535
- <button
536
593
  type="button"
537
- className="settings-popout__btn"
538
- aria-expanded={avatarOpen}
539
- onClick={() => setAvatarOpen(v => !v)}
594
+ role="tab"
595
+ id={tabDomId(t.id)}
596
+ className="settings-popout__tab"
597
+ aria-selected={t.id === activeTab}
598
+ aria-controls={panelDomId}
599
+ tabIndex={t.id === activeTab ? 0 : -1}
600
+ onClick={() => selectTab(t.id)}
540
601
  >
541
- {avatarOpen ? 'Done' : 'Change'}
602
+ {t.label}
603
+ {t.dot && <span style={PASSKEY_DOT} aria-hidden="true" />}
542
604
  </button>
543
- </span>
544
- {avatarOpen && <AvatarPicker />}
545
- </section>
546
- )}
547
-
548
- {/* Content visibility level. Held back until the first-open fetch
549
- settles, so it lands in the same paint as the tier and name
550
- rather than a round trip behind them. `content` is fetched
551
- concurrently with whoami(), so by then it is already here. */}
552
- {!resolving && showContentPill && (
553
- <section className="settings-popout__row settings-popout__row--stack">
554
- <span className="settings-popout__label">Content visibility</span>
555
- {content ? (
556
- <>
557
- <div
558
- className="settings-popout__pill"
559
- role="radiogroup"
560
- aria-label="Content visibility level"
561
- >
562
- {Array.from({ length: content.maxLevel }, (_, i) => i + 1).map(lvl => (
605
+ ))}
606
+ </div>
607
+ </div>
608
+
609
+ <div
610
+ className="settings-popout__tabpanel"
611
+ role="tabpanel"
612
+ id={panelDomId}
613
+ aria-labelledby={tabDomId(activeTab)}
614
+ >
615
+ {activeTab === 'profile' && (
616
+ <>
617
+ {/* Access tier. While resolving, the state still says 'public' —
618
+ rendering "Guest" there would be a wrong answer that corrects
619
+ itself a moment later, which reads exactly like the lag this
620
+ placeholder exists to remove. */}
621
+ <section className="settings-popout__row">
622
+ <span className="settings-popout__label">Access tier</span>
623
+ {resolving ? (
624
+ <span className="settings-popout__value">…</span>
625
+ ) : (
626
+ <span className={`settings-popout__tier settings-popout__tier--${userType}`}>
627
+ {TIER_LABEL[userType]}
628
+ </span>
629
+ )}
630
+ </section>
631
+
632
+ {/* Display name */}
633
+ <section className="settings-popout__row">
634
+ <span className="settings-popout__label">Display name</span>
635
+ {resolving ? (
636
+ <span className="settings-popout__value">…</span>
637
+ ) : editingName ? (
638
+ <span className="settings-popout__inline">
639
+ <input
640
+ className="settings-popout__input"
641
+ value={nameDraft}
642
+ maxLength={64}
643
+ autoFocus
644
+ disabled={nameSaving}
645
+ aria-invalid={nameError !== null}
646
+ aria-describedby={nameError ? 'settings-popout-name-error' : undefined}
647
+ onChange={e => {
648
+ setNameDraft(e.target.value)
649
+ setNameError(null)
650
+ }}
651
+ onKeyDown={e => {
652
+ if (e.key === 'Enter') {
653
+ saveName().catch(reportErr)
654
+ }
655
+ if (e.key === 'Escape') {
656
+ // The edit's Escape, not the popout's (window listener).
657
+ e.stopPropagation()
658
+ setEditingName(false)
659
+ setNameError(null)
660
+ setNameDraft(displayName ?? '')
661
+ }
662
+ }}
663
+ />
563
664
  <button
564
- key={lvl}
565
665
  type="button"
566
- role="radio"
567
- aria-checked={lvl === content.level}
568
- aria-label={`Level ${lvl}`}
569
- className={`settings-popout__seg${
570
- lvl <= content.level ? ' settings-popout__seg--filled' : ''
571
- }`}
572
- disabled={levelSaving}
666
+ className="settings-popout__btn settings-popout__btn--primary"
667
+ disabled={nameSaving}
573
668
  onClick={() => {
574
- pickLevel(lvl).catch(reportErr)
669
+ saveName().catch(reportErr)
575
670
  }}
576
671
  >
577
- {lvl}
672
+ {nameSaving ? '…' : 'Save'}
578
673
  </button>
579
- ))}
580
- </div>
581
- <span className="settings-popout__hint">
582
- Higher levels reveal more mature content across apps. Level 1 is
583
- safe-for-everyone.
584
- </span>
585
- </>
586
- ) : (
587
- // Not "Loading…" — the fetch has already settled by the time
588
- // this section renders at all, so a null here means it failed.
589
- <span className="settings-popout__hint">Currently unavailable.</span>
590
- )}
591
- </section>
592
- )}
593
-
594
- {/* Switch key. Signs in inline through the SITE's sign-in client
595
- (the /auth page's own code path), never a post of ours. A real
596
- <form> with a username + current-password pair, so password
597
- managers offer and save the key. */}
598
- {keyFormOpen ? (
599
- <section className="settings-popout__row settings-popout__row--stack">
600
- <form
601
- className="settings-popout__key-form"
602
- onSubmit={e => {
603
- e.preventDefault()
604
- submitKey().catch(reportErr)
605
- }}
606
- >
607
- <input
608
- type="text"
609
- name="username"
610
- autoComplete="username"
611
- value="hadoku"
612
- readOnly
613
- hidden
614
- />
615
- <label className="settings-popout__label" htmlFor="settings-popout-key">
616
- Access key
617
- </label>
618
- <span className="settings-popout__inline">
619
- <input
620
- id="settings-popout-key"
621
- className="settings-popout__input"
622
- type="password"
623
- name="password"
624
- autoComplete="current-password"
625
- autoCapitalize="none"
626
- spellCheck={false}
627
- autoFocus
628
- value={keyDraft}
629
- disabled={keyBusy}
630
- aria-invalid={keyError !== null}
631
- aria-describedby={keyError ? 'settings-popout-key-error' : undefined}
632
- onChange={e => setKeyDraft(e.target.value)}
633
- />
634
- <button
635
- type="submit"
636
- className="settings-popout__btn settings-popout__btn--primary"
637
- disabled={keyBusy}
638
- >
639
- {keyBusy ? 'Signing in…' : 'Sign in'}
640
- </button>
641
- </span>
642
- {passkeysSupported() && (
643
- <span className="settings-popout__inline">
674
+ {nameError && (
675
+ <span
676
+ id="settings-popout-name-error"
677
+ className="settings-popout__error"
678
+ role="alert"
679
+ >
680
+ {nameError}
681
+ </span>
682
+ )}
683
+ </span>
684
+ ) : (
644
685
  <button
645
686
  type="button"
646
- className="settings-popout__btn"
647
- disabled={keyBusy}
687
+ className="settings-popout__value settings-popout__value--editable"
688
+ aria-label="Edit display name"
648
689
  onClick={() => {
649
- signInWithPasskey().catch(reportErr)
690
+ setNameDraft(displayName ?? '')
691
+ setEditingName(true)
650
692
  }}
651
693
  >
652
- {passkeyMode === 'signin' ? 'Waiting for passkey…' : 'Use a passkey'}
694
+ {displayName || 'Unnamed'}
653
695
  </button>
654
- </span>
696
+ )}
697
+ </section>
698
+
699
+ {/* Avatar: picture and character, chosen in place (AvatarPicker).
700
+ Collapsed until Change, so opening the gear costs no request and no
701
+ page load reads the avatar. Hidden for public callers, like the
702
+ content pill: an avatar needs a session. */}
703
+ {!resolving && userType !== 'public' && (
704
+ <section className="settings-popout__row settings-popout__row--stack">
705
+ <span className="settings-popout__inline">
706
+ <span className="settings-popout__label settings-popout__label--grow">
707
+ Avatar
708
+ </span>
709
+ <button
710
+ type="button"
711
+ className="settings-popout__btn"
712
+ aria-expanded={avatarOpen}
713
+ onClick={() => setAvatarOpen(v => !v)}
714
+ >
715
+ {avatarOpen ? 'Done' : 'Change'}
716
+ </button>
717
+ </span>
718
+ {avatarOpen && <AvatarPicker />}
719
+ </section>
655
720
  )}
656
- {/* Cancel on a line of its own: in the row it would slide under
657
- the pointer, and a double click would cancel what it started. */}
658
- {passkeyMode === 'signin' && (
659
- <span className="settings-popout__inline">
660
- <button
661
- type="button"
662
- className="settings-popout__btn"
663
- onClick={() => cancelPasskey()}
721
+ </>
722
+ )}
723
+
724
+ {/* Content visibility level. Held back until the first-open fetch
725
+ settles, so it lands in the same paint as the tier and name
726
+ rather than a round trip behind them. `content` is fetched
727
+ concurrently with whoami(), so by then it is already here. */}
728
+ {activeTab === 'content' && (
729
+ <section className="settings-popout__row settings-popout__row--stack">
730
+ <span className="settings-popout__label">Content visibility</span>
731
+ {content ? (
732
+ <>
733
+ <div
734
+ className="settings-popout__pill"
735
+ role="radiogroup"
736
+ aria-label="Content visibility level"
664
737
  >
665
- Cancel
666
- </button>
667
- </span>
668
- )}
669
- {keyError && (
670
- <span
671
- id="settings-popout-key-error"
672
- className="settings-popout__error"
673
- role="alert"
674
- >
675
- {keyError}
676
- </span>
738
+ {Array.from({ length: content.maxLevel }, (_, i) => i + 1).map(lvl => (
739
+ <button
740
+ key={lvl}
741
+ type="button"
742
+ role="radio"
743
+ aria-checked={lvl === content.level}
744
+ aria-label={`Level ${lvl}`}
745
+ className={`settings-popout__seg${
746
+ lvl <= content.level ? ' settings-popout__seg--filled' : ''
747
+ }`}
748
+ disabled={levelSaving}
749
+ onClick={() => {
750
+ pickLevel(lvl).catch(reportErr)
751
+ }}
752
+ >
753
+ {lvl}
754
+ </button>
755
+ ))}
756
+ </div>
757
+ <span className="settings-popout__hint">
758
+ Higher levels reveal more mature content across apps. Level 1 is
759
+ safe-for-everyone.
760
+ </span>
761
+ </>
762
+ ) : (
763
+ // Not "Loading…" — the fetch has already settled by the time
764
+ // this section renders at all, so a null here means it failed.
765
+ <span className="settings-popout__hint">Currently unavailable.</span>
677
766
  )}
678
- </form>
679
- </section>
680
- ) : (
681
- <section className="settings-popout__row settings-popout__row--stack">
682
- <span className="settings-popout__inline">
683
- <span className="settings-popout__label settings-popout__label--grow">
684
- Access key
685
- </span>
686
- {/* Signed-in people only: the site refuses to save one for anyone else. */}
687
- {!resolving && userType !== 'public' && passkeysSupported() && (
688
- <button
689
- type="button"
690
- className={`settings-popout__btn${needsPasskey ? ` settings-popout__btn--primary ${PASSKEY_PULSE_CLASS}` : ''}`}
691
- disabled={passkeyMode !== null || passkeySaved}
692
- onClick={() => {
693
- savePasskey().catch(reportErr)
694
- }}
695
- >
696
- {passkeySaved
697
- ? 'Passkey saved'
698
- : passkeyMode === 'save'
699
- ? 'Saving…'
700
- : 'Save passkey'}
701
- </button>
767
+ </section>
768
+ )}
769
+
770
+ {/* Switch key. Signs in inline through the SITE's sign-in client
771
+ (the /auth page's own code path), never a post of ours. A real
772
+ <form> with a username + current-password pair, so password
773
+ managers offer and save the key. */}
774
+ {activeTab === 'account' && (
775
+ <>
776
+ {keyFormOpen ? (
777
+ <section className="settings-popout__row settings-popout__row--stack">
778
+ <form
779
+ className="settings-popout__key-form"
780
+ onSubmit={e => {
781
+ e.preventDefault()
782
+ submitKey().catch(reportErr)
783
+ }}
784
+ >
785
+ <input
786
+ type="text"
787
+ name="username"
788
+ autoComplete="username"
789
+ value="hadoku"
790
+ readOnly
791
+ hidden
792
+ />
793
+ <label className="settings-popout__label" htmlFor="settings-popout-key">
794
+ Access key
795
+ </label>
796
+ <span className="settings-popout__inline">
797
+ <input
798
+ id="settings-popout-key"
799
+ className="settings-popout__input"
800
+ type="password"
801
+ name="password"
802
+ autoComplete="current-password"
803
+ autoCapitalize="none"
804
+ spellCheck={false}
805
+ autoFocus
806
+ value={keyDraft}
807
+ disabled={keyBusy}
808
+ aria-invalid={keyError !== null}
809
+ aria-describedby={keyError ? 'settings-popout-key-error' : undefined}
810
+ onChange={e => setKeyDraft(e.target.value)}
811
+ />
812
+ <button
813
+ type="submit"
814
+ className="settings-popout__btn settings-popout__btn--primary"
815
+ disabled={keyBusy}
816
+ >
817
+ {keyBusy ? 'Signing in…' : 'Sign in'}
818
+ </button>
819
+ </span>
820
+ {passkeysSupported() && (
821
+ <span className="settings-popout__inline">
822
+ <button
823
+ type="button"
824
+ className="settings-popout__btn"
825
+ disabled={keyBusy}
826
+ onClick={() => {
827
+ signInWithPasskey().catch(reportErr)
828
+ }}
829
+ >
830
+ {passkeyMode === 'signin' ? 'Waiting for passkey…' : 'Use a passkey'}
831
+ </button>
832
+ </span>
833
+ )}
834
+ {/* Cancel on a line of its own: in the row it would slide under
835
+ the pointer, and a double click would cancel what it started. */}
836
+ {passkeyMode === 'signin' && (
837
+ <span className="settings-popout__inline">
838
+ <button
839
+ type="button"
840
+ className="settings-popout__btn"
841
+ onClick={() => cancelPasskey()}
842
+ >
843
+ Cancel
844
+ </button>
845
+ </span>
846
+ )}
847
+ {keyError && (
848
+ <span
849
+ id="settings-popout-key-error"
850
+ className="settings-popout__error"
851
+ role="alert"
852
+ >
853
+ {keyError}
854
+ </span>
855
+ )}
856
+ </form>
857
+ </section>
858
+ ) : (
859
+ <section className="settings-popout__row settings-popout__row--stack">
860
+ <span className="settings-popout__inline">
861
+ <span className="settings-popout__label settings-popout__label--grow">
862
+ Access key
863
+ </span>
864
+ {/* Signed-in people only: the site refuses to save one for anyone else. */}
865
+ {!resolving && userType !== 'public' && passkeysSupported() && (
866
+ <button
867
+ type="button"
868
+ className={`settings-popout__btn${needsPasskey ? ` settings-popout__btn--primary ${PASSKEY_PULSE_CLASS}` : ''}`}
869
+ disabled={passkeyMode !== null || passkeySaved}
870
+ onClick={() => {
871
+ savePasskey().catch(reportErr)
872
+ }}
873
+ >
874
+ {passkeySaved
875
+ ? 'Passkey saved'
876
+ : passkeyMode === 'save'
877
+ ? 'Saving…'
878
+ : 'Save passkey'}
879
+ </button>
880
+ )}
881
+ <button
882
+ type="button"
883
+ className="settings-popout__btn"
884
+ disabled={passkeyMode === 'save'}
885
+ onClick={openKeyForm}
886
+ >
887
+ Switch key
888
+ </button>
889
+ </span>
890
+ {/* Its own line, so nothing moves under a double click. */}
891
+ {passkeyMode === 'save' && (
892
+ <span className="settings-popout__inline">
893
+ <button
894
+ type="button"
895
+ className="settings-popout__btn"
896
+ onClick={() => cancelPasskey()}
897
+ >
898
+ Cancel
899
+ </button>
900
+ </span>
901
+ )}
902
+ {passkeyError && (
903
+ <span className="settings-popout__error" role="alert">
904
+ {passkeyError}
905
+ </span>
906
+ )}
907
+ </section>
702
908
  )}
703
- <button
704
- type="button"
705
- className="settings-popout__btn"
706
- disabled={passkeyMode === 'save'}
707
- onClick={openKeyForm}
708
- >
709
- Switch key
710
- </button>
711
- </span>
712
- {/* Its own line, so nothing moves under a double click. */}
713
- {passkeyMode === 'save' && (
714
- <span className="settings-popout__inline">
715
- <button
716
- type="button"
717
- className="settings-popout__btn"
718
- onClick={() => cancelPasskey()}
719
- >
720
- Cancel
721
- </button>
722
- </span>
723
- )}
724
- {passkeyError && (
725
- <span className="settings-popout__error" role="alert">
726
- {passkeyError}
727
- </span>
728
- )}
729
- </section>
730
- )}
731
-
732
- {/* A self-made account (member) can delete itself. The confirm is a
909
+
910
+ {/* A self-made account (member) can delete itself. The confirm is a
733
911
  separate button on its own line, so a double click on Delete
734
912
  never confirms. */}
735
- {!resolving && userType === 'member' && (
736
- <section className="settings-popout__row settings-popout__row--stack">
737
- <span className="settings-popout__inline">
738
- <span className="settings-popout__label settings-popout__label--grow">Account</span>
739
- {deleteStage === 'idle' ? (
740
- <button
741
- type="button"
742
- className="settings-popout__btn"
743
- onClick={() => {
744
- setDeleteError(null)
745
- setDeleteStage('confirm')
746
- }}
747
- >
748
- Delete account
749
- </button>
750
- ) : (
751
- <button
752
- type="button"
753
- className="settings-popout__btn"
754
- disabled={deleteStage === 'busy'}
755
- onClick={() => setDeleteStage('idle')}
756
- >
757
- Keep
758
- </button>
759
- )}
760
- </span>
761
- {deleteStage !== 'idle' && (
762
- <span className="settings-popout__inline">
763
- <button
764
- type="button"
765
- className="settings-popout__btn settings-popout__btn--primary"
766
- disabled={deleteStage === 'busy'}
767
- onClick={() => {
768
- setDeleteStage('busy')
769
- deleteOwnAccount()
770
- .then(deleted => {
771
- if (!deleted) {
772
- setDeleteError('Account not deleted')
913
+ {!resolving && userType === 'member' && (
914
+ <section className="settings-popout__row settings-popout__row--stack">
915
+ <span className="settings-popout__inline">
916
+ <span className="settings-popout__label settings-popout__label--grow">
917
+ Account
918
+ </span>
919
+ {deleteStage === 'idle' ? (
920
+ <button
921
+ type="button"
922
+ className="settings-popout__btn"
923
+ onClick={() => {
924
+ setDeleteError(null)
773
925
  setDeleteStage('confirm')
774
- return
775
- }
776
- localStorage.removeItem('hadoku_session_id')
777
- localStorage.removeItem('hadoku_user_type')
778
- window.location.assign('/')
779
- })
780
- .catch(reportErr)
781
- }}
782
- >
783
- {deleteStage === 'busy' ? 'Deleting…' : 'Delete for good'}
784
- </button>
785
- </span>
786
- )}
787
- {deleteError && (
788
- <span className="settings-popout__error" role="alert">
789
- {deleteError}
790
- </span>
791
- )}
792
- </section>
793
- )}
794
-
795
- {/* App-specific settings (optional) — same popout, one gear. */}
796
- {children && (
797
- <section className="settings-popout__row settings-popout__row--stack settings-popout__app">
798
- {children}
799
- </section>
800
- )}
926
+ }}
927
+ >
928
+ Delete account
929
+ </button>
930
+ ) : (
931
+ <button
932
+ type="button"
933
+ className="settings-popout__btn"
934
+ disabled={deleteStage === 'busy'}
935
+ onClick={() => setDeleteStage('idle')}
936
+ >
937
+ Keep
938
+ </button>
939
+ )}
940
+ </span>
941
+ {deleteStage !== 'idle' && (
942
+ <span className="settings-popout__inline">
943
+ <button
944
+ type="button"
945
+ className="settings-popout__btn settings-popout__btn--primary"
946
+ disabled={deleteStage === 'busy'}
947
+ onClick={() => {
948
+ setDeleteStage('busy')
949
+ deleteOwnAccount()
950
+ .then(deleted => {
951
+ if (!deleted) {
952
+ setDeleteError('Account not deleted')
953
+ setDeleteStage('confirm')
954
+ return
955
+ }
956
+ localStorage.removeItem('hadoku_session_id')
957
+ localStorage.removeItem('hadoku_user_type')
958
+ window.location.assign('/')
959
+ })
960
+ .catch(reportErr)
961
+ }}
962
+ >
963
+ {deleteStage === 'busy' ? 'Deleting…' : 'Delete for good'}
964
+ </button>
965
+ </span>
966
+ )}
967
+ {deleteError && (
968
+ <span className="settings-popout__error" role="alert">
969
+ {deleteError}
970
+ </span>
971
+ )}
972
+ </section>
973
+ )}
974
+ </>
975
+ )}
976
+
977
+ {/* App-specific settings (optional) — same popout, one gear. */}
978
+ {activeTab === 'app:' && (
979
+ <section className="settings-popout__row settings-popout__row--stack">
980
+ {children}
981
+ </section>
982
+ )}
983
+ {appTab && (
984
+ <section className="settings-popout__row settings-popout__row--stack">
985
+ {appTab.render()}
986
+ </section>
987
+ )}
988
+ </div>
801
989
  </div>
802
990
  )}
803
991
  </div>