Skip to content

Commit d321f29

Browse files
committed
feat(home): Home names the open vault, one tap from the switcher
Someone who keeps a work vault and a personal vault could not tell which one was open without opening the drawer, and the way to switch was hard to find (zennotesandroid#143). Home's header now shows the vault's name in a chip that opens the Vaults sheet. The drawer's header still does both, and a tablet keeps the sidebar's vault menu, so the chip is phone only. A long name truncates at 45% of the header, so the greeting stays on one line. The per-vault colors and icons the issue also suggests are not part of this. Also hides core's new way back to a hidden sidebar, data-sidebar-restore, since a phone layout has no sidebar to go back to.
1 parent 68e50e2 commit d321f29

3 files changed

Lines changed: 123 additions & 1 deletion

File tree

‎src/ui-mobile/MobileShell.tsx‎

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { Keyboard } from '@capacitor/keyboard'
1414
import { Capacitor } from '@capacitor/core'
1515
import { getShellSnapshot, useShellSnapshot, subscribeShell, getAdjacentNotePath,
1616
getTagPresenceSnapshot, subscribeTagPresence } from '@zennotes/app-core/shell'
17-
import { getBrowseSnapshot, requestCreateBrowseFolder, requestRenameBrowseDatabase,
17+
import { getBrowseSnapshot, useBrowseSnapshot, requestCreateBrowseFolder, requestRenameBrowseDatabase,
1818
requestMoveBrowseDirectory, requestDeleteBrowseDirectory, type BrowseActionHost } from '@zennotes/app-core/browse'
1919
import { getWorkspaceSnapshot, useWorkspaceSnapshot, subscribeWorkspace, readPersistedHomeState,
2020
configureWorkspacePresentation, pickLocalVault, openLocalVault, connectRemoteProfile, refreshRemoteProfiles } from '@zennotes/app-core/workspace'
@@ -2757,6 +2757,51 @@ function SettingsVaultQuickSwitch(): React.JSX.Element {
27572757
)
27582758
}
27592759

2760+
// ---------------------------------------------------------------------------
2761+
// Home names the open vault, one tap from the switcher (zennotesandroid#143).
2762+
// The drawer's header does both, but only once the drawer is open, so someone
2763+
// who keeps a work and a personal vault could not tell which one they were in.
2764+
// A tablet keeps the sidebar's vault menu, so this is phone only.
2765+
// ---------------------------------------------------------------------------
2766+
function HomeVaultChip(): React.JSX.Element {
2767+
const name = useBrowseSnapshot().vault?.name ?? 'ZenNotes'
2768+
return (
2769+
<button
2770+
type="button"
2771+
className="zn-home-vault-chip"
2772+
aria-label={`Current vault: ${name}. Switch vault`}
2773+
onClick={() => openMobileSheet('vaults')}
2774+
>
2775+
<span>{name}</span>
2776+
<svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true">
2777+
<path d="m6 9 6 6 6-6" />
2778+
</svg>
2779+
</button>
2780+
)
2781+
}
2782+
2783+
function useHomeVaultChip(): void {
2784+
useEffect(() => {
2785+
if (!isPhoneWidth()) return
2786+
const container = document.createElement('div')
2787+
container.className = 'zn-home-vault-host'
2788+
const root = ReactDOM.createRoot(container)
2789+
root.render(<HomeVaultChip />)
2790+
const sync = (): void => {
2791+
const header = document.querySelector('[data-home-nav] header')
2792+
if (header && container.parentElement !== header) header.appendChild(container)
2793+
}
2794+
const observer = new MutationObserver(sync)
2795+
observer.observe(document.body, { childList: true, subtree: true })
2796+
sync()
2797+
return () => {
2798+
observer.disconnect()
2799+
root.unmount()
2800+
container.remove()
2801+
}
2802+
}, [])
2803+
}
2804+
27602805
function useVaultSettingsRows(): void {
27612806
useEffect(() => {
27622807
const access = vaultSettingsAccessForLayout(isPhoneWidth())
@@ -3324,6 +3369,7 @@ function MobileShellRoot(): React.JSX.Element {
33243369
useKanbanCardDrag()
33253370
useYouTubeLiteEmbeds()
33263371
useVaultSettingsRows()
3372+
useHomeVaultChip()
33273373
useLayoutSettingsRow()
33283374
useCloudSettingsRow()
33293375
useAboutGitHubLinks()
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import assert from 'node:assert/strict'
2+
import { readFileSync } from 'node:fs'
3+
import { describe, it } from 'node:test'
4+
5+
const shell = readFileSync(new URL('./MobileShell.tsx', import.meta.url), 'utf8')
6+
const css = readFileSync(new URL('./mobile.css', import.meta.url), 'utf8')
7+
8+
describe('Home names the open vault', () => {
9+
it('mounts in the Home header, on a phone only', () => {
10+
const hook = shell.slice(shell.indexOf('function useHomeVaultChip'), shell.indexOf('function useVaultSettingsRows'))
11+
assert.match(hook, /if \(!isPhoneWidth\(\)\) return/)
12+
assert.match(hook, /\[data-home-nav\] header/)
13+
assert.match(shell, /\n useHomeVaultChip\(\)\n/)
14+
})
15+
16+
it('shows the vault, and opens the switcher', () => {
17+
const chip = shell.slice(shell.indexOf('function HomeVaultChip'), shell.indexOf('function useHomeVaultChip'))
18+
assert.match(chip, /useBrowseSnapshot\(\)\.vault\?\.name/)
19+
assert.match(chip, /openMobileSheet\('vaults'\)/)
20+
})
21+
22+
it('keeps a long name from pushing the greeting off screen', () => {
23+
assert.match(css, /\.zn-home-vault-host \{[^}]*max-width: 45%/)
24+
assert.match(css, /\.zn-home-vault-chip \{[^}]*min-height: 44px/)
25+
assert.match(css, /\.zn-home-vault-chip span \{[^}]*white-space: nowrap/)
26+
})
27+
})
28+
29+
describe('the way back to a hidden sidebar', () => {
30+
it('stays off a phone, which has no sidebar', () => {
31+
assert.match(css, /\.zn-mobile\.zn-phone \[data-sidebar-restore\] \{\s*display: none;/)
32+
})
33+
})

‎src/ui-mobile/mobile.css‎

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1875,6 +1875,49 @@
18751875

18761876
/* ---- Home: keep it minimal ------------------------------------------------ */
18771877

1878+
/* The open vault, one tap from the switcher (zennotesandroid#143). */
1879+
.zn-mobile.zn-phone [data-home-nav] header {
1880+
align-items: center;
1881+
}
1882+
1883+
.zn-mobile.zn-phone .zn-home-vault-host {
1884+
flex: 0 1 auto;
1885+
min-width: 0;
1886+
max-width: 45%;
1887+
}
1888+
1889+
.zn-mobile.zn-phone .zn-home-vault-chip {
1890+
display: flex;
1891+
align-items: center;
1892+
gap: 0.25rem;
1893+
max-width: 100%;
1894+
min-height: 44px;
1895+
padding: 0 0.75rem;
1896+
border: 1px solid rgb(var(--z-fg) / 0.14);
1897+
border-radius: 9999px;
1898+
background: rgb(var(--z-fg) / 0.05);
1899+
color: rgb(var(--z-fg) / 0.85);
1900+
font-size: 0.8125rem;
1901+
font-weight: 500;
1902+
}
1903+
1904+
.zn-mobile.zn-phone .zn-home-vault-chip span {
1905+
min-width: 0;
1906+
overflow: hidden;
1907+
text-overflow: ellipsis;
1908+
white-space: nowrap;
1909+
}
1910+
1911+
.zn-mobile.zn-phone .zn-home-vault-chip svg {
1912+
flex-shrink: 0;
1913+
color: rgb(var(--z-fg) / 0.45);
1914+
}
1915+
1916+
/* Core's way back to a hidden sidebar: a phone has no sidebar to go back to. */
1917+
.zn-mobile.zn-phone [data-sidebar-restore] {
1918+
display: none;
1919+
}
1920+
18781921
/* The quick-action chip row duplicates the ⊕ create sheet — drop it. */
18791922
.zn-mobile.zn-phone [data-home-nav] div.mb-10.flex-wrap.gap-2 {
18801923
display: none;

0 commit comments

Comments
 (0)