summaryrefslogtreecommitdiff
path: root/apps/web/src/stores
diff options
context:
space:
mode:
authorMaze Winther <mazewinther@gmail.com>2025-07-17 17:19:23 +0200
committerMaze Winther <mazewinther@gmail.com>2025-07-17 17:19:23 +0200
commitce47e88e3482a55e4ed4c1c790ce85fd9109a2ee (patch)
tree671a1bc178b7a9ef11a9afe131b7160846d600a4 /apps/web/src/stores
parent9af8905c0c945766defb9b77990928e099a650bd (diff)
parent502725b98ec53b1668ceeae1a9f5463c64cdddf6 (diff)
downloadopencut-ce47e88e3482a55e4ed4c1c790ce85fd9109a2ee.tar.gz
Merge branch 'main' of https://github.com/mazeincoding/AppCut
Diffstat (limited to 'apps/web/src/stores')
-rw-r--r--apps/web/src/stores/project-store.ts41
1 files changed, 41 insertions, 0 deletions
diff --git a/apps/web/src/stores/project-store.ts b/apps/web/src/stores/project-store.ts
index efb9cc71..a8833982 100644
--- a/apps/web/src/stores/project-store.ts
+++ b/apps/web/src/stores/project-store.ts
@@ -27,6 +27,11 @@ interface ProjectStore {
options?: { backgroundColor?: string; blurIntensity?: number }
) => Promise<void>;
updateProjectFps: (fps: number) => Promise<void>;
+
+ getFilteredAndSortedProjects: (
+ searchQuery: string,
+ sortOption: string
+ ) => TProject[];
}
export const useProjectStore = create<ProjectStore>((set, get) => ({
@@ -317,4 +322,40 @@ export const useProjectStore = create<ProjectStore>((set, get) => ({
});
}
},
+
+ getFilteredAndSortedProjects: (searchQuery: string, sortOption: string) => {
+ const { savedProjects } = get();
+
+ // Filter projects by search query
+ const filteredProjects = savedProjects.filter((project) =>
+ project.name.toLowerCase().includes(searchQuery.toLowerCase())
+ );
+
+ // Sort filtered projects
+ const sortedProjects = [...filteredProjects].sort((a, b) => {
+ const [key, order] = sortOption.split("-");
+
+ if (key !== "createdAt" && key !== "name") {
+ console.warn(`Invalid sort key: ${key}`);
+ return 0;
+ }
+
+ const aValue = a[key];
+ const bValue = b[key];
+
+ if (aValue === undefined || bValue === undefined) return 0;
+
+ if (order === "asc") {
+ if (aValue < bValue) return -1;
+ if (aValue > bValue) return 1;
+ return 0;
+ } else {
+ if (aValue > bValue) return -1;
+ if (aValue < bValue) return 1;
+ return 0;
+ }
+ });
+
+ return sortedProjects;
+ },
}));