mirror of
https://github.com/spacedriveapp/spacedrive
synced 2024-07-14 08:54:04 +00:00
fetch library list alongside retrieving cache (#2162)
This commit is contained in:
parent
68ca2382fd
commit
267cc9c97a
|
@ -42,6 +42,15 @@ export const useCachedLibraries = () => {
|
||||||
export async function getCachedLibraries(cache: NormalisedCache, client: AlphaClient<Procedures>) {
|
export async function getCachedLibraries(cache: NormalisedCache, client: AlphaClient<Procedures>) {
|
||||||
const cachedData = localStorage.getItem(libraryCacheLocalStorageKey);
|
const cachedData = localStorage.getItem(libraryCacheLocalStorageKey);
|
||||||
|
|
||||||
|
const libraries = client.query(['library.list']).then(result => {
|
||||||
|
cache.withNodes(result.nodes);
|
||||||
|
const libraries = cache.withCache(result.items);
|
||||||
|
|
||||||
|
localStorage.setItem(libraryCacheLocalStorageKey, JSON.stringify(result));
|
||||||
|
|
||||||
|
return libraries;
|
||||||
|
});
|
||||||
|
|
||||||
if (cachedData) {
|
if (cachedData) {
|
||||||
// If we fail to load cached data, it's fine
|
// If we fail to load cached data, it's fine
|
||||||
try {
|
try {
|
||||||
|
@ -53,14 +62,8 @@ export async function getCachedLibraries(cache: NormalisedCache, client: AlphaCl
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = await client.query(['library.list']);
|
|
||||||
cache.withNodes(result.nodes);
|
|
||||||
const libraries = cache.withCache(result.items);
|
|
||||||
|
|
||||||
if (result.items.length > 0 || result.nodes.length > 0)
|
return await libraries;
|
||||||
localStorage.setItem(libraryCacheLocalStorageKey, JSON.stringify(result));
|
|
||||||
|
|
||||||
return libraries;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ClientContext {
|
export interface ClientContext {
|
||||||
|
|
Loading…
Reference in a new issue