From 62fa94961f7268de2f64bf850770b031f7f3eb8c Mon Sep 17 00:00:00 2001 From: enya-yy Date: Wed, 11 Oct 2023 22:21:20 +0800 Subject: [PATCH] feat: add team composable --- composables/useTeam.ts | 34 ++++++++++++++++++++++++++++++++++ layouts/entrySidebar.vue | 30 +++++++++++++++++------------- pages/dashboard.vue | 6 ++++-- types.d.ts | 4 ++++ 4 files changed, 59 insertions(+), 15 deletions(-) create mode 100644 composables/useTeam.ts diff --git a/composables/useTeam.ts b/composables/useTeam.ts new file mode 100644 index 0000000..7f598fb --- /dev/null +++ b/composables/useTeam.ts @@ -0,0 +1,34 @@ +import type { Team } from '~/types' + +export function useTeam() { + const currentTeam = useState('team', () => null) + + const teamList = useState('teamList', () => []) + + async function fetchTeamList() { + const data = [{ + name: 'Team A', + }, { + name: 'Team B', + }, { + name: 'Team C', + }] + teamList.value = data + } + + async function selectTeam(team: Team) { + currentTeam.value = team + } + + async function deleteTeam(team: Team) { + teamList.value.splice(teamList.value.findIndex((item: Team) => item.name === team.name), 1) + } + + return { + currentTeam, + teamList, + fetchTeamList, + selectTeam, + deleteTeam, + } +} diff --git a/layouts/entrySidebar.vue b/layouts/entrySidebar.vue index 056cc5a..27950a7 100644 --- a/layouts/entrySidebar.vue +++ b/layouts/entrySidebar.vue @@ -1,25 +1,28 @@ @@ -43,12 +46,13 @@ function submitCreateTeam(team: { name: string }) {
Your teams - +
    -
  • +
  • {{ team.name?.[0] }} - {{ team.name }} + {{ team.name }} +
diff --git a/pages/dashboard.vue b/pages/dashboard.vue index 97d1263..a9bc5b1 100644 --- a/pages/dashboard.vue +++ b/pages/dashboard.vue @@ -2,7 +2,9 @@ definePageMeta({ layout: 'entry-sidebar', }) -const title = ref('Team A') + +const { currentTeam } = useTeam() + const { $client } = useNuxtApp() const { pending, error, data: projects } = $client.protected.projectList.useQuery() @@ -11,7 +13,7 @@ const { pending, error, data: projects } = $client.protected.projectList.useQuer