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
This commit is contained in:
Christoph Brandau
2026-07-09 09:01:42 +02:00
parent 2c9b8adb9e
commit c8d5553214
+13 -13
View File
@@ -377,14 +377,14 @@
$: localBranchNames = localBranches.map((b) => b.name); $: localBranchNames = localBranches.map((b) => b.name);
$: remoteBranches = branches.filter((b) => b.remote); $: remoteBranches = branches.filter((b) => b.remote);
$: repoSearchTerm = repoSearch.trim().toLowerCase(); $: repoSearchTerm = repoSearch.trim().toLowerCase();
$: openRepoRows = repoTabs.filter(repoMatchesSearch); $: openRepoRows = repoTabs.filter((repo) => repoMatchesSearch(repo, repoSearchTerm));
$: recentRepoRows = recentRepoPaths $: recentRepoRows = recentRepoPaths
.filter((path) => !repoTabs.some((tab) => sameRepoPath(tab.path, path))) .filter((path) => !repoTabs.some((tab) => sameRepoPath(tab.path, path)))
.map(repoRowFromPath) .map((path) => repoRowFromPath(path, repoTabs, repoStatusCache))
.filter(repoMatchesSearch); .filter((repo) => repoMatchesSearch(repo, repoSearchTerm));
$: favoriteRepoRows = favoriteRepoPaths $: favoriteRepoRows = favoriteRepoPaths
.map(repoRowFromPath) .map((path) => repoRowFromPath(path, repoTabs, repoStatusCache))
.filter(repoMatchesSearch); .filter((repo) => repoMatchesSearch(repo, repoSearchTerm));
$: leftSidebarRows = buildLeftSidebarRows(branchPanelCollapsed, stashPanelCollapsed, explorerPanelCollapsed); $: leftSidebarRows = buildLeftSidebarRows(branchPanelCollapsed, stashPanelCollapsed, explorerPanelCollapsed);
$: allLeftPanelsCollapsed = branchPanelCollapsed && stashPanelCollapsed && explorerPanelCollapsed; $: allLeftPanelsCollapsed = branchPanelCollapsed && stashPanelCollapsed && explorerPanelCollapsed;
@@ -949,11 +949,11 @@
return result; return result;
} }
function repoRowFromPath(path: string): RepoTab { function repoRowFromPath(path: string, tabs = repoTabs, statusCache = repoStatusCache): RepoTab {
const openTab = repoTabs.find((tab) => sameRepoPath(tab.path, path)); const openTab = tabs.find((tab) => sameRepoPath(tab.path, path));
if (openTab) return openTab; if (openTab) return openTab;
const cached = repoStatusCache[repoKey(path)]; const cached = statusCache[repoKey(path)];
if (cached) return { ...cached, path, name: repoNameFromPath(path) }; if (cached) return { ...cached, path, name: repoNameFromPath(path) };
return { return {
@@ -967,11 +967,11 @@
}; };
} }
function repoMatchesSearch(repo: RepoTab): boolean { function repoMatchesSearch(repo: RepoTab, searchTerm = repoSearchTerm): boolean {
if (!repoSearchTerm) return true; if (!searchTerm) return true;
return repo.name.toLowerCase().includes(repoSearchTerm) return repo.name.toLowerCase().includes(searchTerm)
|| repo.path.toLowerCase().includes(repoSearchTerm) || repo.path.toLowerCase().includes(searchTerm)
|| (repo.branch ?? "").toLowerCase().includes(repoSearchTerm); || (repo.branch ?? "").toLowerCase().includes(searchTerm);
} }
function loadRepoLists() { function loadRepoLists() {