Skip to content

Commit e38ea34

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 85c8e20 commit e38ea34

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
@@ -288,10 +288,24 @@ export class MobileVault {
288288
// layout — trust it even when other loose folders exist at the root (a
289289
// daily/weekly-notes dir created during a transient mis-inference must
290290
// never flip a vault into root mode permanently).
291+
//
292+
// An empty one says nothing, though: this app makes it on first open, so a
293+
// folder opened before its notes arrived (Syncthing still copying, a vault
294+
// moved over in parts) read as inbox mode for good and showed none of them
295+
// (#1023). With nothing inside, reading the root instead cannot hide a note.
291296
const inboxDir = resolveFolderPath('inbox', systemFolderPaths).toLowerCase()
292-
if (entries.some((e) => e.type === 'directory' && e.name.toLowerCase() === inboxDir)) {
297+
const inbox = entries.find((e) => e.type === 'directory' && e.name.toLowerCase() === inboxDir)
298+
if (inbox && (await this.fs.readdir(inbox.name)).some((e) => !e.name.startsWith('.'))) {
293299
return 'inbox'
294300
}
301+
return this.rootHoldsLooseContent(entries, systemFolderPaths) ? 'root' : 'inbox'
302+
}
303+
304+
/** Markdown or a folder at the root that only root mode would show. */
305+
private rootHoldsLooseContent(
306+
entries: FileInfo[],
307+
systemFolderPaths?: SystemFolderPaths | null
308+
): boolean {
295309
// Remapped system folders are system directories, not loose user content:
296310
// without this, a vault whose inbox is `01 - Entry` reads as a flat
297311
// root-mode vault.
@@ -301,14 +315,13 @@ export class MobileVault {
301315
if (value) customDirs.add(value.toLowerCase())
302316
}
303317
}
304-
for (const e of entries) {
305-
if (e.name.startsWith('.')) continue
306-
if (RESERVED_ROOT_NAMES.has(e.name)) continue
307-
if (customDirs.has(e.name.toLowerCase())) continue
308-
if (e.type === 'directory') return 'root'
309-
if (isMarkdownPath(e.name)) return 'root'
310-
}
311-
return 'inbox'
318+
return entries.some(
319+
(e) =>
320+
!e.name.startsWith('.') &&
321+
!RESERVED_ROOT_NAMES.has(e.name) &&
322+
!customDirs.has(e.name.toLowerCase()) &&
323+
(e.type === 'directory' || isMarkdownPath(e.name))
324+
)
312325
}
313326

314327
async getVaultSettings(): Promise<VaultSettings> {
@@ -413,7 +426,9 @@ export class MobileVault {
413426
async rootContentHiddenByInboxMode(): Promise<boolean> {
414427
const settings = await this.getVaultSettings()
415428
if (settings.primaryNotesLocation !== 'inbox') return false
416-
return (await this.inferPrimaryNotesLocation(settings.systemFolderPaths)) === 'root'
429+
// Not the inference: it trusts an inbox with notes in it, and this banner
430+
// is the only thing that says notes beside that inbox are out of view.
431+
return this.rootHoldsLooseContent(await this.fs.readdir(''), settings.systemFolderPaths)
417432
}
418433

419434
/** 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'
@@ -882,6 +883,54 @@ function useLongPress(): (fn: () => void) => {
882883
})
883884
}
884885

886+
/** Notes beside the inbox are out of view in inbox mode: say so, and offer the
887+
* way to show them. It asks the vault each time the drawer opens. */
888+
function HiddenRootNotesNotice({ vaultRoot }: { vaultRoot: string | null }): React.JSX.Element | null {
889+
const [hidden, setHidden] = useState(false)
890+
useEffect(() => {
891+
let live = true
892+
if (!vaultRoot || rootNoticeDismissed(vaultRoot)) {
893+
setHidden(false)
894+
return
895+
}
896+
void window.zen
897+
.rootContentHiddenByInboxMode()
898+
.then((answer) => {
899+
if (live) setHidden(answer)
900+
})
901+
.catch(() => {})
902+
return () => {
903+
live = false
904+
}
905+
}, [vaultRoot])
906+
if (!hidden || !vaultRoot) return null
907+
return (
908+
<div className="zn-mobile-drawer-notice" role="status">
909+
<p>Some notes aren’t shown. Notes and folders at this vault’s top level are hidden.</p>
910+
<div className="zn-mobile-drawer-notice-actions">
911+
<button
912+
type="button"
913+
onClick={() => {
914+
setHidden(false)
915+
void showRootNotes(window.zen).catch(() => setHidden(true))
916+
}}
917+
>
918+
Show them
919+
</button>
920+
<button
921+
type="button"
922+
onClick={() => {
923+
setHidden(false)
924+
dismissRootNotice(vaultRoot)
925+
}}
926+
>
927+
Dismiss
928+
</button>
929+
</div>
930+
</div>
931+
)
932+
}
933+
885934
function MobileDrawerBody(props: {
886935
vaultName: string
887936
vaultRoot: string | null
@@ -1089,6 +1138,8 @@ function MobileDrawerBody(props: {
10891138
Search notes
10901139
</button>
10911140

1141+
<HiddenRootNotesNotice vaultRoot={props.vaultRoot} />
1142+
10921143
<div className="zn-mobile-drawer-scroll" ref={scrollRef}>
10931144
{(pull > 0 || refreshing) && (
10941145
<div
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
@@ -1007,6 +1007,33 @@
10071007
font-weight: 500;
10081008
}
10091009

1010+
.zn-phone .zn-mobile-drawer-notice {
1011+
margin: 0.5rem 0.75rem;
1012+
padding: 0.625rem 0.75rem;
1013+
border-radius: 0.625rem;
1014+
background: rgb(var(--z-accent) / 0.1);
1015+
font-size: 0.875rem;
1016+
line-height: 1.35;
1017+
color: rgb(var(--z-fg-1));
1018+
}
1019+
1020+
.zn-phone .zn-mobile-drawer-notice-actions {
1021+
display: flex;
1022+
gap: 1rem;
1023+
margin-top: 0.375rem;
1024+
}
1025+
1026+
.zn-phone .zn-mobile-drawer-notice-actions button {
1027+
min-height: 2.75rem;
1028+
font-weight: 600;
1029+
color: rgb(var(--z-accent));
1030+
}
1031+
1032+
.zn-phone .zn-mobile-drawer-notice-actions button + button {
1033+
font-weight: 400;
1034+
color: rgb(var(--z-grey-1));
1035+
}
1036+
10101037
.zn-phone .zn-mobile-drawer-empty {
10111038
padding: 1rem 0.75rem;
10121039
font-size: 0.9375rem;

0 commit comments

Comments
 (0)