mirror of
https://github.com/spacedriveapp/spacedrive
synced 2024-07-04 12:13:27 +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>) {
|
||||
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 we fail to load cached data, it's fine
|
||||
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)
|
||||
localStorage.setItem(libraryCacheLocalStorageKey, JSON.stringify(result));
|
||||
|
||||
return libraries;
|
||||
return await libraries;
|
||||
}
|
||||
|
||||
export interface ClientContext {
|
||||
|
|
Loading…
Reference in a new issue