2026-02-22 17:46:31 +01:00
|
|
|
import { useCallback, useEffect, useMemo, useState } from 'react'
|
2026-02-14 18:22:42 +01:00
|
|
|
import { Sidebar } from './components/Sidebar'
|
|
|
|
|
import { NoteList } from './components/NoteList'
|
|
|
|
|
import { Editor } from './components/Editor'
|
|
|
|
|
import { ResizeHandle } from './components/ResizeHandle'
|
2026-02-21 09:41:46 +01:00
|
|
|
import { CreateTypeDialog } from './components/CreateTypeDialog'
|
2026-02-14 21:17:38 +01:00
|
|
|
import { QuickOpenPalette } from './components/QuickOpenPalette'
|
2026-02-14 21:19:38 +01:00
|
|
|
import { Toast } from './components/Toast'
|
2026-02-15 13:00:10 +01:00
|
|
|
import { CommitDialog } from './components/CommitDialog'
|
2026-02-17 11:03:23 +01:00
|
|
|
import { StatusBar } from './components/StatusBar'
|
2026-02-22 13:38:18 +01:00
|
|
|
import { SettingsPanel } from './components/SettingsPanel'
|
2026-02-22 17:46:31 +01:00
|
|
|
import { GitHubVaultModal } from './components/GitHubVaultModal'
|
2026-02-17 12:10:21 +01:00
|
|
|
import { useVaultLoader } from './hooks/useVaultLoader'
|
2026-02-22 13:38:18 +01:00
|
|
|
import { useSettings } from './hooks/useSettings'
|
2026-02-21 19:15:39 +01:00
|
|
|
import { useNoteActions, generateUntitledName } from './hooks/useNoteActions'
|
2026-02-20 19:59:05 +01:00
|
|
|
import { useAppKeyboard } from './hooks/useAppKeyboard'
|
2026-02-22 10:48:13 +01:00
|
|
|
import { useEntryActions } from './hooks/useEntryActions'
|
2026-02-21 11:07:47 +01:00
|
|
|
import { isTauri } from './mock-tauri'
|
2026-02-21 10:50:50 +01:00
|
|
|
import { useKeyboardNavigation } from './hooks/useKeyboardNavigation'
|
2026-02-22 12:10:24 +01:00
|
|
|
import { useUpdater } from './hooks/useUpdater'
|
2026-02-22 13:38:18 +01:00
|
|
|
import { setApiKey } from './utils/ai-chat'
|
2026-02-17 12:10:21 +01:00
|
|
|
import type { SidebarSelection, GitCommit } from './types'
|
2026-02-22 17:46:31 +01:00
|
|
|
import type { VaultOption } from './components/StatusBar'
|
2026-02-14 18:20:07 +01:00
|
|
|
import './App.css'
|
|
|
|
|
|
2026-02-15 12:54:11 +01:00
|
|
|
// Type declaration for mock content storage
|
|
|
|
|
declare global {
|
|
|
|
|
interface Window {
|
|
|
|
|
__mockContent?: Record<string, string>
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-14 19:35:10 +01:00
|
|
|
const DEFAULT_SELECTION: SidebarSelection = { kind: 'filter', filter: 'all' }
|
|
|
|
|
|
2026-02-22 17:46:31 +01:00
|
|
|
const DEFAULT_VAULTS: VaultOption[] = isTauri()
|
2026-02-21 11:07:47 +01:00
|
|
|
? [
|
|
|
|
|
{ label: 'Demo v2', path: '/Users/luca/Workspace/laputa-app/demo-vault-v2' },
|
|
|
|
|
{ label: 'Laputa', path: '/Users/luca/Laputa' },
|
|
|
|
|
]
|
|
|
|
|
: [
|
|
|
|
|
{ label: 'Demo v2', path: '/Users/luca/Workspace/laputa-app/demo-vault-v2' },
|
|
|
|
|
]
|
2026-02-17 17:45:31 +01:00
|
|
|
|
2026-02-22 10:48:13 +01:00
|
|
|
function useLayoutPanels() {
|
2026-02-14 18:22:42 +01:00
|
|
|
const [sidebarWidth, setSidebarWidth] = useState(250)
|
|
|
|
|
const [noteListWidth, setNoteListWidth] = useState(300)
|
|
|
|
|
const [inspectorWidth, setInspectorWidth] = useState(280)
|
|
|
|
|
const [inspectorCollapsed, setInspectorCollapsed] = useState(false)
|
2026-02-22 10:48:13 +01:00
|
|
|
const handleSidebarResize = useCallback((delta: number) => setSidebarWidth((w) => Math.max(150, Math.min(400, w + delta))), [])
|
|
|
|
|
const handleNoteListResize = useCallback((delta: number) => setNoteListWidth((w) => Math.max(200, Math.min(500, w + delta))), [])
|
|
|
|
|
const handleInspectorResize = useCallback((delta: number) => setInspectorWidth((w) => Math.max(200, Math.min(500, w - delta))), [])
|
|
|
|
|
return { sidebarWidth, noteListWidth, inspectorWidth, inspectorCollapsed, setInspectorCollapsed, handleSidebarResize, handleNoteListResize, handleInspectorResize }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function App() {
|
|
|
|
|
const [selection, setSelection] = useState<SidebarSelection>(DEFAULT_SELECTION)
|
|
|
|
|
const layout = useLayoutPanels()
|
2026-02-14 20:53:52 +01:00
|
|
|
const [gitHistory, setGitHistory] = useState<GitCommit[]>([])
|
2026-02-21 09:41:46 +01:00
|
|
|
const [showCreateTypeDialog, setShowCreateTypeDialog] = useState(false)
|
2026-02-14 21:17:38 +01:00
|
|
|
const [showQuickOpen, setShowQuickOpen] = useState(false)
|
2026-02-15 13:00:10 +01:00
|
|
|
const [showCommitDialog, setShowCommitDialog] = useState(false)
|
2026-02-14 21:19:38 +01:00
|
|
|
const [toastMessage, setToastMessage] = useState<string | null>(null)
|
2026-02-22 17:46:31 +01:00
|
|
|
const [vaultPath, setVaultPath] = useState(DEFAULT_VAULTS[0].path)
|
2026-02-20 16:06:51 +01:00
|
|
|
const [showAIChat, setShowAIChat] = useState(false)
|
2026-02-22 13:38:18 +01:00
|
|
|
const [showSettings, setShowSettings] = useState(false)
|
2026-02-22 17:46:31 +01:00
|
|
|
const [showGitHubVault, setShowGitHubVault] = useState(false)
|
|
|
|
|
const [extraVaults, setExtraVaults] = useState<VaultOption[]>([])
|
|
|
|
|
|
|
|
|
|
const allVaults = useMemo(() => [...DEFAULT_VAULTS, ...extraVaults], [extraVaults])
|
2026-02-14 21:19:38 +01:00
|
|
|
|
2026-02-17 17:45:31 +01:00
|
|
|
const vault = useVaultLoader(vaultPath)
|
2026-02-22 13:38:18 +01:00
|
|
|
const { settings, saveSettings } = useSettings()
|
|
|
|
|
|
|
|
|
|
// Sync Anthropic key from settings to localStorage for AIChatPanel
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
setApiKey(settings.anthropic_key ?? '')
|
|
|
|
|
}, [settings.anthropic_key])
|
|
|
|
|
|
fix: sync in-memory entries after property/rename changes
Two propagation gaps fixed:
1. Property changes (type, status, color, etc.) now immediately sync to
the entries state via frontmatterToEntryPatch(), so sidebar, note list,
and relations panel reflect updates without restart.
2. After renaming a note, all other open tabs reload their content from
disk, picking up updated wikilinks immediately.
Design decisions:
- Used key-mapping approach (frontmatterToEntryPatch) instead of a new
parse_md_file Tauri command — simpler, works in both Tauri and mock
modes, covers all VaultEntry fields.
- Converted useNoteActions to config object to avoid excess arguments.
- Extracted findWikilinkTarget, reloadTabsAfterRename, renameToastMessage
as standalone functions to reduce hook complexity (cc 10→9).
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-22 17:48:39 +01:00
|
|
|
const notes = useNoteActions({ addEntry: vault.addEntry, updateContent: vault.updateContent, entries: vault.entries, setToastMessage, updateEntry: vault.updateEntry })
|
2026-02-15 12:56:28 +01:00
|
|
|
|
2026-02-22 10:48:13 +01:00
|
|
|
const entryActions = useEntryActions({
|
|
|
|
|
entries: vault.entries,
|
|
|
|
|
updateEntry: vault.updateEntry,
|
|
|
|
|
handleUpdateFrontmatter: notes.handleUpdateFrontmatter,
|
|
|
|
|
handleDeleteProperty: notes.handleDeleteProperty,
|
|
|
|
|
setToastMessage,
|
|
|
|
|
})
|
|
|
|
|
|
2026-02-21 19:15:39 +01:00
|
|
|
// Immediate note creation — no dialog, just create and open
|
|
|
|
|
const handleCreateNoteImmediate = useCallback((type?: string) => {
|
|
|
|
|
const noteType = type || 'Note'
|
|
|
|
|
notes.handleCreateNote(generateUntitledName(vault.entries, noteType), noteType)
|
|
|
|
|
window.dispatchEvent(new CustomEvent('laputa:focus-editor'))
|
|
|
|
|
}, [vault.entries, notes])
|
2026-02-21 09:41:46 +01:00
|
|
|
|
2026-02-17 17:45:31 +01:00
|
|
|
const handleSwitchVault = useCallback((path: string) => {
|
|
|
|
|
setVaultPath(path)
|
|
|
|
|
setSelection(DEFAULT_SELECTION)
|
|
|
|
|
setGitHistory([])
|
|
|
|
|
notes.closeAllTabs()
|
|
|
|
|
}, [notes])
|
|
|
|
|
|
2026-02-22 17:46:31 +01:00
|
|
|
const handleVaultCloned = useCallback((path: string, label: string) => {
|
|
|
|
|
setExtraVaults(prev => {
|
|
|
|
|
if (prev.some(v => v.path === path)) return prev
|
|
|
|
|
return [...prev, { label, path }]
|
|
|
|
|
})
|
|
|
|
|
handleSwitchVault(path)
|
|
|
|
|
setToastMessage(`Vault "${label}" cloned and opened`)
|
|
|
|
|
}, [handleSwitchVault])
|
|
|
|
|
|
2026-02-14 20:53:52 +01:00
|
|
|
useEffect(() => {
|
2026-02-22 10:48:13 +01:00
|
|
|
if (!notes.activeTabPath) { setGitHistory([]); return }
|
2026-02-17 12:10:21 +01:00
|
|
|
vault.loadGitHistory(notes.activeTabPath).then(setGitHistory)
|
fix: resolve React hooks/compiler ESLint errors
- Wrap ref assignments in useEffect to fix refs-during-render in
useTabManagement, useKeyboardNavigation, and Editor
- Rewrite useAppKeyboard to define keyMap inside useEffect, eliminating
ref access during render
- Add eslint-disable for react-hooks/set-state-in-effect on legitimate
dialog reset patterns (CommitDialog, CreateNoteDialog, CreateTypeDialog,
QuickOpenPalette, AIChatPanel, useVaultLoader)
- Add eslint-disable for react-hooks/static-components on icon lookups
(NoteItem, NoteList PinnedCard) — stateless icon components from a
static map
- Add eslint-disable for react-hooks/purity on Date.now() in
NoteItem TrashDateLine — intentionally memoized on trashedAt
- Remove unused `model` param from buildSystemPrompt (ai-chat.ts) and
update callers
- Fix exhaustive-deps: suppress vault object dep in App.tsx git history
effect (vault object is unstable, loadGitHistory is the real dep)
- Remove unused `modifiedFiles` from useNoteListData params and caller
- Add missing `ref` to Sidebar useOutsideClick deps
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-22 14:06:51 +01:00
|
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps -- vault object is unstable; loadGitHistory is the actual dep
|
2026-02-17 12:10:21 +01:00
|
|
|
}, [notes.activeTabPath, vault.loadGitHistory])
|
2026-02-14 20:53:52 +01:00
|
|
|
|
2026-02-21 09:41:46 +01:00
|
|
|
const openCreateTypeDialog = useCallback(() => {
|
|
|
|
|
setShowCreateTypeDialog(true)
|
2026-02-20 23:49:30 +01:00
|
|
|
}, [])
|
|
|
|
|
|
2026-02-21 09:41:46 +01:00
|
|
|
const handleCreateType = useCallback((name: string) => {
|
|
|
|
|
notes.handleCreateType(name)
|
|
|
|
|
setToastMessage(`Type "${name}" created`)
|
2026-02-22 10:48:13 +01:00
|
|
|
}, [notes])
|
2026-02-21 17:29:42 +01:00
|
|
|
|
2026-02-21 19:22:44 +01:00
|
|
|
const handleRenameTab = useCallback((path: string, newTitle: string) => {
|
|
|
|
|
notes.handleRenameNote(path, newTitle, vaultPath, vault.replaceEntry)
|
|
|
|
|
}, [notes, vaultPath, vault])
|
|
|
|
|
|
2026-02-20 19:59:05 +01:00
|
|
|
useAppKeyboard({
|
|
|
|
|
onQuickOpen: () => setShowQuickOpen(true),
|
2026-02-21 19:15:39 +01:00
|
|
|
onCreateNote: handleCreateNoteImmediate,
|
2026-02-20 19:59:05 +01:00
|
|
|
onSave: () => setToastMessage('Saved'),
|
2026-02-22 13:38:18 +01:00
|
|
|
onOpenSettings: () => setShowSettings(true),
|
2026-02-22 10:48:13 +01:00
|
|
|
onTrashNote: entryActions.handleTrashNote,
|
|
|
|
|
onArchiveNote: entryActions.handleArchiveNote,
|
2026-02-20 19:59:05 +01:00
|
|
|
activeTabPathRef: notes.activeTabPathRef,
|
|
|
|
|
handleCloseTabRef: notes.handleCloseTabRef,
|
|
|
|
|
})
|
2026-02-14 21:14:16 +01:00
|
|
|
|
2026-02-22 12:10:24 +01:00
|
|
|
useUpdater()
|
|
|
|
|
|
2026-02-21 10:50:50 +01:00
|
|
|
useKeyboardNavigation({
|
|
|
|
|
tabs: notes.tabs,
|
|
|
|
|
activeTabPath: notes.activeTabPath,
|
|
|
|
|
entries: vault.entries,
|
|
|
|
|
selection,
|
|
|
|
|
allContent: vault.allContent,
|
|
|
|
|
onSwitchTab: notes.handleSwitchTab,
|
|
|
|
|
onReplaceActiveTab: notes.handleReplaceActiveTab,
|
|
|
|
|
onSelectNote: notes.handleSelectNote,
|
|
|
|
|
})
|
|
|
|
|
|
2026-02-15 13:00:10 +01:00
|
|
|
const handleCommitPush = useCallback(async (message: string) => {
|
|
|
|
|
setShowCommitDialog(false)
|
|
|
|
|
try {
|
2026-02-17 12:10:21 +01:00
|
|
|
const result = await vault.commitAndPush(message)
|
|
|
|
|
setToastMessage(result)
|
|
|
|
|
vault.loadModifiedFiles()
|
2026-02-15 13:00:10 +01:00
|
|
|
} catch (err) {
|
|
|
|
|
console.error('Commit failed:', err)
|
|
|
|
|
setToastMessage(`Commit failed: ${err}`)
|
|
|
|
|
}
|
2026-02-17 12:10:21 +01:00
|
|
|
}, [vault])
|
|
|
|
|
|
|
|
|
|
const activeTab = notes.tabs.find((t) => t.entry.path === notes.activeTabPath) ?? null
|
2026-02-15 13:00:10 +01:00
|
|
|
|
2026-02-14 18:20:07 +01:00
|
|
|
return (
|
2026-02-17 11:03:23 +01:00
|
|
|
<div className="app-shell">
|
|
|
|
|
<div className="app">
|
2026-02-22 10:48:13 +01:00
|
|
|
<div className="app__sidebar" style={{ width: layout.sidebarWidth }}>
|
2026-02-22 11:38:03 +01:00
|
|
|
<Sidebar entries={vault.entries} selection={selection} onSelect={setSelection} onSelectNote={notes.handleSelectNote} onCreateType={handleCreateNoteImmediate} onCreateNewType={openCreateTypeDialog} onCustomizeType={entryActions.handleCustomizeType} onReorderSections={entryActions.handleReorderSections} modifiedCount={vault.modifiedFiles.length} onCommitPush={() => setShowCommitDialog(true)} />
|
2026-02-17 11:03:23 +01:00
|
|
|
</div>
|
2026-02-22 10:48:13 +01:00
|
|
|
<ResizeHandle onResize={layout.handleSidebarResize} />
|
|
|
|
|
<div className="app__note-list" style={{ width: layout.noteListWidth }}>
|
2026-02-21 19:15:39 +01:00
|
|
|
<NoteList entries={vault.entries} selection={selection} selectedNote={activeTab?.entry ?? null} allContent={vault.allContent} modifiedFiles={vault.modifiedFiles} onSelectNote={notes.handleSelectNote} onCreateNote={handleCreateNoteImmediate} />
|
2026-02-17 11:03:23 +01:00
|
|
|
</div>
|
2026-02-22 10:48:13 +01:00
|
|
|
<ResizeHandle onResize={layout.handleNoteListResize} />
|
2026-02-17 11:03:23 +01:00
|
|
|
<div className="app__editor">
|
|
|
|
|
<Editor
|
2026-02-17 12:10:21 +01:00
|
|
|
tabs={notes.tabs}
|
|
|
|
|
activeTabPath={notes.activeTabPath}
|
|
|
|
|
entries={vault.entries}
|
|
|
|
|
onSwitchTab={notes.handleSwitchTab}
|
|
|
|
|
onCloseTab={notes.handleCloseTab}
|
2026-02-21 17:24:01 +01:00
|
|
|
onReorderTabs={notes.handleReorderTabs}
|
2026-02-17 12:10:21 +01:00
|
|
|
onNavigateWikilink={notes.handleNavigateWikilink}
|
|
|
|
|
onLoadDiff={vault.loadDiff}
|
2026-02-21 22:27:18 +01:00
|
|
|
onLoadDiffAtCommit={vault.loadDiffAtCommit}
|
2026-02-17 12:10:21 +01:00
|
|
|
isModified={vault.isFileModified}
|
2026-02-21 19:15:39 +01:00
|
|
|
onCreateNote={handleCreateNoteImmediate}
|
2026-02-22 10:48:13 +01:00
|
|
|
inspectorCollapsed={layout.inspectorCollapsed}
|
|
|
|
|
onToggleInspector={() => layout.setInspectorCollapsed((c) => !c)}
|
|
|
|
|
inspectorWidth={layout.inspectorWidth}
|
|
|
|
|
onInspectorResize={layout.handleInspectorResize}
|
2026-02-17 11:03:23 +01:00
|
|
|
inspectorEntry={activeTab?.entry ?? null}
|
|
|
|
|
inspectorContent={activeTab?.content ?? null}
|
2026-02-17 12:10:21 +01:00
|
|
|
allContent={vault.allContent}
|
2026-02-17 11:03:23 +01:00
|
|
|
gitHistory={gitHistory}
|
2026-02-17 12:10:21 +01:00
|
|
|
onUpdateFrontmatter={notes.handleUpdateFrontmatter}
|
|
|
|
|
onDeleteProperty={notes.handleDeleteProperty}
|
|
|
|
|
onAddProperty={notes.handleAddProperty}
|
2026-02-20 16:06:51 +01:00
|
|
|
showAIChat={showAIChat}
|
|
|
|
|
onToggleAIChat={() => setShowAIChat(c => !c)}
|
2026-02-21 10:07:02 +01:00
|
|
|
vaultPath={vaultPath}
|
2026-02-22 10:48:13 +01:00
|
|
|
onTrashNote={entryActions.handleTrashNote}
|
|
|
|
|
onRestoreNote={entryActions.handleRestoreNote}
|
|
|
|
|
onArchiveNote={entryActions.handleArchiveNote}
|
|
|
|
|
onUnarchiveNote={entryActions.handleUnarchiveNote}
|
2026-02-21 19:22:44 +01:00
|
|
|
onRenameTab={handleRenameTab}
|
2026-02-17 11:03:23 +01:00
|
|
|
/>
|
|
|
|
|
</div>
|
2026-02-14 18:20:07 +01:00
|
|
|
</div>
|
2026-02-22 17:46:31 +01:00
|
|
|
<StatusBar noteCount={vault.entries.length} vaultPath={vaultPath} vaults={allVaults} onSwitchVault={handleSwitchVault} onOpenSettings={() => setShowSettings(true)} onConnectGitHub={() => setShowGitHubVault(true)} hasGitHub={!!settings.github_token} />
|
2026-02-14 21:19:38 +01:00
|
|
|
<Toast message={toastMessage} onDismiss={() => setToastMessage(null)} />
|
2026-02-22 10:48:13 +01:00
|
|
|
<QuickOpenPalette open={showQuickOpen} entries={vault.entries} onSelect={notes.handleSelectNote} onClose={() => setShowQuickOpen(false)} />
|
|
|
|
|
<CreateTypeDialog open={showCreateTypeDialog} onClose={() => setShowCreateTypeDialog(false)} onCreate={handleCreateType} />
|
|
|
|
|
<CommitDialog open={showCommitDialog} modifiedCount={vault.modifiedFiles.length} onCommit={handleCommitPush} onClose={() => setShowCommitDialog(false)} />
|
2026-02-22 13:38:18 +01:00
|
|
|
<SettingsPanel open={showSettings} settings={settings} onSave={saveSettings} onClose={() => setShowSettings(false)} />
|
2026-02-22 17:46:31 +01:00
|
|
|
<GitHubVaultModal
|
|
|
|
|
open={showGitHubVault}
|
|
|
|
|
githubToken={settings.github_token}
|
|
|
|
|
onClose={() => setShowGitHubVault(false)}
|
|
|
|
|
onVaultCloned={handleVaultCloned}
|
|
|
|
|
onOpenSettings={() => { setShowGitHubVault(false); setShowSettings(true) }}
|
|
|
|
|
/>
|
2026-02-14 18:22:42 +01:00
|
|
|
</div>
|
2026-02-14 18:20:07 +01:00
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default App
|