@eifi1/ui-kit 0.35.0 → 0.36.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +35 -5
- package/dist/admin/role-select.d.ts +3 -2
- package/dist/admin/role-select.js +2 -0
- package/dist/admin/role-select.js.map +1 -1
- package/dist/components/amount-input.d.ts +2 -2
- package/dist/components/amount-input.js.map +1 -1
- package/dist/components/autocomplete.d.ts +2 -2
- package/dist/components/autocomplete.js +2 -1
- package/dist/components/autocomplete.js.map +1 -1
- package/dist/components/button-look.d.ts +1 -1
- package/dist/components/button-look.js +9 -4
- package/dist/components/button-look.js.map +1 -1
- package/dist/components/checkbox-group.d.ts +5 -2
- package/dist/components/checkbox-group.js +15 -4
- package/dist/components/checkbox-group.js.map +1 -1
- package/dist/components/column-mapper.d.ts +5 -3
- package/dist/components/column-mapper.js +2 -0
- package/dist/components/column-mapper.js.map +1 -1
- package/dist/components/combobox.d.ts +2 -2
- package/dist/components/combobox.js +2 -1
- package/dist/components/combobox.js.map +1 -1
- package/dist/components/country-select.d.ts +3 -3
- package/dist/components/country-select.js +3 -0
- package/dist/components/country-select.js.map +1 -1
- package/dist/components/currency-select.d.ts +3 -2
- package/dist/components/currency-select.js +10 -1
- package/dist/components/currency-select.js.map +1 -1
- package/dist/components/date-field.d.ts +2 -1
- package/dist/components/date-field.js.map +1 -1
- package/dist/components/date-picker.js +3 -0
- package/dist/components/date-picker.js.map +1 -1
- package/dist/components/date-range-picker.js +3 -0
- package/dist/components/date-range-picker.js.map +1 -1
- package/dist/components/entity-combobox.d.ts +2 -2
- package/dist/components/entity-combobox.js +2 -1
- package/dist/components/entity-combobox.js.map +1 -1
- package/dist/components/field-parts.d.ts +66 -11
- package/dist/components/field-parts.js +32 -10
- package/dist/components/field-parts.js.map +1 -1
- package/dist/components/field-strip.d.ts +3 -2
- package/dist/components/field-strip.js +2 -1
- package/dist/components/field-strip.js.map +1 -1
- package/dist/components/field.d.ts +3 -2
- package/dist/components/field.js +24 -15
- package/dist/components/field.js.map +1 -1
- package/dist/components/help-popover.d.ts +9 -7
- package/dist/components/help-popover.js.map +1 -1
- package/dist/components/icon-picker.d.ts +3 -2
- package/dist/components/icon-picker.js +3 -0
- package/dist/components/icon-picker.js.map +1 -1
- package/dist/components/inline-entity-combobox.d.ts +2 -2
- package/dist/components/inline-entity-combobox.js +2 -1
- package/dist/components/inline-entity-combobox.js.map +1 -1
- package/dist/components/input.d.ts +2 -2
- package/dist/components/input.js +2 -1
- package/dist/components/input.js.map +1 -1
- package/dist/components/month-picker.d.ts +2 -1
- package/dist/components/month-picker.js +8 -1
- package/dist/components/month-picker.js.map +1 -1
- package/dist/components/multi-entity-combobox.d.ts +2 -2
- package/dist/components/multi-entity-combobox.js +2 -1
- package/dist/components/multi-entity-combobox.js.map +1 -1
- package/dist/components/multi-select.d.ts +2 -2
- package/dist/components/multi-select.js +3 -0
- package/dist/components/multi-select.js.map +1 -1
- package/dist/components/number-input.d.ts +2 -2
- package/dist/components/number-input.js.map +1 -1
- package/dist/components/numeric-field.d.ts +5 -2
- package/dist/components/numeric-field.js +4 -1
- package/dist/components/numeric-field.js.map +1 -1
- package/dist/components/one-time-code-input.d.ts +2 -1
- package/dist/components/one-time-code-input.js +2 -1
- package/dist/components/one-time-code-input.js.map +1 -1
- package/dist/components/phone-input.d.ts +1 -1
- package/dist/components/phone-input.js +4 -0
- package/dist/components/phone-input.js.map +1 -1
- package/dist/components/popover.js +1 -1
- package/dist/components/popover.js.map +1 -1
- package/dist/components/select.d.ts +4 -3
- package/dist/components/select.js +2 -1
- package/dist/components/select.js.map +1 -1
- package/dist/components/slider.d.ts +3 -2
- package/dist/components/slider.js +7 -1
- package/dist/components/slider.js.map +1 -1
- package/dist/components/stat-tile.js +2 -11
- package/dist/components/stat-tile.js.map +1 -1
- package/dist/components/swatch-picker.d.ts +3 -2
- package/dist/components/swatch-picker.js +3 -0
- package/dist/components/swatch-picker.js.map +1 -1
- package/dist/components/text-link.js +3 -1
- package/dist/components/text-link.js.map +1 -1
- package/dist/components/textarea.d.ts +2 -1
- package/dist/components/textarea.js +9 -3
- package/dist/components/textarea.js.map +1 -1
- package/dist/components/toggle-group.d.ts +2 -2
- package/dist/components/toggle-group.js +7 -3
- package/dist/components/toggle-group.js.map +1 -1
- package/dist/eslint/index.js +1 -1
- package/dist/i18n/defaults.js +5 -1
- package/dist/i18n/defaults.js.map +1 -1
- package/dist/i18n/german.js +97 -1
- package/dist/i18n/german.js.map +1 -1
- package/dist/i18n/kit-labels.d.ts +15 -0
- package/dist/i18n/kit-labels.js +21 -1
- package/dist/i18n/kit-labels.js.map +1 -1
- package/dist/i18n/locales/en.js +103 -2
- package/dist/i18n/locales/en.js.map +3 -3
- package/dist/i18n/locales/es.js +95 -1
- package/dist/i18n/locales/es.js.map +1 -1
- package/dist/i18n/locales/fr.js +96 -1
- package/dist/i18n/locales/fr.js.map +1 -1
- package/dist/i18n/locales/hu.js +95 -1
- package/dist/i18n/locales/hu.js.map +1 -1
- package/dist/i18n/locales/it.js +96 -1
- package/dist/i18n/locales/it.js.map +1 -1
- package/dist/i18n/locales/zh.js +95 -1
- package/dist/i18n/locales/zh.js.map +1 -1
- package/dist/i18n/review.js +13 -0
- package/dist/i18n/review.js.map +1 -1
- package/dist/i18n/shared-labels.js +3 -1
- package/dist/i18n/shared-labels.js.map +1 -1
- package/dist/index.d.ts +21 -0
- package/dist/index.js +38 -0
- package/dist/index.js.map +1 -1
- package/dist/lib/device-settings.d.ts +72 -0
- package/dist/lib/device-settings.js +64 -0
- package/dist/lib/device-settings.js.map +1 -0
- package/dist/lib/plain-text.d.ts +11 -0
- package/dist/lib/plain-text.js +16 -0
- package/dist/lib/plain-text.js.map +1 -0
- package/dist/lib/safe-storage.d.ts +6 -0
- package/dist/lib/safe-storage.js +11 -0
- package/dist/lib/safe-storage.js.map +1 -1
- package/dist/notifications/notification-parts.d.ts +39 -0
- package/dist/notifications/notification-parts.js +47 -0
- package/dist/notifications/notification-parts.js.map +1 -0
- package/dist/notifications/notification-types-setting.d.ts +62 -0
- package/dist/notifications/notification-types-setting.js +192 -0
- package/dist/notifications/notification-types-setting.js.map +1 -0
- package/dist/notifications/notification-types.d.ts +75 -0
- package/dist/notifications/notification-types.js +2 -0
- package/dist/notifications/notification-types.js.map +1 -0
- package/dist/notifications/notifications-labels.d.ts +131 -0
- package/dist/notifications/notifications-labels.js +83 -0
- package/dist/notifications/notifications-labels.js.map +1 -0
- package/dist/notifications/push-device-setting.d.ts +37 -0
- package/dist/notifications/push-device-setting.js +164 -0
- package/dist/notifications/push-device-setting.js.map +1 -0
- package/dist/notifications/push-devices-setting.d.ts +44 -0
- package/dist/notifications/push-devices-setting.js +203 -0
- package/dist/notifications/push-devices-setting.js.map +1 -0
- package/dist/notifications/quiet-hours-setting.d.ts +47 -0
- package/dist/notifications/quiet-hours-setting.js +131 -0
- package/dist/notifications/quiet-hours-setting.js.map +1 -0
- package/dist/notifications/time-zone-select.d.ts +50 -0
- package/dist/notifications/time-zone-select.js +76 -0
- package/dist/notifications/time-zone-select.js.map +1 -0
- package/dist/notifications/unsubscribe-panel.d.ts +53 -0
- package/dist/notifications/unsubscribe-panel.js +139 -0
- package/dist/notifications/unsubscribe-panel.js.map +1 -0
- package/dist/notifications/use-push-device.d.ts +122 -0
- package/dist/notifications/use-push-device.js +230 -0
- package/dist/notifications/use-push-device.js.map +1 -0
- package/dist/rhf/fields.d.ts +26 -19
- package/dist/rhf/fields.js +51 -22
- package/dist/rhf/fields.js.map +1 -1
- package/dist/settings/device-reset-setting-labels.d.ts +3 -0
- package/dist/settings/device-reset-setting-labels.js +15 -0
- package/dist/settings/device-reset-setting-labels.js.map +1 -0
- package/dist/settings/device-reset-setting.d.ts +58 -0
- package/dist/settings/device-reset-setting.js +51 -0
- package/dist/settings/device-reset-setting.js.map +1 -0
- package/dist/shell/app-shell.js +5 -0
- package/dist/shell/app-shell.js.map +1 -1
- package/dist/theme/contrast-tokens.d.ts +42 -4
- package/dist/theme/contrast-tokens.js +56 -9
- package/dist/theme/contrast-tokens.js.map +1 -1
- package/dist/theme/contrast.d.ts +4 -2
- package/dist/theme/contrast.js +13 -0
- package/dist/theme/contrast.js.map +1 -1
- package/dist/theme/palette-derive.d.ts +15 -1
- package/dist/theme/palette-derive.js +37 -8
- package/dist/theme/palette-derive.js.map +1 -1
- package/dist/theme/palette-presets.d.ts +2 -1
- package/dist/theme/palette-presets.js +5 -5
- package/dist/theme/palette-presets.js.map +1 -1
- package/dist/theme/palette-store.js +6 -0
- package/dist/theme/palette-store.js.map +1 -1
- package/dist/theme/text-size.js +6 -0
- package/dist/theme/text-size.js.map +1 -1
- package/dist/theme/theme-store.js +6 -0
- package/dist/theme/theme-store.js.map +1 -1
- package/package.json +1 -1
- package/src/admin/role-select.tsx +4 -1
- package/src/components/amount-input.tsx +2 -1
- package/src/components/autocomplete.tsx +5 -2
- package/src/components/button-look.ts +15 -5
- package/src/components/checkbox-group.tsx +22 -4
- package/src/components/column-mapper.tsx +6 -2
- package/src/components/combobox.tsx +5 -2
- package/src/components/country-select.tsx +6 -1
- package/src/components/currency-select.tsx +12 -3
- package/src/components/date-field.tsx +2 -2
- package/src/components/date-picker.tsx +3 -0
- package/src/components/date-range-picker.tsx +3 -0
- package/src/components/entity-combobox.tsx +5 -2
- package/src/components/field-parts.tsx +107 -19
- package/src/components/field-strip.tsx +4 -3
- package/src/components/field.tsx +28 -15
- package/src/components/help-popover.tsx +9 -7
- package/src/components/icon-picker.tsx +8 -3
- package/src/components/inline-entity-combobox.tsx +5 -2
- package/src/components/input.tsx +4 -2
- package/src/components/month-picker.tsx +10 -3
- package/src/components/multi-entity-combobox.tsx +5 -2
- package/src/components/multi-select.tsx +6 -1
- package/src/components/number-input.tsx +2 -2
- package/src/components/numeric-field.ts +10 -2
- package/src/components/one-time-code-input.tsx +5 -3
- package/src/components/phone-input.tsx +4 -0
- package/src/components/popover.tsx +3 -1
- package/src/components/select.tsx +6 -3
- package/src/components/slider.tsx +10 -3
- package/src/components/stat-tile.tsx +3 -18
- package/src/components/swatch-picker.tsx +9 -4
- package/src/components/text-link.tsx +3 -1
- package/src/components/textarea.tsx +11 -4
- package/src/components/toggle-group.tsx +21 -5
- package/src/i18n/defaults.ts +4 -0
- package/src/i18n/german.ts +113 -0
- package/src/i18n/kit-labels.tsx +51 -1
- package/src/i18n/locales/en.ts +6 -0
- package/src/i18n/locales/es.ts +106 -0
- package/src/i18n/locales/fr.ts +106 -0
- package/src/i18n/locales/hu.ts +104 -0
- package/src/i18n/locales/it.ts +105 -0
- package/src/i18n/locales/zh.ts +96 -0
- package/src/i18n/review.ts +13 -0
- package/src/i18n/shared-labels.ts +2 -0
- package/src/index.ts +50 -0
- package/src/lib/device-settings.ts +146 -0
- package/src/lib/plain-text.ts +22 -0
- package/src/lib/safe-storage.ts +16 -0
- package/src/notifications/notification-parts.tsx +83 -0
- package/src/notifications/notification-types-setting.tsx +309 -0
- package/src/notifications/notification-types.ts +80 -0
- package/src/notifications/notifications-labels.ts +238 -0
- package/src/notifications/push-device-setting.tsx +224 -0
- package/src/notifications/push-devices-setting.tsx +306 -0
- package/src/notifications/quiet-hours-setting.tsx +185 -0
- package/src/notifications/time-zone-select.tsx +126 -0
- package/src/notifications/unsubscribe-panel.tsx +203 -0
- package/src/notifications/use-push-device.ts +392 -0
- package/src/rhf/fields.tsx +77 -29
- package/src/settings/device-reset-setting-labels.ts +20 -0
- package/src/settings/device-reset-setting.tsx +119 -0
- package/src/shell/app-shell.tsx +8 -0
- package/src/theme/contrast-tokens.ts +106 -12
- package/src/theme/contrast.ts +30 -4
- package/src/theme/palette-derive.ts +68 -7
- package/src/theme/palette-presets.ts +9 -6
- package/src/theme/palette-store.ts +12 -0
- package/src/theme/text-size.ts +8 -0
- package/src/theme/theme-store.ts +10 -0
- package/tokens.css +38 -4
|
@@ -37,6 +37,8 @@ export const DEFAULT_COMMON_LABELS: CommonLabels = {
|
|
|
37
37
|
fieldValue: (field, value) => `${field}: ${value}`,
|
|
38
38
|
dismiss: "Dismiss",
|
|
39
39
|
opensInNewTab: "opens in a new tab",
|
|
40
|
+
aboutField: (field) => `About ${field}`,
|
|
41
|
+
help: "Help",
|
|
40
42
|
};
|
|
41
43
|
|
|
42
44
|
export const DEFAULT_DATE_PICKER_LABELS: DatePickerLabels = {
|
package/src/index.ts
CHANGED
|
@@ -856,6 +856,13 @@ export type { PlanLimitToastOptions } from "./billing/plan-limit-toast";
|
|
|
856
856
|
// come with `./shell` above (also `@eifi1/ui-kit/shell`).
|
|
857
857
|
export { DEFAULT_SETTINGS_LABELS, useSettingsLabels } from "./settings/settings-labels";
|
|
858
858
|
export type { SettingsLabels, SettingsGroupLabels, SettingsCoreGroup } from "./settings/settings-labels";
|
|
859
|
+
// 0.36.0 (§11): "Reset this device's settings" — the registry the kit's stores, provider
|
|
860
|
+
// and shell join on their own and an app adds its own device keys to, and the card, the
|
|
861
|
+
// appearance group's last.
|
|
862
|
+
export { registerDeviceSetting, deviceSettings, resetDeviceSettings } from "./lib/device-settings";
|
|
863
|
+
export type { DeviceSetting, DeviceSettingKind } from "./lib/device-settings";
|
|
864
|
+
export { DeviceResetSetting, DEVICE_RESET_ANCHOR, DEFAULT_DEVICE_RESET_LABELS } from "./settings/device-reset-setting";
|
|
865
|
+
export type { DeviceResetSettingProps, DeviceResetLabels } from "./settings/device-reset-setting";
|
|
859
866
|
// The language follows the account (§6.2); since 0.32 so do the text size and the
|
|
860
867
|
// contrast (useAccountAppearance below, docs/text-size-harmonization.md §6).
|
|
861
868
|
export { useAccountLanguage, resolveAccountLanguage, matchOfferedLanguage } from "./settings/use-account-language";
|
|
@@ -877,6 +884,49 @@ export type {
|
|
|
877
884
|
AccountAppearance,
|
|
878
885
|
} from "./settings/use-account-appearance";
|
|
879
886
|
|
|
887
|
+
// ── notifications ────────────────────────────────────────────────────────────
|
|
888
|
+
// 0.36.0 (docs/notifications-harmonization.md §4.2): the notification cards — the types
|
|
889
|
+
// the server answers (the kit keeps no list of its own), quiet hours with the zone picker,
|
|
890
|
+
// this device's push on its hook, the device list — and the signed-out unsubscribe page.
|
|
891
|
+
// Each card takes the app's request functions; the kit makes no request itself.
|
|
892
|
+
export { DEFAULT_NOTIFICATIONS_LABELS } from "./notifications/notifications-labels";
|
|
893
|
+
export type { NotificationsLabels, NotificationRegionLabels } from "./notifications/notifications-labels";
|
|
894
|
+
export type {
|
|
895
|
+
DigestCadence,
|
|
896
|
+
NotificationSwitches,
|
|
897
|
+
NotificationTypesValue,
|
|
898
|
+
NotificationTypeEntry,
|
|
899
|
+
NotificationTypeGroup,
|
|
900
|
+
NotificationSettingsPatch,
|
|
901
|
+
PushDeviceItem,
|
|
902
|
+
} from "./notifications/notification-types";
|
|
903
|
+
export { NotificationTypesSetting } from "./notifications/notification-types-setting";
|
|
904
|
+
export type { NotificationTypesSettingProps } from "./notifications/notification-types-setting";
|
|
905
|
+
export { QuietHoursSetting } from "./notifications/quiet-hours-setting";
|
|
906
|
+
export type { QuietHoursSettingProps } from "./notifications/quiet-hours-setting";
|
|
907
|
+
export { TimeZoneSelect, timeZoneOptions, deviceTimeZone } from "./notifications/time-zone-select";
|
|
908
|
+
export type { TimeZoneSelectProps } from "./notifications/time-zone-select";
|
|
909
|
+
export {
|
|
910
|
+
usePushDevice,
|
|
911
|
+
PUSH_SUBSCRIPTION_CHANGED,
|
|
912
|
+
notifyPushSubscriptionChanged,
|
|
913
|
+
pushSupported,
|
|
914
|
+
PushDeviceError,
|
|
915
|
+
} from "./notifications/use-push-device";
|
|
916
|
+
export type {
|
|
917
|
+
PushDevice,
|
|
918
|
+
UsePushDeviceOptions,
|
|
919
|
+
PushSubscriptionInput,
|
|
920
|
+
PushPermission,
|
|
921
|
+
PushDeviceErrorCode,
|
|
922
|
+
} from "./notifications/use-push-device";
|
|
923
|
+
export { PushDeviceSetting } from "./notifications/push-device-setting";
|
|
924
|
+
export type { PushDeviceSettingProps, PushDeviceAction } from "./notifications/push-device-setting";
|
|
925
|
+
export { PushDevicesSetting, describeUserAgent } from "./notifications/push-devices-setting";
|
|
926
|
+
export type { PushDevicesSettingProps } from "./notifications/push-devices-setting";
|
|
927
|
+
export { UnsubscribePanel, unsubscribeTokenType } from "./notifications/unsubscribe-panel";
|
|
928
|
+
export type { UnsubscribePanelProps } from "./notifications/unsubscribe-panel";
|
|
929
|
+
|
|
880
930
|
// ── landing ──────────────────────────────────────────────────────────────────
|
|
881
931
|
// 0.31.0 (docs/landing-demo-harmonization.md): the public landing page. Its router-aware parts — the header and the resume (RootEntry,
|
|
882
932
|
// RedirectIfAuthed, the last-visited page) — come with `./shell` above.
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { readSessionStored, readStored, removeStored, storedKeys, writeSessionStored } from "./safe-storage";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* What this device keeps of how it shows the app, and the one action that puts it all
|
|
5
|
+
* back: "Reset this device's settings" (docs/settings-harmonization.md §11).
|
|
6
|
+
*
|
|
7
|
+
* A registry, because no one part knows every key. The kit's own stores and components
|
|
8
|
+
* join it themselves — the theme, palette, text-size and contrast stores when they are
|
|
9
|
+
* created, `UiKitProvider` (the prefix its tables keep their views under) and `AppShell`
|
|
10
|
+
* (the sidebar's folded state) while they are mounted — and an app adds its own keys
|
|
11
|
+
* beside the store or accessor that owns each (keksdose's date format, kastlan's
|
|
12
|
+
* language, Kurvenschmiede's curve channels). {@link resetDeviceSettings} then clears
|
|
13
|
+
* exactly what joined, and nothing else: the sign-in, the session, what waits to be sent
|
|
14
|
+
* and the account never join (§11.2 decision 2), so a key nobody registered survives.
|
|
15
|
+
*
|
|
16
|
+
* No React and no router: a store joins at module scope, when it is created. Here in
|
|
17
|
+
* `src/lib` beside `safe-storage.ts`, which the stores and the shell already import, so
|
|
18
|
+
* `src/theme` and `src/shell` do not import `src/settings`. One module instance, one
|
|
19
|
+
* module-level list.
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
/** What a reset of this device's settings clears (§11.2 decision 1): how the app looks
|
|
23
|
+
* here, and how its tables and panels were left. An app's own list may add a third kind
|
|
24
|
+
* of its own for what never goes (Kurvenschmiede's "never"). */
|
|
25
|
+
export type DeviceSettingKind = "appearance" | "view";
|
|
26
|
+
|
|
27
|
+
export interface DeviceSetting {
|
|
28
|
+
/** The storage key; with `prefix`, every key that starts with it. */
|
|
29
|
+
key: string;
|
|
30
|
+
/** `true`: `key` is a prefix (a table's views, keksdose's display currency per budget).
|
|
31
|
+
* It matches by `startsWith`: `budget.displayCurrency.` does not take the legacy
|
|
32
|
+
* `budget.displayCurrency`. */
|
|
33
|
+
prefix?: boolean;
|
|
34
|
+
/** Default `"local"`. */
|
|
35
|
+
storage?: "local" | "session";
|
|
36
|
+
kind: DeviceSettingKind;
|
|
37
|
+
/**
|
|
38
|
+
* Puts the live value back to its default through the store's own setter, the one its
|
|
39
|
+
* control calls, so whatever that setter also does still happens — never
|
|
40
|
+
* `setState(getInitialState())`, which skips it. REQUIRED for anything held in memory:
|
|
41
|
+
* every persisted zustand store (removing its key alone, it writes its value back on its
|
|
42
|
+
* next change), a mounted component's state. With `reset` the key is left to it (a
|
|
43
|
+
* persisted store writes its default itself); without, the key, or every key under the
|
|
44
|
+
* prefix, is removed — for what is read where it is next used (a table at its mount, a
|
|
45
|
+
* plain accessor).
|
|
46
|
+
*/
|
|
47
|
+
reset?: () => void;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** Whoever joined one key, in join order; the last one's entry is the key's entry. */
|
|
51
|
+
type Holders = { entry: DeviceSetting }[];
|
|
52
|
+
|
|
53
|
+
/** One slot per key and storage area, in the order each was first joined. */
|
|
54
|
+
const slots = new Map<string, Holders>();
|
|
55
|
+
|
|
56
|
+
const areaOf = (entry: DeviceSetting): "local" | "session" => (entry.storage === "session" ? "session" : "local");
|
|
57
|
+
const slotOf = (entry: DeviceSetting) => `${areaOf(entry)}:${entry.key}`;
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Join the registry; answers the leave function. A store joins once, at creation, and
|
|
61
|
+
* never leaves; a component joins while mounted and leaves in its effect's cleanup.
|
|
62
|
+
*
|
|
63
|
+
* **One entry per key** (and storage area): joining a key again replaces its entry and
|
|
64
|
+
* adds a holder, and a leave drops its holder — the entry goes with the last one, and
|
|
65
|
+
* until then the latest remaining holder's entry is the key's. So a module evaluated twice
|
|
66
|
+
* (a test, a hot reload) does not reset twice, and two nested providers with one prefix
|
|
67
|
+
* keep their entry until the outer one unmounts.
|
|
68
|
+
*/
|
|
69
|
+
export function registerDeviceSetting(entry: DeviceSetting): () => void {
|
|
70
|
+
const slot = slotOf(entry);
|
|
71
|
+
const holder = { entry: { ...entry } };
|
|
72
|
+
const holders = slots.get(slot);
|
|
73
|
+
if (holders) holders.push(holder);
|
|
74
|
+
else slots.set(slot, [holder]);
|
|
75
|
+
let left = false;
|
|
76
|
+
return () => {
|
|
77
|
+
if (left) return;
|
|
78
|
+
left = true;
|
|
79
|
+
// A holder that has not left is in its slot: only its own leave takes it out, and a
|
|
80
|
+
// slot goes only once it is empty.
|
|
81
|
+
const current = slots.get(slot) as Holders;
|
|
82
|
+
current.splice(current.indexOf(holder), 1);
|
|
83
|
+
if (current.length === 0) slots.delete(slot);
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** Every entry, in join order: for an app's own test (Kurvenschmiede holds it to its
|
|
88
|
+
* `STORAGE` list) or its privacy page. */
|
|
89
|
+
export function deviceSettings(): readonly DeviceSetting[] {
|
|
90
|
+
return [...slots.values()].map((holders) => holders[holders.length - 1].entry);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** Is this a development build? `import.meta.env` is a Vite injection, absent under Node. */
|
|
94
|
+
function devBuild(): boolean {
|
|
95
|
+
return Boolean(import.meta.env?.DEV);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** The keys an entry covers now: a prefix's keys found under it, else its own key. */
|
|
99
|
+
function keysOf(entry: DeviceSetting): string[] {
|
|
100
|
+
return entry.prefix ? storedKeys(entry.key, areaOf(entry)) : [entry.key];
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/** Remove what `entry` covers; answers the keys that were there. */
|
|
104
|
+
function removeEntry(entry: DeviceSetting): string[] {
|
|
105
|
+
const session = areaOf(entry) === "session";
|
|
106
|
+
const present = keysOf(entry).filter((key) => (session ? readSessionStored(key) : readStored(key)) !== null);
|
|
107
|
+
for (const key of present) {
|
|
108
|
+
if (session) writeSessionStored(key, null);
|
|
109
|
+
else removeStored(key);
|
|
110
|
+
}
|
|
111
|
+
return present;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Reset every entry, at once; answers the keys it reset or removed, prefixes expanded.
|
|
116
|
+
*
|
|
117
|
+
* Synchronous, in two passes: first every `reset`, in join order, so each live store puts
|
|
118
|
+
* its value back (and writes its default); then the keys of the entries without one. A
|
|
119
|
+
* `reset` that throws is caught (`console.error` in development), its key is removed
|
|
120
|
+
* instead, and the rest still run. It never reloads, navigates or sends a request, and
|
|
121
|
+
* never touches a key nobody registered. Where the browser refuses storage, the live
|
|
122
|
+
* values still reset and nothing throws.
|
|
123
|
+
*
|
|
124
|
+
* The answer: an entry with a `reset` lists its key (a prefix, the keys found under it);
|
|
125
|
+
* an entry without lists the keys it removed, those that were there.
|
|
126
|
+
*/
|
|
127
|
+
export function resetDeviceSettings(): string[] {
|
|
128
|
+
const keys: string[] = [];
|
|
129
|
+
const remove: DeviceSetting[] = [];
|
|
130
|
+
for (const entry of deviceSettings()) {
|
|
131
|
+
if (!entry.reset) {
|
|
132
|
+
remove.push(entry);
|
|
133
|
+
continue;
|
|
134
|
+
}
|
|
135
|
+
const covered = keysOf(entry);
|
|
136
|
+
try {
|
|
137
|
+
entry.reset();
|
|
138
|
+
keys.push(...covered);
|
|
139
|
+
} catch (error) {
|
|
140
|
+
if (devBuild()) console.error(`resetDeviceSettings: the reset of "${entry.key}" threw; its key is removed instead.`, error);
|
|
141
|
+
remove.push(entry);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
for (const entry of remove) keys.push(...removeEntry(entry));
|
|
145
|
+
return [...new Set(keys)];
|
|
146
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { isValidElement } from "react";
|
|
2
|
+
import type { ReactNode } from "react";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The text of a label node: a string or number as is, an element by its children,
|
|
6
|
+
* recursively, whitespace collapsed. A `<Tooltip label="…">Spend</Tooltip>` label yields
|
|
7
|
+
* "Spend" — the text the reader sees, not the bubble's. `undefined` when there is no text
|
|
8
|
+
* to find (an icon), so the caller falls back to a name of its own.
|
|
9
|
+
*
|
|
10
|
+
* Package-private — not re-exported from the barrel. StatTile names its sparkline by it;
|
|
11
|
+
* a field names its `help` "?" by it ("About <label>", round 0.36).
|
|
12
|
+
*/
|
|
13
|
+
export function plainText(node: ReactNode): string | undefined {
|
|
14
|
+
const walk = (n: ReactNode): string => {
|
|
15
|
+
if (typeof n === "string" || typeof n === "number") return String(n);
|
|
16
|
+
if (Array.isArray(n)) return n.map(walk).join("");
|
|
17
|
+
if (isValidElement<{ children?: ReactNode }>(n)) return walk(n.props.children);
|
|
18
|
+
return "";
|
|
19
|
+
};
|
|
20
|
+
const text = walk(node).replace(/\s+/g, " ").trim();
|
|
21
|
+
return text === "" ? undefined : text;
|
|
22
|
+
}
|
package/src/lib/safe-storage.ts
CHANGED
|
@@ -59,3 +59,19 @@ export function writeSessionStored(key: string, value: string | null): void {
|
|
|
59
59
|
value === null ? storage.removeItem(key) : storage.setItem(key, value),
|
|
60
60
|
);
|
|
61
61
|
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Every key in `area` that starts with `prefix`, or `[]` where storage refuses — for the
|
|
65
|
+
* reset of this device's settings, which removes a table's views by their prefix
|
|
66
|
+
* (docs/settings-harmonization.md §11.4). Package-private, like {@link removeStored}.
|
|
67
|
+
*/
|
|
68
|
+
export function storedKeys(prefix: string, area: "local" | "session" = "local"): string[] {
|
|
69
|
+
return guarded(area === "session" ? "sessionStorage" : "localStorage", [], (storage) => {
|
|
70
|
+
const keys: string[] = [];
|
|
71
|
+
for (let i = 0; i < storage.length; i++) {
|
|
72
|
+
const key = storage.key(i);
|
|
73
|
+
if (key !== null && key.startsWith(prefix)) keys.push(key);
|
|
74
|
+
}
|
|
75
|
+
return keys;
|
|
76
|
+
});
|
|
77
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { useState } from "react";
|
|
2
|
+
import type { ReactNode } from "react";
|
|
3
|
+
|
|
4
|
+
import { useKitLabels, type LabelOverride } from "../i18n/kit-labels";
|
|
5
|
+
import { hasContent } from "../lib/presence";
|
|
6
|
+
import { AlertBanner } from "../components/alert-banner";
|
|
7
|
+
import { DEFAULT_NOTIFICATIONS_LABELS } from "./notifications-labels";
|
|
8
|
+
import type { NotificationsLabels } from "./notifications-labels";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* What the notification cards share: their words, the failure line under a card, and
|
|
12
|
+
* the overlay a card shows while its write runs.
|
|
13
|
+
*
|
|
14
|
+
* @internal Not part of the barrel; the cards are.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
/** The `notifications` namespace: English, then the provider, then the card's prop. */
|
|
18
|
+
export function useNotificationsLabels(prop?: LabelOverride<NotificationsLabels>): NotificationsLabels {
|
|
19
|
+
return useKitLabels("notifications", DEFAULT_NOTIFICATIONS_LABELS, prop);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** The app's words for a failure, else `fallback`. */
|
|
23
|
+
export function describeFailure(own: ReactNode | undefined, fallback: ReactNode): ReactNode {
|
|
24
|
+
return hasContent(own) ? own : fallback;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** A failure, said under the card's controls — nothing toasts (§4.2). */
|
|
28
|
+
export function FailureLine({ children }: { children: ReactNode }) {
|
|
29
|
+
if (!hasContent(children)) return null;
|
|
30
|
+
return (
|
|
31
|
+
<AlertBanner tone="danger" size="sm" role="alert">
|
|
32
|
+
{children}
|
|
33
|
+
</AlertBanner>
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** What {@link useWriteOverlay} answers. */
|
|
38
|
+
export interface WriteOverlay<V> {
|
|
39
|
+
has: (key: string) => boolean;
|
|
40
|
+
get: (key: string) => V | undefined;
|
|
41
|
+
pending: (key: string) => boolean;
|
|
42
|
+
set: (key: string, value: V) => void;
|
|
43
|
+
settle: (key: string, ok: boolean) => void;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Values a card shows while its write runs, over what the server last answered.
|
|
48
|
+
*
|
|
49
|
+
* `set(key, value)` shows `value` at once; `settle(key, ok)` drops it again when the
|
|
50
|
+
* write failed (the server's value comes back) and keeps it when it succeeded, until the
|
|
51
|
+
* app hands the card a new `source` — the PATCH's answer, or a refetch — which clears
|
|
52
|
+
* every settled entry, so a card whose app does not update its query on success does not
|
|
53
|
+
* flick back to the old value in between. `pending(key)` says whether a write for `key`
|
|
54
|
+
* is still running.
|
|
55
|
+
*
|
|
56
|
+
* The reset on a new `source` is React's "adjust state while rendering" pattern, not an
|
|
57
|
+
* effect: the overlay is gone in the same render that shows the new value.
|
|
58
|
+
*/
|
|
59
|
+
export function useWriteOverlay<V>(source: unknown): WriteOverlay<V> {
|
|
60
|
+
const [entries, setEntries] = useState<ReadonlyMap<string, { value: V; running: boolean }>>(new Map());
|
|
61
|
+
const [seen, setSeen] = useState(source);
|
|
62
|
+
if (seen !== source) {
|
|
63
|
+
setSeen(source);
|
|
64
|
+
const kept = new Map([...entries].filter(([, entry]) => entry.running));
|
|
65
|
+
if (kept.size !== entries.size) setEntries(kept);
|
|
66
|
+
}
|
|
67
|
+
return {
|
|
68
|
+
has: (key: string) => entries.has(key),
|
|
69
|
+
get: (key: string) => entries.get(key)?.value,
|
|
70
|
+
pending: (key: string) => entries.get(key)?.running === true,
|
|
71
|
+
set: (key: string, value: V) =>
|
|
72
|
+
setEntries((current) => new Map(current).set(key, { value, running: true })),
|
|
73
|
+
settle: (key: string, ok: boolean) =>
|
|
74
|
+
setEntries((current) => {
|
|
75
|
+
const entry = current.get(key);
|
|
76
|
+
if (!entry) return current;
|
|
77
|
+
const next = new Map(current);
|
|
78
|
+
if (ok) next.set(key, { value: entry.value, running: false });
|
|
79
|
+
else next.delete(key);
|
|
80
|
+
return next;
|
|
81
|
+
}),
|
|
82
|
+
};
|
|
83
|
+
}
|
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
import { useId, useState } from "react";
|
|
2
|
+
import type { ComponentPropsWithRef, ReactNode } from "react";
|
|
3
|
+
|
|
4
|
+
import type { LabelOverride } from "../i18n/kit-labels";
|
|
5
|
+
import { cn } from "../lib/cn";
|
|
6
|
+
import { hasContent } from "../lib/presence";
|
|
7
|
+
import { Card } from "../components/card";
|
|
8
|
+
import { Select } from "../components/select";
|
|
9
|
+
import { Skeleton } from "../components/skeleton";
|
|
10
|
+
import { Switch } from "../components/switch";
|
|
11
|
+
import { SectionLabel } from "../components/text";
|
|
12
|
+
import { COMMIT_EXCEPT_BILLING } from "../components/write-lock";
|
|
13
|
+
import { CARD_DESCRIPTION_CLASS } from "../settings/settings-card-classes";
|
|
14
|
+
import { SettingsCardTitle } from "../settings/settings-heading";
|
|
15
|
+
import { settle, useMounted } from "../account/account-parts";
|
|
16
|
+
import { describeFailure, FailureLine, useNotificationsLabels, useWriteOverlay } from "./notification-parts";
|
|
17
|
+
import type { WriteOverlay } from "./notification-parts";
|
|
18
|
+
import type { NotificationsLabels } from "./notifications-labels";
|
|
19
|
+
import type {
|
|
20
|
+
DigestCadence,
|
|
21
|
+
NotificationSettingsPatch,
|
|
22
|
+
NotificationSwitches,
|
|
23
|
+
NotificationTypeEntry,
|
|
24
|
+
NotificationTypeGroup,
|
|
25
|
+
NotificationTypesValue,
|
|
26
|
+
} from "./notification-types";
|
|
27
|
+
|
|
28
|
+
/** Is this a development build? Dead code in a consumer's production bundle; on under
|
|
29
|
+
* vitest, where a type the card cannot draw is a bug a test should fail on (as
|
|
30
|
+
* `SettingsSection`'s catalogue check). */
|
|
31
|
+
function devChecks(): boolean {
|
|
32
|
+
return Boolean(import.meta.env?.DEV);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface NotificationTypesSettingProps<Id extends string = string>
|
|
36
|
+
extends Omit<ComponentPropsWithRef<"div">, "children" | "onChange"> {
|
|
37
|
+
/** The app's words for its types, in its order. Where an app types its ids. */
|
|
38
|
+
types: readonly NotificationTypeEntry<Id>[];
|
|
39
|
+
/** The `GET`'s `types` (§3.2); `undefined` while the first load runs. */
|
|
40
|
+
value: NotificationTypesValue | undefined;
|
|
41
|
+
/** The settings are loading. */
|
|
42
|
+
loading?: boolean;
|
|
43
|
+
/**
|
|
44
|
+
* Save one change — `PATCH /notifications/settings` with this body: one switch per
|
|
45
|
+
* call (`{types: {digest: {app: true}}}`), or `{digest_cadence}`. The switch shows its
|
|
46
|
+
* new state while the call runs and goes back if it rejects; hand the card the
|
|
47
|
+
* PATCH's answer (or refetch) when it resolves.
|
|
48
|
+
*/
|
|
49
|
+
onChange: (patch: NotificationSettingsPatch<Id>) => Promise<unknown> | void;
|
|
50
|
+
/** Headings over the types, in the app's words (keksdose's three). Without them, one
|
|
51
|
+
* list in the order of `types`. In development every type the server answered must
|
|
52
|
+
* be in one. */
|
|
53
|
+
groups?: readonly NotificationTypeGroup<Id>[];
|
|
54
|
+
/** The digest type and the account's cadence: a cadence `Select` under that type
|
|
55
|
+
* while it is on. */
|
|
56
|
+
digest?: { type: Id; cadence: DigestCadence };
|
|
57
|
+
/** Under a type while it is on — keksdose's low-balance threshold field. */
|
|
58
|
+
renderExtra?: (id: Id) => ReactNode;
|
|
59
|
+
/** The account's address is unverified: every e-mail switch says
|
|
60
|
+
* `labels.emailUnverified` under it (decision 16). */
|
|
61
|
+
emailUnverified?: boolean;
|
|
62
|
+
/** Nothing can be changed (the switches stay readable). */
|
|
63
|
+
disabled?: boolean;
|
|
64
|
+
/** The app's own words for a failed save, or `undefined` for the kit's `failed`. */
|
|
65
|
+
describeError?: (error: unknown) => ReactNode | undefined;
|
|
66
|
+
labels?: LabelOverride<NotificationsLabels>;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** One drawn type: the app's words and the server's switches. */
|
|
70
|
+
interface Row<Id extends string> {
|
|
71
|
+
entry: NotificationTypeEntry<Id>;
|
|
72
|
+
switches: NotificationSwitches;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** A switch's key in the write overlay. */
|
|
76
|
+
const switchKey = (id: string, channel: "app" | "email") => `${id}.${channel}`;
|
|
77
|
+
const CADENCE_KEY = "digest_cadence";
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* What the person hears about, and how (docs/notifications-harmonization.md §2.1–§2.3,
|
|
81
|
+
* §4.2): one row per type the SERVER answered, the app's words on it, a switch for "in
|
|
82
|
+
* the app" and "By e-mail" under it where the type offers mail. Where the app has no
|
|
83
|
+
* "in the app" channel (Kurvenschmiede), the e-mail switch is the row's own, with the
|
|
84
|
+
* type's label.
|
|
85
|
+
*
|
|
86
|
+
* **The server's list is the only list.** The card keeps no defaults and no list of
|
|
87
|
+
* types: it draws what `value` holds, in the order of `groups`, else of `types`. A type
|
|
88
|
+
* the app names that the server did not answer is not drawn (kastlan's tenant receives
|
|
89
|
+
* neither of its types). In development a type the server answered with no entry in
|
|
90
|
+
* `types`, or in no group when `groups` is given, throws — keksdose's compile-time
|
|
91
|
+
* `_EVERY_TYPE_IS_GROUPED`, now at run time, since the list is the server's.
|
|
92
|
+
*
|
|
93
|
+
* **Each flip saves at once**, one switch per call; the switch shows its new state while
|
|
94
|
+
* the call runs and goes back if it rejects, with the failure said under the card. The
|
|
95
|
+
* digest's cadence and the app's extra field (`renderExtra`) show under their type while
|
|
96
|
+
* it is on.
|
|
97
|
+
*
|
|
98
|
+
* Under a write lock the switches are `commit` controls exempt from billing: a lapsed
|
|
99
|
+
* plan never keeps a person from turning notifications off (billing §12.13).
|
|
100
|
+
*/
|
|
101
|
+
export function NotificationTypesSetting<Id extends string = string>({
|
|
102
|
+
types,
|
|
103
|
+
value,
|
|
104
|
+
loading,
|
|
105
|
+
onChange,
|
|
106
|
+
groups,
|
|
107
|
+
digest,
|
|
108
|
+
renderExtra,
|
|
109
|
+
emailUnverified = false,
|
|
110
|
+
disabled = false,
|
|
111
|
+
describeError,
|
|
112
|
+
labels: labelsProp,
|
|
113
|
+
className,
|
|
114
|
+
...rest
|
|
115
|
+
}: NotificationTypesSettingProps<Id>) {
|
|
116
|
+
const labels = useNotificationsLabels(labelsProp);
|
|
117
|
+
const overlay = useWriteOverlay<boolean>(value);
|
|
118
|
+
const cadenceOverlay = useWriteOverlay<DigestCadence>(digest?.cadence);
|
|
119
|
+
const [failure, setFailure] = useState<ReactNode>(null);
|
|
120
|
+
const mounted = useMounted();
|
|
121
|
+
const groupId = useId();
|
|
122
|
+
|
|
123
|
+
const answered = value ? Object.keys(value) : [];
|
|
124
|
+
const entries = new Map(types.map((entry) => [entry.id as string, entry]));
|
|
125
|
+
if (value && devChecks()) {
|
|
126
|
+
const unnamed = answered.filter((id) => !entries.has(id));
|
|
127
|
+
if (unnamed.length) {
|
|
128
|
+
throw new Error(
|
|
129
|
+
`NotificationTypesSetting: the server answered ${unnamed.map((id) => `"${id}"`).join(", ")} with no entry in \`types\` — give every type the server can send its words.`,
|
|
130
|
+
);
|
|
131
|
+
}
|
|
132
|
+
if (groups) {
|
|
133
|
+
const grouped = new Set<string>(groups.flatMap((group) => group.types));
|
|
134
|
+
const loose = answered.filter((id) => !grouped.has(id));
|
|
135
|
+
if (loose.length) {
|
|
136
|
+
throw new Error(
|
|
137
|
+
`NotificationTypesSetting: ${loose.map((id) => `"${id}"`).join(", ")} is in no group — a type in no group is drawn nowhere, and could not be turned off.`,
|
|
138
|
+
);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
const rowOf = (id: Id): Row<Id> | null => {
|
|
144
|
+
const switches = value?.[id];
|
|
145
|
+
const entry = entries.get(id);
|
|
146
|
+
if (!switches || !entry || (switches.app === null && switches.email === null)) return null;
|
|
147
|
+
return { entry, switches };
|
|
148
|
+
};
|
|
149
|
+
const rowsOf = (ids: readonly Id[]) => ids.map(rowOf).filter((row): row is Row<Id> => row !== null);
|
|
150
|
+
|
|
151
|
+
const shown = (id: string, channel: "app" | "email", server: boolean): boolean => {
|
|
152
|
+
const key = switchKey(id, channel);
|
|
153
|
+
return overlay.get(key) ?? server;
|
|
154
|
+
};
|
|
155
|
+
/** The row's own switch: `app`, or `email` where the app has no `app` channel. */
|
|
156
|
+
const rowOn = ({ entry, switches }: Row<Id>) =>
|
|
157
|
+
switches.app !== null
|
|
158
|
+
? shown(entry.id, "app", switches.app)
|
|
159
|
+
: shown(entry.id, "email", switches.email === true);
|
|
160
|
+
|
|
161
|
+
const save = <V,>(key: string, patch: NotificationSettingsPatch<Id>, which: WriteOverlay<V>, next: V) => {
|
|
162
|
+
if (which.pending(key)) return;
|
|
163
|
+
setFailure(null);
|
|
164
|
+
which.set(key, next);
|
|
165
|
+
settle(() => onChange(patch)).then(
|
|
166
|
+
() => {
|
|
167
|
+
if (mounted.current) which.settle(key, true);
|
|
168
|
+
},
|
|
169
|
+
(error: unknown) => {
|
|
170
|
+
if (!mounted.current) return;
|
|
171
|
+
which.settle(key, false);
|
|
172
|
+
setFailure(describeFailure(describeError?.(error), labels.failed));
|
|
173
|
+
},
|
|
174
|
+
);
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
const flip = (id: Id, channel: "app" | "email", on: boolean) =>
|
|
178
|
+
save(
|
|
179
|
+
switchKey(id, channel),
|
|
180
|
+
{ types: { [id]: { [channel]: on } } as NotificationSettingsPatch<Id>["types"] },
|
|
181
|
+
overlay,
|
|
182
|
+
on,
|
|
183
|
+
);
|
|
184
|
+
|
|
185
|
+
const cadence = cadenceOverlay.get(CADENCE_KEY) ?? digest?.cadence;
|
|
186
|
+
|
|
187
|
+
const unverifiedLine = emailUnverified ? (
|
|
188
|
+
<span className="block" data-email-unverified="">
|
|
189
|
+
{labels.emailUnverified}
|
|
190
|
+
</span>
|
|
191
|
+
) : null;
|
|
192
|
+
|
|
193
|
+
const renderRow = (row: Row<Id>) => {
|
|
194
|
+
const { entry, switches } = row;
|
|
195
|
+
const on = rowOn(row);
|
|
196
|
+
const emailOnly = switches.app === null;
|
|
197
|
+
const both = !emailOnly && switches.email !== null;
|
|
198
|
+
const cadenceSelect =
|
|
199
|
+
on && digest?.type === entry.id && cadence ? (
|
|
200
|
+
<Select
|
|
201
|
+
label={labels.digestCadence}
|
|
202
|
+
value={cadence}
|
|
203
|
+
disabled={disabled}
|
|
204
|
+
commit={COMMIT_EXCEPT_BILLING}
|
|
205
|
+
onChange={(event) => {
|
|
206
|
+
const next = event.target.value as DigestCadence;
|
|
207
|
+
if (next !== cadence) save(CADENCE_KEY, { digest_cadence: next }, cadenceOverlay, next);
|
|
208
|
+
}}
|
|
209
|
+
className="max-w-44"
|
|
210
|
+
>
|
|
211
|
+
<option value="weekly">{labels.digestWeekly}</option>
|
|
212
|
+
<option value="monthly">{labels.digestMonthly}</option>
|
|
213
|
+
</Select>
|
|
214
|
+
) : null;
|
|
215
|
+
const extra = on ? renderExtra?.(entry.id) : null;
|
|
216
|
+
const description =
|
|
217
|
+
emailOnly && unverifiedLine ? (
|
|
218
|
+
<>
|
|
219
|
+
{entry.description !== undefined && <span className="block">{entry.description}</span>}
|
|
220
|
+
{unverifiedLine}
|
|
221
|
+
</>
|
|
222
|
+
) : (
|
|
223
|
+
entry.description
|
|
224
|
+
);
|
|
225
|
+
return (
|
|
226
|
+
<div
|
|
227
|
+
key={entry.id}
|
|
228
|
+
data-notification-type={entry.id}
|
|
229
|
+
// A row with two switches is a group named by its type, so "By e-mail" is heard
|
|
230
|
+
// with the type it belongs to.
|
|
231
|
+
role={both ? "group" : undefined}
|
|
232
|
+
aria-label={both ? entry.label : undefined}
|
|
233
|
+
className="space-y-2"
|
|
234
|
+
>
|
|
235
|
+
<Switch
|
|
236
|
+
label={entry.label}
|
|
237
|
+
description={description}
|
|
238
|
+
checked={on}
|
|
239
|
+
disabled={disabled}
|
|
240
|
+
commit={COMMIT_EXCEPT_BILLING}
|
|
241
|
+
onCheckedChange={(next) => flip(entry.id, emailOnly ? "email" : "app", next)}
|
|
242
|
+
/>
|
|
243
|
+
{both && (
|
|
244
|
+
<div className="ps-4">
|
|
245
|
+
<Switch
|
|
246
|
+
size="sm"
|
|
247
|
+
label={labels.byEmail}
|
|
248
|
+
description={unverifiedLine ?? undefined}
|
|
249
|
+
checked={shown(entry.id, "email", switches.email === true)}
|
|
250
|
+
disabled={disabled}
|
|
251
|
+
commit={COMMIT_EXCEPT_BILLING}
|
|
252
|
+
onCheckedChange={(next) => flip(entry.id, "email", next)}
|
|
253
|
+
/>
|
|
254
|
+
</div>
|
|
255
|
+
)}
|
|
256
|
+
{(cadenceSelect || hasContent(extra)) && (
|
|
257
|
+
<div className="ps-4 space-y-2">
|
|
258
|
+
{cadenceSelect}
|
|
259
|
+
{extra}
|
|
260
|
+
</div>
|
|
261
|
+
)}
|
|
262
|
+
</div>
|
|
263
|
+
);
|
|
264
|
+
};
|
|
265
|
+
|
|
266
|
+
let body: ReactNode;
|
|
267
|
+
if (loading || value === undefined) {
|
|
268
|
+
body = <Skeleton lines={3} label={labels.typesLoading} />;
|
|
269
|
+
} else if (groups) {
|
|
270
|
+
const drawn = groups
|
|
271
|
+
.map((group) => ({ group, rows: rowsOf(group.types) }))
|
|
272
|
+
.filter(({ rows }) => rows.length > 0);
|
|
273
|
+
body =
|
|
274
|
+
drawn.length === 0 ? (
|
|
275
|
+
<p className={CARD_DESCRIPTION_CLASS}>{labels.typesEmpty}</p>
|
|
276
|
+
) : (
|
|
277
|
+
drawn.map(({ group, rows }) => {
|
|
278
|
+
const headingId = `${groupId}-${group.id}`;
|
|
279
|
+
return (
|
|
280
|
+
<div key={group.id} role="group" aria-labelledby={headingId} className="space-y-3">
|
|
281
|
+
<SectionLabel as="div" size="xs" id={headingId}>
|
|
282
|
+
{group.label}
|
|
283
|
+
</SectionLabel>
|
|
284
|
+
{rows.map(renderRow)}
|
|
285
|
+
</div>
|
|
286
|
+
);
|
|
287
|
+
})
|
|
288
|
+
);
|
|
289
|
+
} else {
|
|
290
|
+
const rows = rowsOf(types.map((entry) => entry.id));
|
|
291
|
+
body =
|
|
292
|
+
rows.length === 0 ? (
|
|
293
|
+
<p className={CARD_DESCRIPTION_CLASS}>{labels.typesEmpty}</p>
|
|
294
|
+
) : (
|
|
295
|
+
<div className="space-y-3">{rows.map(renderRow)}</div>
|
|
296
|
+
);
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
return (
|
|
300
|
+
<Card {...rest} className={cn("p-4 space-y-3", className)}>
|
|
301
|
+
<div>
|
|
302
|
+
<SettingsCardTitle>{labels.typesTitle}</SettingsCardTitle>
|
|
303
|
+
<div className={CARD_DESCRIPTION_CLASS}>{labels.typesDescription}</div>
|
|
304
|
+
</div>
|
|
305
|
+
{body}
|
|
306
|
+
<FailureLine>{failure}</FailureLine>
|
|
307
|
+
</Card>
|
|
308
|
+
);
|
|
309
|
+
}
|