main
import {
getBoard,
type IssueQuery,
listIssues,
listLabels,
listMilestones,
listSpaceMembers,
} from '@app/domains/issues/model'
import { boardKey, prefetch, spaceMembersPageKey } from '@app/lib'
import { ISSUE_PAGE_SIZE } from './use-board-data'
/**
* The query a board mounts with (board-location defaults: state `open`, sort
* `created`, page 1). Field order matters — `useBoardData` derives its cache
* key from `JSON.stringify(query)`, so this literal must produce the exact
* same string as the board view's.
*/
const DEFAULT_QUERY: IssueQuery = {
state: 'open',
q: undefined,
priorities: undefined,
labelIds: undefined,
milestoneIds: undefined,
assigneeIds: undefined,
sort: 'created',
limit: ISSUE_PAGE_SIZE,
offset: 0,
}
/** Hover prefetch for the board column: everything `useBoardData` loads. */
export function prefetchBoardView(space: string, board: string): void {
if (!space || !board) return
const ref = { space, board }
void prefetch(boardKey(space, board, 'board'), () => getBoard(ref))
void prefetch(boardKey(space, board, 'labels'), () => listLabels(ref))
void prefetch(boardKey(space, board, 'milestones'), () => listMilestones(ref))
void prefetch(boardKey(space, board, `issues:${JSON.stringify(DEFAULT_QUERY)}`), () => listIssues(ref, DEFAULT_QUERY))
void prefetch(spaceMembersPageKey(space), () => listSpaceMembers(space))
}