mirror of
https://github.com/HangarMC/Hangar.git
synced 2024-11-27 06:01:08 +08:00
Load org visibility along with other user data in parallel
This commit is contained in:
parent
94a0ba6f0b
commit
46cd1bf871
@ -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));
|
||||
|
@ -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],
|
||||
};
|
||||
})
|
||||
);
|
||||
|
@ -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();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user