/** * Workspace page data queries: everything the page frame loads per render * (identity, space lists, nav lists, recent messages, repo tags). Space * mutations live in features/space-management; user-account mutations in * features/user-settings. */ import Apis from '@/shared/api' import { unwrapApi, type ApiEnvelope } from '@/shared/lib' import type { BoardItem, DmItem, Me, MySpace, RepoItem, RoomBrief, TagItem, } from './workspace' export const fetchMe = () => unwrapApi(Apis.account.me()) export const fetchMySpaces = () => unwrapApi(Apis.user.my_spaces({ params: {} })) export const fetchSpaceRooms = (spaceName: string) => unwrapApi(Apis.chat.list_space_rooms({ pathParams: { space_name: spaceName } })) export const fetchDms = () => unwrapApi<{ items: DmItem[] }>(Apis.chat.list_dms({ params: { limit: 50 } })).then(p => p?.items ?? []) export const fetchSpaceRepos = (spaceName: string) => unwrapApi<{ items: RepoItem[] }>( Apis.repos.list_repos({ pathParams: { space_name: spaceName }, params: { limit: 50 } }), ).then(p => p?.items ?? []) // `list_boards` is typed against the generic `Page` schema; items are `BoardDto`. export const fetchSpaceBoards = (spaceName: string) => unwrapApi<{ items: BoardItem[] }>( Apis.issues.list_boards({ pathParams: { space_name: spaceName }, params: { limit: 50 }, }) as unknown as PromiseLike>, ).then(p => p?.items ?? []) /** First page of tag names for the repo toolbar chip. */ export const fetchTags = (spaceName: string, repoName: string) => unwrapApi<{ items: TagItem[] }>( Apis.tags.list_tags({ pathParams: { space_name: spaceName, repo_name: repoName }, params: { limit: 10 }, }), ).then(p => p?.items ?? [])