Skip to content

Commit

Permalink
working prototype
Browse files Browse the repository at this point in the history
  • Loading branch information
jthrilly committed Oct 12, 2023
1 parent 7004ee9 commit be03ff9
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions providers/InterviewProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use client';

import { createContext, useContext, useEffect } from 'react';
import { createContext, useContext, useEffect, useState } from 'react';
import type {
NcEdge,
NcNetwork,
Expand Down Expand Up @@ -48,14 +48,13 @@ function InterviewProvider({
'stage',
parseAsInteger.withDefault(1),
);
const [initialized, setInitialized] = useState(false);
const { network, networkHandlers } = useNetwork(initialNetwork);
const { mutate: updateNetwork } = trpc.interview.updateNetwork.useMutation();

const protocolStageCount = protocol?.stages.length;
const stageConfig = protocol.stages[currentStage - 1]!;

const { network, networkHandlers } = useNetwork(initialNetwork);

const { mutate: updateNetwork } = trpc.interview.updateNetwork.useMutation();

const navigationHandlers = {
nextPage: () => {
const nextStage = currentStage + 1;
Expand All @@ -78,9 +77,14 @@ function InterviewProvider({

// When state changes, sync it with the server using react query
useEffect(() => {
// updateNetwork({ interviewId, network });
if (!initialized) {
setInitialized(true);
return;
}

updateNetwork({ interviewId, network });
console.log('network changed', network);
}, [network]);
}, [network, updateNetwork, initialized, interviewId]);

return (
<InterviewContext.Provider
Expand Down

0 comments on commit be03ff9

Please sign in to comment.