1+ /** biome-ignore-all lint/complexity/noBannedTypes: Needed to define union types */
12import { useMutation , useQuery } from "@tanstack/react-query" ;
23import { useSubscription } from "@trpc/tanstack-react-query" ;
34import { useEffect , useRef , useState } from "react" ;
@@ -19,12 +20,12 @@ export interface QuestionVotingData {
1920
2021export type VotingPageState = GetStatesUnion < typeof VotingPageState . enum > ;
2122export const VotingPageState = makeStates ( "vps" , {
22- loading : state ( ) ,
23- waiting : state ( ) ,
24- ended : state ( ) ,
23+ loading : state < { } > ( ) ,
24+ waiting : state < { } > ( ) ,
25+ ended : state < { } > ( ) ,
2526 viewingResults : state < ShowingResultsState > ( ) ,
2627 voting : state < QuestionVotingData > ( ) ,
27- kicked : state ( ) ,
28+ kicked : state < { } > ( ) ,
2829} ) ;
2930
3031interface LastVote {
@@ -39,15 +40,20 @@ export function useVoterState(props: {
3940 const [ lastVote , setLastVote ] = useState < LastVote | null > ( null ) ;
4041 const voteLock = useRef < Promise < void > > ( Promise . resolve ( ) ) ;
4142
42- const castVoteMutation = useMutation ( trpc . vote . castVote . mutationOptions ( ) )
43+ const castVoteMutation = useMutation ( trpc . vote . castVote . mutationOptions ( ) ) ;
4344
4445 const runSyncAsync = async ( fn : ( ) => Promise < void > ) => {
45- const promise = voteLock . current . catch ( ( ) => { } ) . then ( fn ) ;
46+ const promise = voteLock . current . catch ( ( ) => { } ) . then ( fn ) ;
4647 voteLock . current = promise ;
4748 await promise ;
4849 } ;
4950
50- const subscription = useSubscription ( trpc . vote . listen . subscriptionOptions ( { roomId : props . roomId , votingKey : props . votingKey } ) )
51+ const subscription = useSubscription (
52+ trpc . vote . listen . subscriptionOptions ( {
53+ roomId : props . roomId ,
54+ votingKey : props . votingKey ,
55+ } ) ,
56+ ) ;
5157
5258 const { isInitialVoteLoading } = useFetchInitialVote (
5359 props ,
@@ -100,10 +106,10 @@ export function useVoterState(props: {
100106
101107type InitialVoteFetchState = GetStatesUnion < typeof InitialVoteFetchState . enum > ;
102108const InitialVoteFetchState = makeStates ( "ivfs" , {
103- waitingForVoterState : state ( ) ,
104- ignoring : state ( ) ,
109+ waitingForVoterState : state < { } > ( ) ,
110+ ignoring : state < { } > ( ) ,
105111 fetching : state < { questionId : string } > ( ) ,
106- fetched : state ( ) ,
112+ fetched : state < { } > ( ) ,
107113} ) ;
108114
109115/**
@@ -122,17 +128,22 @@ function useFetchInitialVote(
122128 InitialVoteFetchState . waitingForVoterState ( { } ) ,
123129 ) ;
124130
125- const initialVoteQuery = useQuery ( trpc . vote . getMyVote . queryOptions ( {
126- roomId : props . roomId ,
127- votingKey : props . votingKey ,
128-
129- // If we're not fetching, then the query is disabled anyway and this arg doesnt matter
130- questionId : InitialVoteFetchState . is . fetching ( fetchState )
131- ? fetchState . questionId
132- : "" ,
133- } , {
134- enabled : InitialVoteFetchState . is . fetching ( fetchState ) ,
135- } ) )
131+ const initialVoteQuery = useQuery (
132+ trpc . vote . getMyVote . queryOptions (
133+ {
134+ roomId : props . roomId ,
135+ votingKey : props . votingKey ,
136+
137+ // If we're not fetching, then the query is disabled anyway and this arg doesnt matter
138+ questionId : InitialVoteFetchState . is . fetching ( fetchState )
139+ ? fetchState . questionId
140+ : "" ,
141+ } ,
142+ {
143+ enabled : InitialVoteFetchState . is . fetching ( fetchState ) ,
144+ } ,
145+ ) ,
146+ ) ;
136147
137148 useEffect ( ( ) => {
138149 if (
0 commit comments