From c8d5553214419e116dd5ad32d34f34e65adea7f5 Mon Sep 17 00:00:00 2001 From: Christoph Brandau Date: Thu, 9 Jul 2026 09:01:42 +0200 Subject: [PATCH] refactor(App): streamline repo search and row mapping functions This update enhances the repo search functionality by passing the search term directly to the filtering functions. It also refactors the row mapping functions to accept parameters for better flexibility and clarity, improving the overall readability and maintainability of the code. - Simplified search and mapping logic for repositories - Improved parameter handling in helper functions --- src/App.svelte | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/App.svelte b/src/App.svelte index 4ba1889..f086c45 100644 --- a/src/App.svelte +++ b/src/App.svelte @@ -377,14 +377,14 @@ $: localBranchNames = localBranches.map((b) => b.name); $: remoteBranches = branches.filter((b) => b.remote); $: repoSearchTerm = repoSearch.trim().toLowerCase(); - $: openRepoRows = repoTabs.filter(repoMatchesSearch); + $: openRepoRows = repoTabs.filter((repo) => repoMatchesSearch(repo, repoSearchTerm)); $: recentRepoRows = recentRepoPaths .filter((path) => !repoTabs.some((tab) => sameRepoPath(tab.path, path))) - .map(repoRowFromPath) - .filter(repoMatchesSearch); + .map((path) => repoRowFromPath(path, repoTabs, repoStatusCache)) + .filter((repo) => repoMatchesSearch(repo, repoSearchTerm)); $: favoriteRepoRows = favoriteRepoPaths - .map(repoRowFromPath) - .filter(repoMatchesSearch); + .map((path) => repoRowFromPath(path, repoTabs, repoStatusCache)) + .filter((repo) => repoMatchesSearch(repo, repoSearchTerm)); $: leftSidebarRows = buildLeftSidebarRows(branchPanelCollapsed, stashPanelCollapsed, explorerPanelCollapsed); $: allLeftPanelsCollapsed = branchPanelCollapsed && stashPanelCollapsed && explorerPanelCollapsed; @@ -949,11 +949,11 @@ return result; } - function repoRowFromPath(path: string): RepoTab { - const openTab = repoTabs.find((tab) => sameRepoPath(tab.path, path)); + function repoRowFromPath(path: string, tabs = repoTabs, statusCache = repoStatusCache): RepoTab { + const openTab = tabs.find((tab) => sameRepoPath(tab.path, path)); if (openTab) return openTab; - const cached = repoStatusCache[repoKey(path)]; + const cached = statusCache[repoKey(path)]; if (cached) return { ...cached, path, name: repoNameFromPath(path) }; return { @@ -967,11 +967,11 @@ }; } - function repoMatchesSearch(repo: RepoTab): boolean { - if (!repoSearchTerm) return true; - return repo.name.toLowerCase().includes(repoSearchTerm) - || repo.path.toLowerCase().includes(repoSearchTerm) - || (repo.branch ?? "").toLowerCase().includes(repoSearchTerm); + function repoMatchesSearch(repo: RepoTab, searchTerm = repoSearchTerm): boolean { + if (!searchTerm) return true; + return repo.name.toLowerCase().includes(searchTerm) + || repo.path.toLowerCase().includes(searchTerm) + || (repo.branch ?? "").toLowerCase().includes(searchTerm); } function loadRepoLists() {