mirror of
https://github.com/Elysola/WebHooker.git
synced 2026-11-21 01:23:40 +00:00
fix(console-data): discard superseded load responses
Only the latest request may update a list, its error or loading state. Invalidate pending group loads after a save so an older response cannot restore stale configuration during persistent-console navigation.
This commit is contained in:
1 parent
de84155e09
commit
05d025ef9c
4 files changed
+34
-11
No files matched your search
@@ -10,6 +10,9 @@ export function useGroupsApi() {
|
||||
const error = ref("");
|
||||
/** A load has succeeded: an id missing from `groups` really is unknown. */
|
||||
const loaded = ref(false);
|
||||
// Bumped by every load and save, so only the latest request may land: a
|
||||
// load that started before a save must not bring back the old groups.
|
||||
let request = 0;
|
||||
|
||||
function roleOf(groupId: string): GroupRole | undefined {
|
||||
return isSuper.value ? "owner" : roles.value[groupId];
|
||||
@@ -26,6 +29,7 @@ export function useGroupsApi() {
|
||||
}
|
||||
|
||||
async function load(): Promise<void> {
|
||||
const mine = ++request;
|
||||
loading.value = true;
|
||||
error.value = "";
|
||||
needLogin.value = false;
|
||||
@@ -35,14 +39,16 @@ export function useGroupsApi() {
|
||||
isSuper?: boolean;
|
||||
roles?: Record<string, GroupRole>;
|
||||
}>("/admin/api/groups");
|
||||
if (mine !== request) return;
|
||||
groups.value = data.groups ?? [];
|
||||
isSuper.value = data.isSuper ?? false;
|
||||
roles.value = data.roles ?? {};
|
||||
loaded.value = true;
|
||||
} catch (err) {
|
||||
if (!needLogin.value) error.value = err instanceof Error ? err.message : String(err);
|
||||
if (mine === request && !needLogin.value)
|
||||
error.value = err instanceof Error ? err.message : String(err);
|
||||
} finally {
|
||||
loading.value = false;
|
||||
if (mine === request) loading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,6 +57,8 @@ export function useGroupsApi() {
|
||||
method: "PUT",
|
||||
body: JSON.stringify({ groups: next }),
|
||||
});
|
||||
request++;
|
||||
loading.value = false;
|
||||
groups.value = next;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user