| 771 | } |
| 772 | |
| 773 | function LayoutStep({ |
| 774 | primaryLocation, |
| 775 | dailyEnabled, |
| 776 | dailyDirectory, |
| 777 | setVaultSettings, |
| 778 | hasVault, |
| 779 | onBack, |
| 780 | onNext |
| 781 | }: { |
| 782 | primaryLocation: PrimaryNotesLocation |
| 783 | dailyEnabled: boolean |
| 784 | dailyDirectory: string |
| 785 | setVaultSettings: (next: VaultSettings) => Promise<void> |
| 786 | hasVault: boolean |
| 787 | onBack: () => void |
| 788 | onNext: () => void |
| 789 | }): JSX.Element { |
| 790 | // Local draft so the directory input doesn't normalize on every keystroke. |
| 791 | const [dirDraft, setDirDraft] = useState<string>(dailyDirectory) |
| 792 | |
| 793 | useEffect(() => { |
| 794 | setDirDraft(dailyDirectory) |
| 795 | }, [dailyDirectory]) |
| 796 | |
| 797 | const commit = (patch: { |
| 798 | primaryNotesLocation?: PrimaryNotesLocation |
| 799 | dailyEnabled?: boolean |
| 800 | dailyDirectory?: string |
| 801 | }): void => { |
| 802 | const current = useStore.getState().vaultSettings |
| 803 | void setVaultSettings({ |
| 804 | ...current, |
| 805 | primaryNotesLocation: patch.primaryNotesLocation ?? current.primaryNotesLocation, |
| 806 | dailyNotes: { |
| 807 | ...current.dailyNotes, |
| 808 | enabled: patch.dailyEnabled ?? current.dailyNotes.enabled, |
| 809 | directory: |
| 810 | patch.dailyDirectory !== undefined |
| 811 | ? normalizeDailyNotesDirectory(patch.dailyDirectory) |
| 812 | : current.dailyNotes.directory |
| 813 | } |
| 814 | }) |
| 815 | } |
| 816 | |
| 817 | if (!hasVault) { |
| 818 | return ( |
| 819 | <div> |
| 820 | <StepHeading |
| 821 | eyebrow="Step 4" |
| 822 | title="Vault layout" |
| 823 | subtitle="Pick a vault first — these settings live inside the vault." |
| 824 | /> |
| 825 | <StepFooter primaryLabel="Back to vault" onPrimary={onBack} hideBack /> |
| 826 | </div> |
| 827 | ) |
| 828 | } |
| 829 | |
| 830 | return ( |