Load org visibility along with other user data in parallel

This commit is contained in:
Nassim Jahnke 2023-04-29 13:22:12 +02:00
parent 94a0ba6f0b
commit 46cd1bf871
No known key found for this signature in database
GPG Key ID: 6BE3B555EBC5982B
3 changed files with 10 additions and 5 deletions

View File

@ -25,6 +25,10 @@ const internalVisibility = computed({
});
async function changeOrgVisibility(org: string) {
if (loading.value) {
return;
}
loading.value = true;
const hidden = internalVisibility.value[org];
await useInternalApi(`organizations/${org}/userOrganizationsVisibility?hidden=${hidden}`, "post").catch((e) => handleRequestError(e));

View File

@ -24,6 +24,7 @@ import { NuxtApp } from "@nuxt/schema";
import { useApi, useInternalApi } from "~/composables/useApi";
import { ref, useAsyncData, createError } from "#imports";
import { handleRequestError } from "~/composables/useErrorHandling";
import { useAuthStore } from "~/store/auth";
export type NonNullAsyncData<T, E = unknown> = { data: Ref<T> } & Pick<AsyncData<T, E>, "pending" | "refresh" | "execute" | "error">;
@ -180,8 +181,10 @@ export async function useUserData(
projects: PaginatedResult<Project>;
organizations: { [key: string]: OrganizationRoleTable };
pinned: ProjectCompact[];
organizationVisibility: { [key: string]: boolean } | null;
} | null>
> {
const self = user === useAuthStore().user?.name;
return extract(
await useAsyncData("useUserData:" + user, async () => {
// noinspection ES6MissingAwait
@ -194,6 +197,7 @@ export async function useUserData(
}),
useInternalApi<{ [key: string]: RoleTable }>(`organizations/${user}/userOrganizations`),
useApi<ProjectCompact[]>(`users/${user}/pinned`),
self ? useOrgVisibility(user) : null,
]);
return {
starred: data[0] as PaginatedResult<ProjectCompact>,
@ -201,6 +205,7 @@ export async function useUserData(
projects: data[2] as PaginatedResult<Project>,
organizations: data[3] as { [key: string]: OrganizationRoleTable },
pinned: data[4] as ProjectCompact[],
organizationVisibility: data[5],
};
})
);

View File

@ -71,12 +71,8 @@ const requestParams = computed(() => {
});
const userData = await useUserData(props.user.name, requestParams.value);
const { starred, watching, organizations, pinned } = userData.value || { starred: null };
const { starred, watching, organizations, pinned, organizationVisibility } = userData.value || { starred: null };
const projects = ref(userData.value?.projects);
let organizationVisibility = null;
if (props.user.name === useAuthStore().user?.name) {
organizationVisibility = await useOrgVisibility(props.user.name);
}
const orgRoles = useBackendData.orgRoles.filter((role) => role.assignable);
const authStore = useAuthStore();