Skip to content

Commit 21a4d1c

Browse files
committed
fix(vault): a folder opened before its notes arrived shows them (#1023)
Opening an empty folder made `inbox/`, and an inbox directory settled the layout as inbox mode for good. Notes that arrived afterward (Syncthing still copying, a vault moved over in parts) sat at the root, out of view, with 0 of 83 listed even after a restart. An empty inbox says nothing now, so reading the root cannot hide a note. An inbox with anything in it stays inbox mode, as before. That leaves a note made before the sync arrived, which keeps inbox mode and hides what lands beside it. The drawer now says so and offers Show them, as the desktop sidebar does. The check for it no longer trusts the inbox, or it could never fire. Until this shell adopts a core with the refreshNotes fix, the notes show on the next resume rather than at once.
1 parent 0e9ed5b commit 21a4d1c

6 files changed

Lines changed: 249 additions & 10 deletions

File tree

‎src/bridge/vault-fs.ts‎

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -291,10 +291,24 @@ export class MobileVault {
291291
// layout — trust it even when other loose folders exist at the root (a
292292
// daily/weekly-notes dir created during a transient mis-inference must
293293
// never flip a vault into root mode permanently).
294+
//
295+
// An empty one says nothing, though: this app makes it on first open, so a
296+
// folder opened before its notes arrived (Syncthing still copying, a vault
297+
// moved over in parts) read as inbox mode for good and showed none of them
298+
// (#1023). With nothing inside, reading the root instead cannot hide a note.
294299
const inboxDir = resolveFolderPath('inbox', systemFolderPaths).toLowerCase()
295-
if (entries.some((e) => e.type === 'directory' && e.name.toLowerCase() === inboxDir)) {
300+
const inbox = entries.find((e) => e.type === 'directory' && e.name.toLowerCase() === inboxDir)
301+
if (inbox && (await this.fs.readdir(inbox.name)).some((e) => !e.name.startsWith('.'))) {
296302
return 'inbox'
297303
}
304+
return this.rootHoldsLooseContent(entries, systemFolderPaths) ? 'root' : 'inbox'
305+
}
306+
307+
/** Markdown or a folder at the root that only root mode would show. */
308+
private rootHoldsLooseContent(
309+
entries: FileInfo[],
310+
systemFolderPaths?: SystemFolderPaths | null
311+
): boolean {
298312
// Remapped system folders are system directories, not loose user content:
299313
// without this, a vault whose inbox is `01 - Entry` reads as a flat
300314
// root-mode vault.
@@ -304,14 +318,13 @@ export class MobileVault {
304318
if (value) customDirs.add(value.toLowerCase())
305319
}
306320
}
307-
for (const e of entries) {
308-
if (e.name.startsWith('.')) continue
309-
if (RESERVED_ROOT_NAMES.has(e.name)) continue
310-
if (customDirs.has(e.name.toLowerCase())) continue
311-
if (e.type === 'directory') return 'root'
312-
if (isMarkdownPath(e.name)) return 'root'
313-
}
314-
return 'inbox'
321+
return entries.some(
322+
(e) =>
323+
!e.name.startsWith('.') &&
324+
!RESERVED_ROOT_NAMES.has(e.name) &&
325+
!customDirs.has(e.name.toLowerCase()) &&
326+
(e.type === 'directory' || isMarkdownPath(e.name))
327+
)
315328
}
316329

317330
async getVaultSettings(): Promise<VaultSettings> {
@@ -417,7 +430,9 @@ export class MobileVault {
417430
async rootContentHiddenByInboxMode(): Promise<boolean> {
418431
const settings = await this.getVaultSettings()
419432
if (settings.primaryNotesLocation !== 'inbox') return false
420-
return (await this.inferPrimaryNotesLocation(settings.systemFolderPaths)) === 'root'
433+
// Not the inference: it trusts an inbox with notes in it, and this banner
434+
// is the only thing that says notes beside that inbox are out of view.
435+
return this.rootHoldsLooseContent(await this.fs.readdir(''), settings.systemFolderPaths)
421436
}
422437

423438
/** The folder a vault-relative path belongs to, remap-aware. Settings are
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
import assert from 'node:assert/strict'
2+
import { test } from 'node:test'
3+
import { loadMobileModule } from '../../tooling/load-mobile-module.ts'
4+
5+
Object.defineProperty(globalThis, 'localStorage', { configurable: true, value: { getItem: () => null, setItem: () => {}, removeItem: () => {} } })
6+
const { MobileVault } = await loadMobileModule(['./src/bridge/vault-fs'])
7+
8+
// A folder opened before its notes arrived (#1023): this app makes `inbox/` on
9+
// first open, and nothing may keep the notes that land beside it out of view.
10+
function fixture(files: string[], dirs: string[] = []) {
11+
const vault = new MobileVault('Fixture')
12+
const children = (dir: string) => {
13+
const prefix = dir ? `${dir}/` : ''
14+
const names = new Map<string, 'file' | 'directory'>()
15+
for (const file of files) {
16+
if (!file.startsWith(prefix)) continue
17+
const [head, ...rest] = file.slice(prefix.length).split('/')
18+
names.set(head!, rest.length ? 'directory' : 'file')
19+
}
20+
for (const entry of dirs) {
21+
if (!entry.startsWith(prefix)) continue
22+
const [head, ...rest] = entry.slice(prefix.length).split('/')
23+
if (head && !rest.length) names.set(head, 'directory')
24+
}
25+
return [...names].map(([name, type]) => ({ name, type }))
26+
}
27+
Object.assign(vault, {
28+
fs: { readdir: async (dir: string) => children(dir), readTextOrNull: async () => null, rootPath: '/fixture' }
29+
})
30+
return vault
31+
}
32+
const layout = async (vault: InstanceType<typeof MobileVault>) => (await vault.getVaultSettings()).primaryNotesLocation
33+
34+
test('an empty inbox does not hold back folders that arrived beside it', async () => {
35+
assert.equal(await layout(fixture(['Trips/Rome.md', 'Work/Plan.md'], ['inbox', 'quick', 'archive', 'trash'])), 'root')
36+
})
37+
38+
test('an empty inbox does not hold back a loose note at the root', async () => {
39+
assert.equal(await layout(fixture(['Loose.md'], ['inbox'])), 'root')
40+
})
41+
42+
test('dotfiles inside the inbox are not notes', async () => {
43+
assert.equal(await layout(fixture(['inbox/.DS_Store', 'Trips/Rome.md'], ['inbox'])), 'root')
44+
})
45+
46+
test('an inbox with anything in it stays inbox mode, loose folders or not', async () => {
47+
assert.equal(await layout(fixture(['inbox/Welcome.md', 'Daily/2026-11-04.md'])), 'inbox')
48+
})
49+
50+
test('an empty vault and a media-only vault stay inbox mode', async () => {
51+
assert.equal(await layout(fixture([], ['inbox'])), 'inbox')
52+
assert.equal(await layout(fixture(['VID_1.mp4'], ['inbox'])), 'inbox')
53+
})
54+
55+
test('the banner sees notes an inbox-mode vault.json hides when the inbox is empty', async () => {
56+
const vault = fixture(['Trips/Rome.md'], ['inbox'])
57+
Object.assign(vault, { settingsCache: { ...(await vault.getVaultSettings()), primaryNotesLocation: 'inbox' } })
58+
assert.equal(await vault.rootContentHiddenByInboxMode(), true)
59+
})
60+
61+
test('the banner speaks up when an inbox with a note hides folders beside it', async () => {
62+
const vault = fixture(['inbox/First.md', 'Trips/Rome.md'])
63+
assert.equal(await layout(vault), 'inbox')
64+
assert.equal(await vault.rootContentHiddenByInboxMode(), true)
65+
})
66+
67+
test('the banner stays quiet with nothing loose at the root', async () => {
68+
const vault = fixture(['inbox/First.md', 'VID_1.mp4'], ['quick', 'archive', 'trash'])
69+
assert.equal(await vault.rootContentHiddenByInboxMode(), false)
70+
})
71+
72+
test('a resume that settles the layout re-reads it', async () => {
73+
const files: string[] = []
74+
const vault = fixture(files, ['inbox'])
75+
assert.equal(await layout(vault), 'inbox')
76+
files.push('Trips/Rome.md')
77+
Object.assign(vault, { listNotes: async () => [] })
78+
await vault.rescan()
79+
assert.equal(await layout(vault), 'root')
80+
})

‎src/ui-mobile/MobileDrawer.tsx‎

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { useWorkspaceSnapshot, openLocalVault, pickLocalVault, refreshRemoteProf
1717
import { openNote, openAppPage } from '@zennotes/app-core/navigation'
1818
import { showSearch } from '@zennotes/app-core/commands'
1919
import { setSettingsVisible } from '@zennotes/app-core/settings'
20+
import { dismissRootNotice, rootNoticeDismissed, showRootNotes } from './drawer-root-notice'
2021
import { confirm as confirmApp, prompt as promptApp } from '@zennotes/app-core/dialogs'
2122
import { captureMobileWorkspace, reportActionError } from './workspace-context'
2223
import { Keyboard } from '@capacitor/keyboard'
@@ -1067,6 +1068,54 @@ function DrawerRefresh({
10671068
)
10681069
}
10691070

1071+
/** Notes beside the inbox are out of view in inbox mode: say so, and offer the
1072+
* way to show them. It asks the vault each time the drawer opens. */
1073+
function HiddenRootNotesNotice({ vaultRoot }: { vaultRoot: string | null }): React.JSX.Element | null {
1074+
const [hidden, setHidden] = useState(false)
1075+
useEffect(() => {
1076+
let live = true
1077+
if (!vaultRoot || rootNoticeDismissed(vaultRoot)) {
1078+
setHidden(false)
1079+
return
1080+
}
1081+
void window.zen
1082+
.rootContentHiddenByInboxMode()
1083+
.then((answer) => {
1084+
if (live) setHidden(answer)
1085+
})
1086+
.catch(() => {})
1087+
return () => {
1088+
live = false
1089+
}
1090+
}, [vaultRoot])
1091+
if (!hidden || !vaultRoot) return null
1092+
return (
1093+
<div className="zn-mobile-drawer-notice" role="status">
1094+
<p>Some notes aren’t shown. Notes and folders at this vault’s top level are hidden.</p>
1095+
<div className="zn-mobile-drawer-notice-actions">
1096+
<button
1097+
type="button"
1098+
onClick={() => {
1099+
setHidden(false)
1100+
void showRootNotes(window.zen).catch(() => setHidden(true))
1101+
}}
1102+
>
1103+
Show them
1104+
</button>
1105+
<button
1106+
type="button"
1107+
onClick={() => {
1108+
setHidden(false)
1109+
dismissRootNotice(vaultRoot)
1110+
}}
1111+
>
1112+
Dismiss
1113+
</button>
1114+
</div>
1115+
</div>
1116+
)
1117+
}
1118+
10701119
function MobileDrawerBody(props: {
10711120
vaultName: string
10721121
pinKey: string | null
@@ -1209,6 +1258,8 @@ function MobileDrawerBody(props: {
12091258
Search notes
12101259
</button>
12111260

1261+
<HiddenRootNotesNotice vaultRoot={pinKey} />
1262+
12121263
<div className="zn-mobile-drawer-scroll" ref={scrollRef}>
12131264
<DrawerRefresh scrollRef={scrollRef} />
12141265
{path === '' ? (
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import assert from 'node:assert/strict'
2+
import { test } from 'node:test'
3+
import { dismissRootNotice, rootNoticeDismissed, showRootNotes } from './drawer-root-notice.ts'
4+
5+
function memoryStore(): Pick<Storage, 'getItem' | 'setItem'> {
6+
const values = new Map<string, string>()
7+
return { getItem: (key) => values.get(key) ?? null, setItem: (key, value) => void values.set(key, value) }
8+
}
9+
10+
test('dismissing applies to that vault only', () => {
11+
const store = memoryStore()
12+
assert.equal(rootNoticeDismissed('/a', store), false)
13+
dismissRootNotice('/a', store)
14+
assert.equal(rootNoticeDismissed('/a', store), true)
15+
assert.equal(rootNoticeDismissed('/b', store), false)
16+
})
17+
18+
test('storage that refuses never breaks the drawer', () => {
19+
const broken = { getItem: () => { throw new Error('no') }, setItem: () => { throw new Error('no') } }
20+
assert.equal(rootNoticeDismissed('/a', broken), false)
21+
assert.doesNotThrow(() => dismissRootNotice('/a', broken))
22+
})
23+
24+
test('showing root notes changes the layout and keeps the other settings', async () => {
25+
let saved: unknown = null
26+
await showRootNotes({
27+
getVaultSettings: async () => ({ primaryNotesLocation: 'inbox', displayName: 'Mine' }),
28+
setVaultSettings: async (settings) => { saved = settings }
29+
})
30+
assert.deepEqual(saved, { primaryNotesLocation: 'root', displayName: 'Mine' })
31+
})
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/**
2+
* Whether the drawer warns that an inbox-mode vault is hiding notes beside its
3+
* inbox (#1023). The desktop sidebar has this banner; the drawer did not, so a
4+
* vault that filled up after a first note just looked empty, with no word why.
5+
*/
6+
const DISMISSED_PREFIX = 'zn:root-notes-notice-dismissed:'
7+
8+
type KeyValueStore = Pick<Storage, 'getItem' | 'setItem'>
9+
10+
export function rootNoticeDismissed(root: string, store: KeyValueStore = localStorage): boolean {
11+
try {
12+
return store.getItem(DISMISSED_PREFIX + root) === '1'
13+
} catch {
14+
return false
15+
}
16+
}
17+
18+
export function dismissRootNotice(root: string, store: KeyValueStore = localStorage): void {
19+
try {
20+
store.setItem(DISMISSED_PREFIX + root, '1')
21+
} catch {
22+
// The notice comes back next time; nothing is lost.
23+
}
24+
}
25+
26+
type LayoutBridge = {
27+
getVaultSettings: () => Promise<{ primaryNotesLocation?: string }>
28+
setVaultSettings: (settings: never) => Promise<unknown>
29+
}
30+
31+
/** Vault.json keeps the rest of the settings as they are. */
32+
export async function showRootNotes(bridge: LayoutBridge): Promise<void> {
33+
const settings = await bridge.getVaultSettings()
34+
await bridge.setVaultSettings({ ...settings, primaryNotesLocation: 'root' } as never)
35+
}

‎src/ui-mobile/mobile.css‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1017,6 +1017,33 @@
10171017
font-weight: 500;
10181018
}
10191019

1020+
.zn-phone .zn-mobile-drawer-notice {
1021+
margin: 0.5rem 0.75rem;
1022+
padding: 0.625rem 0.75rem;
1023+
border-radius: 0.625rem;
1024+
background: rgb(var(--z-accent) / 0.1);
1025+
font-size: 0.875rem;
1026+
line-height: 1.35;
1027+
color: rgb(var(--z-fg-1));
1028+
}
1029+
1030+
.zn-phone .zn-mobile-drawer-notice-actions {
1031+
display: flex;
1032+
gap: 1rem;
1033+
margin-top: 0.375rem;
1034+
}
1035+
1036+
.zn-phone .zn-mobile-drawer-notice-actions button {
1037+
min-height: 2.75rem;
1038+
font-weight: 600;
1039+
color: rgb(var(--z-accent));
1040+
}
1041+
1042+
.zn-phone .zn-mobile-drawer-notice-actions button + button {
1043+
font-weight: 400;
1044+
color: rgb(var(--z-grey-1));
1045+
}
1046+
10201047
.zn-phone .zn-mobile-drawer-empty {
10211048
padding: 1rem 0.75rem;
10221049
font-size: 0.9375rem;

0 commit comments

Comments
 (0)