client: return themes when fetching them

This commit is contained in:
Johann150 2023-03-18 10:34:25 +01:00
parent 79a9b04d25
commit ae0a7b668f
Signed by untrusted user: Johann150
GPG key ID: 9EE6577A2A06F8F1

View file

@ -8,21 +8,22 @@ export function getThemes(): Theme[] {
return JSON.parse(localStorage.getItem(lsCacheKey) || '[]');
}
export async function fetchThemes(): Promise<void> {
if ($i == null) return;
export async function fetchThemes(): Promise<Theme[]> {
if ($i == null) return [];
try {
const themes = await api('i/registry/get', { scope: ['client'], key: 'themes' });
localStorage.setItem(lsCacheKey, JSON.stringify(themes));
return themes;
} catch (err) {
if (err.code === 'NO_SUCH_KEY') return;
if (err.code === 'NO_SUCH_KEY') return [];
throw err;
}
}
export async function addTheme(theme: Theme): Promise<void> {
await fetchThemes();
const themes = getThemes().concat(theme);
const themes = await fetchThemes()
.then(themes => themes.concat(theme));
await api('i/registry/set', { scope: ['client'], key: 'themes', value: themes });
localStorage.setItem(lsCacheKey, JSON.stringify(themes));
}