mirror of
https://github.com/Elysola/WebHooker.git
synced 2026-11-21 01:23:40 +00:00
feat(console): give each group its own routes URL
Resolve the selected group from /admin/groups/{groupId}, validate console paths, and use browser history for back navigation. Keep Groups active and let an active mobile-tab tap return to the list. Scope pending route loads to their group and retain the count beside long headings.
This commit is contained in:
1 parent
ba95456e67
commit
535bfa98ce
11 files changed
+249
-63
No files matched your search
@@ -5,30 +5,70 @@ export function useGroupRoutesApi() {
|
||||
const routes = ref<Route[]>([]);
|
||||
const loading = ref(false);
|
||||
const error = ref("");
|
||||
/** Group whose routes are shown; responses for any other group are dropped. */
|
||||
const groupId = ref<string | null>(null);
|
||||
/** Group whose routes were last loaded (or saved) successfully. */
|
||||
const loadedId = ref<string | null>(null);
|
||||
// Bumped by every load/clear, so only the latest request may land.
|
||||
let request = 0;
|
||||
|
||||
async function load(groupId: string): Promise<void> {
|
||||
/**
|
||||
* The shown routes are the group's real routes. Saving replaces a group's
|
||||
* whole route list, so a write is only safe from here — never from the
|
||||
* empty list of a load still running or one that failed.
|
||||
*/
|
||||
const ready = computed(() => !!groupId.value && loadedId.value === groupId.value && !error.value);
|
||||
|
||||
async function load(id: string): Promise<void> {
|
||||
const mine = ++request;
|
||||
if (groupId.value !== id) {
|
||||
routes.value = [];
|
||||
loadedId.value = null;
|
||||
}
|
||||
groupId.value = id;
|
||||
loading.value = true;
|
||||
error.value = "";
|
||||
needLogin.value = false;
|
||||
try {
|
||||
const data = await apiFetch<{ routes?: Route[] }>(
|
||||
`/admin/api/groups/${encodeURIComponent(groupId)}/routes`,
|
||||
`/admin/api/groups/${encodeURIComponent(id)}/routes`,
|
||||
);
|
||||
if (mine !== request) return;
|
||||
routes.value = data.routes ?? [];
|
||||
loadedId.value = id;
|
||||
} 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;
|
||||
}
|
||||
}
|
||||
|
||||
async function save(groupId: string, next: Route[]): Promise<void> {
|
||||
await apiFetch(`/admin/api/groups/${encodeURIComponent(groupId)}/routes`, {
|
||||
/** Forget the shown group (its page was left); late responses are ignored. */
|
||||
function clear(): void {
|
||||
request++;
|
||||
groupId.value = null;
|
||||
loadedId.value = null;
|
||||
routes.value = [];
|
||||
loading.value = false;
|
||||
error.value = "";
|
||||
}
|
||||
|
||||
async function save(id: string, next: Route[]): Promise<void> {
|
||||
await apiFetch(`/admin/api/groups/${encodeURIComponent(id)}/routes`, {
|
||||
method: "PUT",
|
||||
body: JSON.stringify({ routes: next }),
|
||||
});
|
||||
// The page may have moved on to another group while the request ran.
|
||||
if (groupId.value !== id) return;
|
||||
// What was just written is the newest state: a load of this group that
|
||||
// started earlier may return the old routes, so it must not land.
|
||||
request++;
|
||||
loading.value = false;
|
||||
error.value = "";
|
||||
routes.value = next;
|
||||
loadedId.value = id;
|
||||
}
|
||||
|
||||
return { routes, loading, needLogin, error, load, save };
|
||||
return { routes, loading, needLogin, error, groupId, ready, load, clear, save };
|
||||
}
|
||||
Reference in new issue
Block a user