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);
$: 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() {