add changes
This commit is contained in:
1
chunk-LA37G65K.js
Normal file
1
chunk-LA37G65K.js
Normal file
@@ -0,0 +1 @@
|
||||
import{a as U}from"./chunk-3GOV5KJM.js";import{a as y}from"./chunk-TPLZKWZ7.js";import{b as v}from"./chunk-RC3JXGN6.js";import{a as S}from"./chunk-52JZ5I3Y.js";import{n as f,w as m}from"./chunk-COFYR5MX.js";import{D as d,Ec as n,W as h,_ as b,a as c,da as r,n as g,ta as i}from"./chunk-2MUIW2M6.js";var D=class l{http=r(f);router=r(m);toastService=r(S);authService=r(y);storageService=r(v);API_URL=`${U.apiUrl}/users`;CACHE_TTL=300*1e3;dashboardState=i(null);historyState=i(null);isLoading=i(!1);error=i(null);dashboardCache=new Map;totalQuizzes=n(()=>this.dashboardState()?.data.stats.totalQuizzes||0);overallAccuracy=n(()=>this.dashboardState()?.data.stats.overallAccuracy||0);currentStreak=n(()=>this.dashboardState()?.data.stats.currentStreak||0);getDashboard(t,s=!1){if(!s){let e=this.dashboardCache.get(t);if(e&&Date.now()-e.timestamp<this.CACHE_TTL)return this.dashboardState.set(e.data),g(e.data)}return this.isLoading.set(!0),this.error.set(null),this.http.get(`${this.API_URL}/${t}/dashboard`).pipe(h(e=>{this.dashboardState.set(e),this.dashboardCache.set(t,{data:e,timestamp:Date.now()}),this.isLoading.set(!1)}),d(e=>{throw console.error("Error fetching dashboard:",e),this.error.set(e.error?.message||"Failed to load dashboard"),this.isLoading.set(!1),e.status===401?(this.toastService.error("Please log in to view your dashboard"),this.router.navigate(["/login"])):this.toastService.error("Failed to load dashboard data"),e}))}getHistory(t,s=1,e=10,o,u="date"){this.isLoading.set(!0),this.error.set(null);let p={page:s,limit:e,sortBy:u};return o&&(p.category=o),this.http.get(`${this.API_URL}/${t}/history`,{params:p}).pipe(h(a=>{this.historyState.set(a),this.isLoading.set(!1)}),d(a=>{throw console.error("Error fetching history:",a),this.error.set(a.error?.message||"Failed to load quiz history"),this.isLoading.set(!1),a.status===401?(this.toastService.error("Please log in to view your history"),this.router.navigate(["/login"])):this.toastService.error("Failed to load quiz history"),a}))}updateProfile(t,s){return this.isLoading.set(!0),this.error.set(null),this.http.put(`${this.API_URL}/${t}`,s).pipe(h(e=>{let o=this.authService.getCurrentUser();if(o&&e.data?.user){let u=c(c({},o),e.data.user);this.storageService.setUserData(u)}this.isLoading.set(!1),this.toastService.success("Profile updated successfully"),this.dashboardCache.delete(t)}),d(e=>{throw console.error("Error updating profile:",e),this.error.set(e.error?.message||"Failed to update profile"),this.isLoading.set(!1),e.status===401?this.toastService.error("Please log in to update your profile"):e.status===409?this.toastService.error("Email or username already exists"):this.toastService.error("Failed to update profile"),e}))}clearCache(){this.dashboardCache.clear(),this.dashboardState.set(null),this.historyState.set(null),this.error.set(null)}isDashboardEmpty(){let t=this.dashboardState();return t?t.data.stats.totalQuizzes===0:!0}static \u0275fac=function(s){return new(s||l)};static \u0275prov=b({token:l,factory:l.\u0275fac,providedIn:"root"})};export{D as a};
|
||||
Reference in New Issue
Block a user