Skip to content

Commit e583a96

Browse files
committed
fix: Load projects from firebase when logged in
1 parent 7f3bad2 commit e583a96

6 files changed

+24
-14
lines changed

web/composables/useDeleteProject.ts

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1+
import useInvalidateProjectListQuery from './useInvalidateProjectListQuery';
2+
13
export default function () {
2-
const projects = useProjects();
4+
const account = useAccountService();
35
const closeTab = useCloseTab();
6+
const invalidateProjectsQuery = useInvalidateProjectListQuery();
47

5-
return (id: string) => {
8+
return async (id: string) => {
9+
await account.value.removeProject(id);
10+
await invalidateProjectsQuery();
611
closeTab(id);
7-
projects.value = projects.value.filter((project) => project.id !== id);
812
};
913
}

web/composables/useEditProject.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
export default function () {
22
const { openDialog } = useDialogState();
3-
const allProjects = useProjects();
3+
const account = useAccountService();
4+
const invalidateProjectsQuery = useInvalidateProjectListQuery();
45

56
const openExistingProject = (project: Project) =>
67
new Promise<Project>((res, rej) => {
@@ -16,8 +17,7 @@ export default function () {
1617
if (project == null) return;
1718

1819
const newProject = await openExistingProject(project);
19-
allProjects.value = allProjects.value.map((p) =>
20-
p.id === newProject.id ? newProject : p,
21-
);
20+
await account.value.saveProject(newProject);
21+
await invalidateProjectsQuery();
2222
};
2323
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { useQueryClient } from '@tanstack/vue-query';
2+
3+
export default function () {
4+
const client = useQueryClient();
5+
const accountId = useAccountServiceId();
6+
return async () => {
7+
client.invalidateQueries({
8+
queryKey: ['projects', accountId.value],
9+
});
10+
};
11+
}

web/composables/useProject.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
export default function () {
22
const route = useRoute();
33
const id = computed(() => route.params.id as string | undefined);
4-
const projects = useProjects();
4+
const { data: projects } = useProjectListQuery();
55

66
return computed(() => projects.value.find((p) => p.id === id.value));
77
}

web/composables/useProjects.ts

-5
This file was deleted.

web/layouts/default.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<script lang="ts" setup>
22
const openIds = useOpenProjectIds();
3-
const projects = useProjects();
3+
const { data: projects } = useProjectListQuery();
44
55
const tabs = computed(() =>
66
openIds.value.map((id) => {

0 commit comments

Comments
 (0)