mitlist/fe/src/stores/groupStore.ts
mohamad ddaa20af3c Remove deprecated task management files and enhance group management functionality
- Deleted obsolete task management files: `tasks.mdc` and `notes.md`.
- Introduced a new `groupStore` for managing group data, including fetching user groups and handling loading states.
- Updated `MainLayout.vue` to navigate to groups with improved loading checks.
- Enhanced `GroupsPage.vue` to support a tabbed interface for creating and joining groups, improving user experience.
- Refined `GroupDetailPage.vue` to display recent expenses with a more interactive layout and added functionality for settling shares.
2025-06-07 18:05:08 +02:00

37 lines
1.1 KiB
TypeScript

import { defineStore } from 'pinia';
import { groupService, type Group } from '@/services/groupService';
export const useGroupStore = defineStore('group', {
state: () => ({
groups: [] as Group[],
isLoading: false,
error: null as Error | null,
}),
actions: {
async fetchGroups() {
// Small cache implemented to prevent re-fetching on every mount
if (this.groups.length > 0) {
return;
}
this.isLoading = true;
this.error = null;
try {
this.groups = await groupService.getUserGroups();
} catch (error) {
this.error = error as Error;
console.error('Failed to fetch groups:', error);
} finally {
this.isLoading = false;
}
},
},
getters: {
groupCount: (state) => state.groups.length,
firstGroupId: (state): number | null => {
if (state.groups.length === 1) {
return state.groups[0].id;
}
return null;
}
}
});