import { queryOptions, useQuery } from "@octanejs/tanstack-query"; import type { InstructionSettings } from "../../../shared/instructions"; import type { CustomerQuerySession } from "../customer-query-session"; import { useCustomerQuerySession } from "../customer-query-provider"; import { callOwner, type SettingsConnection } from "../owner-rpc"; export function instructionOptions( session: CustomerQuerySession, connection: SettingsConnection, ) { return queryOptions({ queryKey: session.key("settings", "instructions"), enabled: !!session.getSnapshot().scope && !!connection?.isReady(), queryFn: ({ signal }) => callOwner( connection, "getInstructionSettings", [], signal, ), }); } export function useInstructionsQuery(connection: SettingsConnection) { const session = useCustomerQuerySession(); return useQuery(instructionOptions(session, connection)); }