Skip to content

Commit

Permalink
fix: Load projects from firebase when logged in
Browse files Browse the repository at this point in the history
  • Loading branch information
aklinker1 committed Sep 2, 2024
1 parent 7f3bad2 commit e583a96
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 14 deletions.
10 changes: 7 additions & 3 deletions web/composables/useDeleteProject.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import useInvalidateProjectListQuery from './useInvalidateProjectListQuery';

export default function () {
const projects = useProjects();
const account = useAccountService();
const closeTab = useCloseTab();
const invalidateProjectsQuery = useInvalidateProjectListQuery();

return (id: string) => {
return async (id: string) => {
await account.value.removeProject(id);
await invalidateProjectsQuery();
closeTab(id);
projects.value = projects.value.filter((project) => project.id !== id);
};
}
8 changes: 4 additions & 4 deletions web/composables/useEditProject.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export default function () {
const { openDialog } = useDialogState();
const allProjects = useProjects();
const account = useAccountService();
const invalidateProjectsQuery = useInvalidateProjectListQuery();

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

const newProject = await openExistingProject(project);
allProjects.value = allProjects.value.map((p) =>
p.id === newProject.id ? newProject : p,
);
await account.value.saveProject(newProject);
await invalidateProjectsQuery();
};
}
11 changes: 11 additions & 0 deletions web/composables/useInvalidateProjectListQuery.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { useQueryClient } from '@tanstack/vue-query';

export default function () {
const client = useQueryClient();
const accountId = useAccountServiceId();
return async () => {
client.invalidateQueries({
queryKey: ['projects', accountId.value],
});
};
}
2 changes: 1 addition & 1 deletion web/composables/useProject.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export default function () {
const route = useRoute();
const id = computed(() => route.params.id as string | undefined);
const projects = useProjects();
const { data: projects } = useProjectListQuery();

return computed(() => projects.value.find((p) => p.id === id.value));
}
5 changes: 0 additions & 5 deletions web/composables/useProjects.ts

This file was deleted.

2 changes: 1 addition & 1 deletion web/layouts/default.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script lang="ts" setup>
const openIds = useOpenProjectIds();
const projects = useProjects();
const { data: projects } = useProjectListQuery();
const tabs = computed(() =>
openIds.value.map((id) => {
Expand Down

0 comments on commit e583a96

Please sign in to comment.