Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 5 additions & 10 deletions frontend/src/stores/dashboard.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { defineStore } from "pinia";
import { useAuthStore } from '@/stores/auth'
import {
fetchDashboardData,
fetchLast7DaysHistory,
Expand All @@ -7,27 +8,21 @@ import {
} from "@/api/dashboard.ts";

export const useDashboardStore = defineStore('dashboard', {
state: () => ({
token: localStorage.getItem('token') as string | null,
}),

getters: {
isAuthenticated: (state) => !!state.token,
},

actions: {
async dashboard(): Promise<DashboardData> {
const auth = useAuthStore()
try {
return await fetchDashboardData(this.token ?? undefined);
return await fetchDashboardData(auth.token ?? undefined);
} catch (e) {
console.error('Failed to fetch dashboard data', e);
throw e;
}
},

async historyLast7Days(): Promise<Last7DaysResponse> {
const auth = useAuthStore()
try {
return await fetchLast7DaysHistory(this.token ?? undefined);
return await fetchLast7DaysHistory(auth.token ?? undefined)
} catch (e) {
console.error('Failed to fetch last 7 days history', e);
throw e;
Expand Down
15 changes: 5 additions & 10 deletions frontend/src/stores/history.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {defineStore} from 'pinia';
import { useAuthStore } from '@/stores/auth'
import {
fetchHistoryData,
type HistoryData,
Expand All @@ -8,27 +9,21 @@ import {
import type {DayStatus} from "@/api/dashboard.ts";

export const useHistoryStore = defineStore('history', {
state: () => ({
token: localStorage.getItem('token') as string | null,
}),

getters: {
isAuthenticated: (state) => !!state.token,
},

actions: {
async fetchHistory(): Promise<HistoryData> {
const auth = useAuthStore()
try {
return await fetchHistoryData(this.token ?? undefined);
return await fetchHistoryData(auth.token ?? undefined);
} catch(e) {
console.error('Failed to fetch history data', e);
throw e;
}
},

async updateStatus(date: string, status: DayStatus): Promise<SingleDayEntry> {
const auth = useAuthStore()
try {
return await updateDayStatus(date, status, this.token ?? undefined);
return await updateDayStatus(date, status, auth.token ?? undefined);
} catch (e) {
console.error(`Failed to update day status for day ${date}`, e);
throw e;
Expand Down