Skip to content

Commit

Permalink
fix: don't freeze on falsesy values in useData
Browse files Browse the repository at this point in the history
  • Loading branch information
MiniDigger committed Aug 17, 2024
1 parent 66aa4a4 commit 96525ac
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
3 changes: 2 additions & 1 deletion frontend/src/composables/useData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ import type {
SettingsResponse,
User,
VersionInfo,
Platform } from "~/types/backend";
Platform,
} from "~/types/backend";

export function useOrganizationVisibility(user: () => string) {
const { data: organizationVisibility, status: organizationVisibilityStatus } = useData(
Expand Down
14 changes: 9 additions & 5 deletions frontend/src/composables/useDataLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ export function useData<T, P extends Record<string, unknown> | string>(
let promise: Promise<void> | undefined;

function refresh() {
console.log("refresh", key(params()));
return load(params());
}

Expand All @@ -103,16 +104,18 @@ export function useData<T, P extends Record<string, unknown> | string>(
// eslint-disable-next-line no-async-promise-executor
return new Promise<void>(async (resolve, reject) => {
console.log("load", key(params));
const result = await loader(params).catch(reject);
// await new Promise((resolve) => setTimeout(resolve, 5000));
console.log("loaded", key(params));
if (result) {
try {
const result = await loader(params);
// await new Promise((resolve) => setTimeout(resolve, 5000));
console.log("loaded", key(params));
setState(result);
status.value = "success";
callback(params);
resolve();
} else {
} catch (err) {
status.value = "error";
callback(params);
reject(err);
}
});
}
Expand All @@ -128,6 +131,7 @@ export function useData<T, P extends Record<string, unknown> | string>(
onServerPrefetch(async () => {
console.log("server prefetch", key(params()));
await promise;
console.log("server prefetch done", key(params()));
});
}
}
Expand Down

0 comments on commit 96525ac

Please sign in to comment.