diff --git a/frontend-new/src/composables/useApiHelper.ts b/frontend-new/src/composables/useApiHelper.ts index 72e95effa..b93df6089 100644 --- a/frontend-new/src/composables/useApiHelper.ts +++ b/frontend-new/src/composables/useApiHelper.ts @@ -1,7 +1,18 @@ import { useApi, useInternalApi } from "~/composables/useApi"; -import { PaginatedResult, Project, User } from "hangar-api"; +import { PaginatedResult, Project, ProjectCompact, Role, User } from "hangar-api"; import { useInitialState } from "~/composables/useInitialState"; -import { Flag, HangarNotification, HangarProject, HealthReport, Invites, LoggedAction, Note, ProjectChannel, ReviewQueueEntry } from "hangar-internal"; +import { + Flag, + HangarNotification, + HangarProject, + HealthReport, + Invites, + LoggedAction, + Note, + ProjectChannel, + ReviewQueueEntry, + RoleTable, +} from "hangar-internal"; export async function useProjects(pagination = { limit: 25, offset: 0 }, blocking = true) { return useInitialState("useProjects", () => useApi>("projects", false, "get", pagination), blocking); @@ -70,3 +81,35 @@ export async function useVersionApprovals(blocking = true) { blocking ); } + +export async function useOrgVisibility(user: string, blocking = true) { + return useInitialState( + "useOrgVisibility", + () => useInternalApi<{ [key: string]: boolean }>(`organizations/${user}/userOrganizationsVisibility`, true), + blocking + ); +} + +export async function useUserData(user: string, blocking = true) { + return useInitialState( + "useUserData", + async () => { + // noinspection ES6MissingAwait + const data = await Promise.all([ + useApi>(`users/${user}/starred`, false), + useApi>(`users/${user}/watching`, false), + useApi>(`projects`, false, "get", { + owner: user, + }), + useInternalApi<{ [key: string]: RoleTable }>(`organizations/${user}/userOrganizations`, false), + ] as Promise[]); + return { + starred: data[0] as PaginatedResult, + watching: data[1] as PaginatedResult, + projects: data[2] as PaginatedResult, + organizations: data[3] as { [key: string]: RoleTable }, + }; + }, + blocking + ); +} diff --git a/frontend-new/src/pages/[user].vue b/frontend-new/src/pages/[user].vue index ab268ea21..c28613a89 100644 --- a/frontend-new/src/pages/[user].vue +++ b/frontend-new/src/pages/[user].vue @@ -10,10 +10,13 @@ const ctx = useContext(); const i18n = useI18n(); const user = await useUser(useRoute().params.user as string).catch((e) => handleRequestError(e, ctx, i18n)); if (!user) { + // TODO check if user is an org here await useRouter().push(useErrorRedirect(useRoute(), 404, "Not found")); } diff --git a/frontend-new/src/pages/[user]/[project]/versions/[version].vue b/frontend-new/src/pages/[user]/[project]/versions/[version].vue index 90be0eb71..77bd43007 100644 --- a/frontend-new/src/pages/[user]/[project]/versions/[version].vue +++ b/frontend-new/src/pages/[user]/[project]/versions/[version].vue @@ -1,3 +1,4 @@ diff --git a/frontend-new/src/pages/[user]/index.vue b/frontend-new/src/pages/[user]/index.vue index fc62e739c..6db4be97c 100644 --- a/frontend-new/src/pages/[user]/index.vue +++ b/frontend-new/src/pages/[user]/index.vue @@ -1,18 +1,99 @@ diff --git a/frontend-new/src/store/backendData.ts b/frontend-new/src/store/backendData.ts index 548ac8490..2deb2b27c 100644 --- a/frontend-new/src/store/backendData.ts +++ b/frontend-new/src/store/backendData.ts @@ -4,7 +4,7 @@ import { computed, ref } from "vue"; import { IPlatform, IProjectCategory, IPrompt, IVisibility } from "hangar-internal"; import { NamedPermission, Platform, ProjectCategory, Prompt } from "~/types/enums"; -import { Announcement as AnnouncementObject, Announcement, IPermission } from "hangar-api"; +import { Announcement as AnnouncementObject, Announcement, IPermission, Role } from "hangar-api"; import { fetchIfNeeded, useInternalApi } from "~/composables/useApi"; interface Validation { @@ -40,6 +40,7 @@ export const useBackendDataStore = defineStore("backendData", () => { const announcements = ref([]); const visibilities = ref([]); const licenses = ref([]); + const orgRoles = ref([]); async function initBackendData() { try { @@ -79,6 +80,8 @@ export const useBackendDataStore = defineStore("backendData", () => { await fetchIfNeeded(async () => await useInternalApi("data/visibilities", false), visibilities); await fetchIfNeeded(async () => await useInternalApi("data/validations", false), validations); + + await fetchIfNeeded(async () => await useInternalApi("data/orgRoles", false), validations); } catch (e) { console.error("ERROR FETCHING BACKEND DATA"); console.error(e); @@ -97,6 +100,7 @@ export const useBackendDataStore = defineStore("backendData", () => { licenses, announcements, visibilities, + orgRoles, initBackendData, visibleCategories, visiblePlatforms,