first commit
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
import { Injectable, signal } from '@angular/core';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { Observable } from 'rxjs';
|
||||
import { tap } from 'rxjs/operators';
|
||||
import type { AuthUser } from './auth.service';
|
||||
|
||||
export interface UserPreferences {
|
||||
language?: string | null;
|
||||
defaultProvider?: string | null;
|
||||
theme?: 'light' | 'dark' | 'black' | 'system' | string | null;
|
||||
videoQuality?: string | null;
|
||||
region?: string | null;
|
||||
version?: number | null;
|
||||
}
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class UserService {
|
||||
private _preferences = signal<UserPreferences | null>(null);
|
||||
|
||||
constructor(private http: HttpClient) {}
|
||||
|
||||
preferences() {
|
||||
return this._preferences();
|
||||
}
|
||||
|
||||
loadPreferences(): Observable<UserPreferences> {
|
||||
return this.http.get<UserPreferences>('/proxy/api/user/preferences', { withCredentials: true }).pipe(
|
||||
tap(p => this._preferences.set(p || {}))
|
||||
);
|
||||
}
|
||||
|
||||
updatePreferences(patch: Partial<UserPreferences>): Observable<UserPreferences> {
|
||||
return this.http.patch<UserPreferences>('/proxy/api/user/preferences', patch, { withCredentials: true }).pipe(
|
||||
tap(p => this._preferences.set(p || {}))
|
||||
);
|
||||
}
|
||||
|
||||
loadMe(): Observable<AuthUser> {
|
||||
return this.http.get<AuthUser>('/proxy/api/user/me', { withCredentials: true });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user