Skip to content

LLM Wiki is a cross-platform desktop application that turns your documents into an organized, interlinked knowledge base — automatically. Instead of traditional RAG (retrieve-and-answer from scratch every time), the LLM incrementally builds and maintains a persistent wiki from your sources。

TypeScript

fix: restore source view after preview

nash_su01567dfff305
diff --git a/src/components/layout/content-area.tsx b/src/components/layout/content-area.tsx
index 35273b8d..21c48bd2 100644
--- a/src/components/layout/content-area.tsx
+++ b/src/components/layout/content-area.tsx
@@ -1,3 +1,4 @@
+import { useEffect, useState } from "react"
import { useWikiStore } from "@/stores/wiki-store"
import { ChatPanel } from "@/components/chat/chat-panel"
import { SettingsView } from "@/components/settings/settings-view"
@@ -12,6 +13,37 @@ import { PreviewPanel } from "./preview-panel"
export function ContentArea() {
const activeView = useWikiStore((s) => s.activeView)
+ // Keep SourcesView mounted after its first visit. Opening a source uses the
+ // full-width wiki preview, and unmounting the source tree here would discard
+ // its scroll position, expanded folders, and incremental row limit. Hiding
+ // the mounted view makes closing the preview a true return operation.
+ const [hasMountedSources, setHasMountedSources] = useState(activeView === "sources")
+
+ useEffect(() => {
+ if (activeView === "sources") setHasMountedSources(true)
+ }, [activeView])
+
+ // Include the current view directly so the first navigation to Sources does
+ // not wait for the effect above and briefly render an empty content area.
+ if (hasMountedSources || activeView === "sources") {
+ return (
+ <>
+ <div className={activeView === "sources" ? "h-full" : "hidden"}>
+ <SourcesView />
+ </div>
+ {activeView !== "sources" && <ActiveContent activeView={activeView} />}
+ </>
+ )
+ }
+
+ return <ActiveContent activeView={activeView} />
+}
+
+function ActiveContent({
+ activeView,
+}: {
+ activeView: ReturnType<typeof useWikiStore.getState>["activeView"]
+}) {
switch (activeView) {
case "chat":
return <ChatPanel />
@@ -22,7 +54,7 @@ export function ContentArea() {
case "skills":
return <SkillsView />
case "sources":
- return <SourcesView />
+ return null
case "review":
return <ReviewView />
case "lint":
diff --git a/src/components/layout/preview-panel.tsx b/src/components/layout/preview-panel.tsx
index fa9317eb..3079a2e6 100644
--- a/src/components/layout/preview-panel.tsx
+++ b/src/components/layout/preview-panel.tsx
@@ -13,7 +13,7 @@ export function PreviewPanel() {
const previewContentPath = useWikiStore((s) => s.previewContentPath)
const externalPreview = useWikiStore((s) => s.externalPreview)
const setFileContent = useWikiStore((s) => s.setFileContent)
- const setSelectedFile = useWikiStore((s) => s.setSelectedFile)
+ const closePreview = useWikiStore((s) => s.closePreview)
const saveTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null)
// Snapshot of what was most recently loaded from disk. Milkdown re-emits
// `markdownUpdated` on initial parse (before the user types anything),
@@ -111,7 +111,7 @@ export function PreviewPanel() {
{fileName}
</span>
<button
- onClick={() => setSelectedFile(null)}
+ onClick={closePreview}
className="shrink-0 rounded p-1 text-muted-foreground hover:bg-accent"
>
<X className="h-3.5 w-3.5" />
diff --git a/src/stores/wiki-store.test.ts b/src/stores/wiki-store.test.ts
index 7a621d5a..fdafcae7 100644
--- a/src/stores/wiki-store.test.ts
+++ b/src/stores/wiki-store.test.ts
@@ -10,6 +10,7 @@ describe("wiki preview store actions", () => {
fileContent: "",
previewContentPath: null,
externalPreview: null,
+ previewReturnView: null,
})
})
@@ -151,6 +152,26 @@ describe("wiki preview store actions", () => {
expect(state.externalPreview).toBeNull()
})
+ it("returns to the originating sources view when closing a preview", () => {
+ useWikiStore.setState({ activeView: "sources", previewReturnView: null })
+
+ useWikiStore.getState().openFileInPreview(
+ "/project/raw/sources/report.pdf",
+ "extracted text",
+ )
+
+ expect(useWikiStore.getState().activeView).toBe("wiki")
+ expect(useWikiStore.getState().previewReturnView).toBe("sources")
+
+ useWikiStore.getState().closePreview()
+
+ const state = useWikiStore.getState()
+ expect(state.activeView).toBe("sources")
+ expect(state.selectedFile).toBeNull()
+ expect(state.fileContent).toBe("")
+ expect(state.previewReturnView).toBeNull()
+ })
+
it("keeps graph ui state until explicitly reset", () => {
useWikiStore.getState().resetGraphUiState()
diff --git a/src/stores/wiki-store.ts b/src/stores/wiki-store.ts
index e237158e..cab7338b 100644
--- a/src/stores/wiki-store.ts
+++ b/src/stores/wiki-store.ts
@@ -350,6 +350,12 @@ interface WikiState {
fileContent: string
previewContentPath: string | null
externalPreview: ExternalPreview | null
+ /**
+ * View that handed control to the full-width wiki preview. Closing the
+ * preview must return there instead of leaving an empty wiki surface.
+ * This is transient navigation state and must not be persisted.
+ */
+ previewReturnView: Exclude<WikiState["activeView"], "wiki"> | null
/**
* One-shot scroll target for the markdown preview. When the user
* clicks an image in search results and chooses "jump to source",
@@ -391,6 +397,7 @@ interface WikiState {
setFileContent: (content: string) => void
openPathInPreview: (path: string) => void
openFileInPreview: (path: string, content: string) => void
+ closePreview: () => void
setExternalPreview: (preview: ExternalPreview | null) => void
setPendingScrollImageSrc: (src: string | null) => void
setActiveView: (view: WikiState["activeView"]) => void
@@ -420,6 +427,7 @@ export const useWikiStore = create<WikiState>((set) => ({
fileContent: "",
previewContentPath: null,
externalPreview: null,
+ previewReturnView: null,
pendingScrollImageSrc: null,
activeView: "wiki",
llmConfig: {
@@ -452,18 +460,36 @@ export const useWikiStore = create<WikiState>((set) => ({
set({ selectedFile, previewContentPath: null, externalPreview: null }),
setFileContent: (fileContent) => set({ fileContent }),
openPathInPreview: (selectedFile) =>
- set({ selectedFile, previewContentPath: null, externalPreview: null, activeView: "wiki" }),
+ set((state) => ({
+ selectedFile,
+ previewContentPath: null,
+ externalPreview: null,
+ activeView: "wiki",
+ previewReturnView:
+ state.activeView === "wiki" ? state.previewReturnView : state.activeView,
+ })),
openFileInPreview: (selectedFile, fileContent) =>
- set({
+ set((state) => ({
selectedFile,
fileContent,
previewContentPath: selectedFile,
externalPreview: null,
activeView: "wiki",
- }),
+ previewReturnView:
+ state.activeView === "wiki" ? state.previewReturnView : state.activeView,
+ })),
+ closePreview: () =>
+ set((state) => ({
+ selectedFile: null,
+ fileContent: "",
+ previewContentPath: null,
+ externalPreview: null,
+ activeView: state.previewReturnView ?? "wiki",
+ previewReturnView: null,
+ })),
setExternalPreview: (externalPreview) => set({ externalPreview }),
setPendingScrollImageSrc: (pendingScrollImageSrc) => set({ pendingScrollImageSrc }),
- setActiveView: (activeView) => set({ activeView }),
+ setActiveView: (activeView) => set({ activeView, previewReturnView: null }),
searchApiConfig: {
provider: "none",
apiKey: "",