Skip to content

Commit

Permalink
List projects from accout service
Browse files Browse the repository at this point in the history
  • Loading branch information
aklinker1 committed Apr 25, 2024
1 parent e374a49 commit 6883e4e
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 31 deletions.
47 changes: 47 additions & 0 deletions web/components/ProjectList.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<script lang="ts" setup>
const createNewProject = useCreateNewProject();
const { data: projects, isFetching } = useProjectListQuery();
const filter = ref('');
const filteredProjects = useArrayFilter(projects, (p) =>
p.name.toLowerCase().includes(filter.value.toLowerCase()),
);
const openProject = useOpenProject();
const deleteProject = useDeleteProject();
</script>

<template>
<ul class="flex flex-col gap-2">
<li>
<UInput
v-model="filter"
placeholder="Filter projects..."
icon="i-heroicons-magnifying-glass"
/>
</li>
<ProjectListItem
v-for="project of filteredProjects"
:key="project.id"
:project
@open="openProject"
@delete="deleteProject"
/>
<li v-if="isFetching" class="flex justify-center">
<UButton
class="pointer-events-none"
loading
variant="ghost"
color="white"
disabled
>
Loading...
</UButton>
</li>
<li v-else-if="filteredProjects.length === 0" class="text-center py-16">
No projects,
<ULink variant="link" @click="createNewProject">add one</ULink>
</li>
<slot />
</ul>
</template>
4 changes: 4 additions & 0 deletions web/composables/useAccountServiceId.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export default function () {
const account = useAccountService();
return computed(() => account.value.id);
}
12 changes: 12 additions & 0 deletions web/composables/useProjectListQuery.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { useQuery } from '@tanstack/vue-query';

export default function () {
const account = useAccountService();
const accountId = useAccountServiceId();
const user = useCurrentUser();
return useQuery({
queryKey: ['projects', accountId],
queryFn: () => account.value.listProjects(),
initialData: [],
});
}
2 changes: 1 addition & 1 deletion web/pages/account.vue
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ async function syncProjects() {
<div class="bg-gray-200 dark:bg-gray-800 h-full p-8 flex flex-col gap-4">
<h2 class="text-2xl font-medium line-clamp-1 truncate">Account</h2>
<template v-if="!currentUser">
<p>Login to share settings and projects between devices</p>
<p>Login to share settings and projects between devices.</p>
<div ref="container" v-if="!currentUser" />
</template>
<template v-else>
Expand Down
31 changes: 2 additions & 29 deletions web/pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,6 @@
import { version } from '~~/package.json';
const createNewProject = useCreateNewProject();
const projects = useProjects();
const filter = ref('');
const filteredProjects = useArrayFilter(projects, (p) =>
p.name.toLowerCase().includes(filter.value.toLowerCase()),
);
const openProject = useOpenProject();
const deleteProject = useDeleteProject();
</script>

<template>
Expand All @@ -28,25 +19,7 @@ const deleteProject = useDeleteProject();
>
</div>
<ClientOnly>
<ul class="flex flex-col gap-2">
<li v-if="projects.length">
<UInput
v-model="filter"
placeholder="Filter projects..."
icon="i-heroicons-magnifying-glass"
/>
</li>
<ProjectListItem
v-for="project of filteredProjects"
:key="project.id"
:project
@open="openProject"
@delete="deleteProject"
/>
<li v-if="filteredProjects.length === 0" class="text-center py-16">
No projects,
<ULink variant="link" @click="createNewProject">add one</ULink>
</li>
<ProjectList>
<li class="text-center pt-16 opacity-50">
<ULink
class="hover:underline"
Expand All @@ -69,7 +42,7 @@ const deleteProject = useDeleteProject();
>User Manual</ULink
>
</li>
</ul>
</ProjectList>
</ClientOnly>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion web/plugins/vue-query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default defineNuxtPlugin((nuxt) => {
const queryClient = new QueryClient({
defaultOptions: {
queries: {
refetchOnMount: false,
refetchOnMount: true,
refetchOnWindowFocus: false,
retry: false,
},
Expand Down
1 change: 1 addition & 0 deletions web/utils/accounts/AccountService.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { Project } from '../projects';

export interface AccountService {
id: string;
getSettings(): Promise<AccountSettings>;
setSettings(changes: Partial<AccountSettings>): Promise<void>;
listProjects(): Promise<Project[]>;
Expand Down
1 change: 1 addition & 0 deletions web/utils/accounts/FirebaseAccountService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export function createFirebaseAccountService(): AccountService {
const projectDoc = (id: string) => doc(usersRef, getUid(), 'projects', id);

return {
id: 'firebase',
async getSettings() {
const res = await getDoc(settingsDoc());
return {
Expand Down
1 change: 1 addition & 0 deletions web/utils/accounts/LocalAccountService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export function createLocalAccountService(): AccountService {
};

return {
id: 'local',
async getSettings() {
return getSettings();
},
Expand Down

0 comments on commit 6883e4e

Please sign in to comment.