forked from FoundKeyGang/FoundKey
client: return themes when fetching them
This commit is contained in:
parent
79a9b04d25
commit
ae0a7b668f
1 changed files with 6 additions and 5 deletions
|
@ -8,21 +8,22 @@ export function getThemes(): Theme[] {
|
||||||
return JSON.parse(localStorage.getItem(lsCacheKey) || '[]');
|
return JSON.parse(localStorage.getItem(lsCacheKey) || '[]');
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function fetchThemes(): Promise<void> {
|
export async function fetchThemes(): Promise<Theme[]> {
|
||||||
if ($i == null) return;
|
if ($i == null) return [];
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const themes = await api('i/registry/get', { scope: ['client'], key: 'themes' });
|
const themes = await api('i/registry/get', { scope: ['client'], key: 'themes' });
|
||||||
localStorage.setItem(lsCacheKey, JSON.stringify(themes));
|
localStorage.setItem(lsCacheKey, JSON.stringify(themes));
|
||||||
|
return themes;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (err.code === 'NO_SUCH_KEY') return;
|
if (err.code === 'NO_SUCH_KEY') return [];
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function addTheme(theme: Theme): Promise<void> {
|
export async function addTheme(theme: Theme): Promise<void> {
|
||||||
await fetchThemes();
|
const themes = await fetchThemes()
|
||||||
const themes = getThemes().concat(theme);
|
.then(themes => themes.concat(theme));
|
||||||
await api('i/registry/set', { scope: ['client'], key: 'themes', value: themes });
|
await api('i/registry/set', { scope: ['client'], key: 'themes', value: themes });
|
||||||
localStorage.setItem(lsCacheKey, JSON.stringify(themes));
|
localStorage.setItem(lsCacheKey, JSON.stringify(themes));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue