Something went wrong. Try again.
Mirror of https://github.com/improsocial/improAn extensible Bluesky client for web
Something went wrong. Try again.
JavaScript
123456789101112131415161718192021222324252627282930313233343536373839404142import { Preferences } from "/js/preferences.js";import { Signal } from "/js/signals.js";
export class PreferencesProvider { constructor(api) { this.api = api; this._preferences = null; this.$preferences = new Signal.State(null); }
requirePreferences() { if (!this._preferences) { throw new Error("Preferences not loaded"); } return this._preferences; }
async fetchPreferences() { if (!this.api.isAuthenticated) { this._setPreferences(Preferences.createLoggedOutPreferences()); return; } const preferencesObj = await this.api.getPreferences(); const labelerDids = Preferences.getLabelerDidsFromPreferences(preferencesObj); const labelerDefs = await this.api.getLabelers(labelerDids); this._setPreferences(new Preferences(preferencesObj, labelerDefs)); }
async updatePreferences(preferences) { if (preferences.persist) { await this.api.updatePreferences(preferences.obj); } this._setPreferences(preferences); }
_setPreferences(preferences) { this._preferences = preferences; this.$preferences.set(preferences); }}