diff --git a/src/components/GitHubOpenDialog.tsx b/src/components/GitHubOpenDialog.tsx index 47d4058..a264ea5 100644 --- a/src/components/GitHubOpenDialog.tsx +++ b/src/components/GitHubOpenDialog.tsx @@ -1,5 +1,5 @@ import { openUrl } from "@tauri-apps/plugin-opener"; -import { useCallback, useEffect, useRef, useState } from "react"; +import { Fragment, useCallback, useEffect, useRef, useState } from "react"; import { getGitHubToken, githubAuthHeaders, @@ -83,6 +83,8 @@ export function GitHubOpenDialog({ onClose, onOpen, onOpenVault }: Props) { const [entries, setEntries] = useState([]); // Free-text filter over "Your repositories" (shown once the list is long). const [repoFilter, setRepoFilter] = useState(""); + // When browsing, hide non-text files (a code repo is mostly noise here). + const [mdOnly, setMdOnly] = useState(false); // Auth + repos list. const [signedIn, setSignedIn] = useState(isGitHubSignedIn()); @@ -275,6 +277,16 @@ export function GitHubOpenDialog({ onClose, onOpen, onOpenVault }: Props) { if (next.length > 0) enterDir(next[next.length - 1], false); } + // Jump to a breadcrumb level (0 = repo root) — truncate the stack and reload. + function jumpTo(index: number) { + if (index >= stack.length - 1) return; // already here + const target = stack[index]; + setStack(stack.slice(0, index + 1)); + enterDir(target, false); + } + + const isTextFile = (name: string) => /\.(md|markdown|mdx|mkd|txt)$/i.test(name); + const haveToken = getGitHubToken() !== null; // A bare repo root in the URL bar → offer "Open as vault" as the primary // action (the headline use), with "Browse" as the secondary. @@ -304,9 +316,31 @@ export function GitHubOpenDialog({ onClose, onOpen, onOpenVault }: Props) { ‹ )} - - {browsing ? `${current.repo}/${current.path}` : "Open from GitHub"} - + {browsing ? ( + + {stack.map((lnk, i) => { + const isLast = i === stack.length - 1; + const label = i === 0 ? lnk.repo : lnk.path.split("/").pop() || lnk.repo; + return ( + + {i > 0 && /} + {isLast ? ( + {label} + ) : ( + + )} + + ); + })} + + ) : ( + Open from GitHub + )} {browsing && ( - ))} - - )} + {browsing && + (() => { + const visibleEntries = mdOnly + ? entries.filter((e) => e.isDir || isTextFile(e.name)) + : entries; + return ( + <> + +
+ {visibleEntries.length === 0 && !loading && ( +
+ {entries.length === 0 ? "Empty folder" : "No Markdown files here"} +
+ )} + {visibleEntries.map((e) => ( + + ))} +
+ + ); + })()} {vaultStatus &&
{vaultStatus}
} {error && (