File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import { defineStore } from "pinia" ;
2+ import { useAuthStore } from '@/stores/auth'
23import {
34 fetchDashboardData ,
45 fetchLast7DaysHistory ,
@@ -7,27 +8,21 @@ import {
78} from "@/api/dashboard.ts" ;
89
910export const useDashboardStore = defineStore ( 'dashboard' , {
10- state : ( ) => ( {
11- token : localStorage . getItem ( 'token' ) as string | null ,
12- } ) ,
13-
14- getters : {
15- isAuthenticated : ( state ) => ! ! state . token ,
16- } ,
17-
1811 actions : {
1912 async dashboard ( ) : Promise < DashboardData > {
13+ const auth = useAuthStore ( )
2014 try {
21- return await fetchDashboardData ( this . token ?? undefined ) ;
15+ return await fetchDashboardData ( auth . token ?? undefined ) ;
2216 } catch ( e ) {
2317 console . error ( 'Failed to fetch dashboard data' , e ) ;
2418 throw e ;
2519 }
2620 } ,
2721
2822 async historyLast7Days ( ) : Promise < Last7DaysResponse > {
23+ const auth = useAuthStore ( )
2924 try {
30- return await fetchLast7DaysHistory ( this . token ?? undefined ) ;
25+ return await fetchLast7DaysHistory ( auth . token ?? undefined )
3126 } catch ( e ) {
3227 console . error ( 'Failed to fetch last 7 days history' , e ) ;
3328 throw e ;
Original file line number Diff line number Diff line change 11import { defineStore } from 'pinia' ;
2+ import { useAuthStore } from '@/stores/auth'
23import {
34 fetchHistoryData ,
45 type HistoryData ,
@@ -8,27 +9,21 @@ import {
89import type { DayStatus } from "@/api/dashboard.ts" ;
910
1011export const useHistoryStore = defineStore ( 'history' , {
11- state : ( ) => ( {
12- token : localStorage . getItem ( 'token' ) as string | null ,
13- } ) ,
14-
15- getters : {
16- isAuthenticated : ( state ) => ! ! state . token ,
17- } ,
18-
1912 actions : {
2013 async fetchHistory ( ) : Promise < HistoryData > {
14+ const auth = useAuthStore ( )
2115 try {
22- return await fetchHistoryData ( this . token ?? undefined ) ;
16+ return await fetchHistoryData ( auth . token ?? undefined ) ;
2317 } catch ( e ) {
2418 console . error ( 'Failed to fetch history data' , e ) ;
2519 throw e ;
2620 }
2721 } ,
2822
2923 async updateStatus ( date : string , status : DayStatus ) : Promise < SingleDayEntry > {
24+ const auth = useAuthStore ( )
3025 try {
31- return await updateDayStatus ( date , status , this . token ?? undefined ) ;
26+ return await updateDayStatus ( date , status , auth . token ?? undefined ) ;
3227 } catch ( e ) {
3328 console . error ( `Failed to update day status for day ${ date } ` , e ) ;
3429 throw e ;
You can’t perform that action at this time.
0 commit comments