Skip to content

Commit

Permalink
Updated state management
Browse files Browse the repository at this point in the history
  • Loading branch information
davenquinn committed Oct 14, 2024
1 parent bb1e51e commit 038dd9d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
23 changes: 19 additions & 4 deletions pages/integrations/xdd/feedback/@sourceTextID/lib/edit-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ type TextRange = {
type TreeAsyncAction = {
type: "save";
tree: TreeData[];
sourceTextID: number;
supersedesRunIDs: number[];
};

type TreeAction =
Expand Down Expand Up @@ -72,7 +74,11 @@ async function treeActionHandler(
switch (action.type) {
case "save":
// Save the tree to the server
const data = prepareDataForServer(action.tree);
const data = prepareDataForServer(
action.tree,
action.sourceTextID,
action.supersedesRunIDs
);
console.log(JSON.stringify(data, null, 2));

return null;
Expand Down Expand Up @@ -329,8 +335,17 @@ function prepareGraphForServer(tree: TreeData[]): GraphData {
return { nodes, edges };
}

function prepareDataForServer(state: TreeData[]): ServerResults {
function prepareDataForServer(
tree: TreeData[],
sourceTextID,
supersedesRunIDs
): ServerResults {
/** This function should be used before sending the data to the server */
const { nodes, edges } = prepareGraphForServer(state);
return { nodes, edges, sourceTextId: 0, supersedesRunIds: null };
const { nodes, edges } = prepareGraphForServer(tree);
return {
nodes,
edges,
sourceTextId: sourceTextID,
supersedesRunIds: supersedesRunIDs ?? [],
};
}
4 changes: 2 additions & 2 deletions pages/integrations/xdd/feedback/@sourceTextID/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ export function FeedbackComponent({
dispatch({
type: "save",
tree,
sourceTextID: sourceID,
runID: runID,
sourceTextID: sourceTextID,
supersedesRunIDs: [runID],
});
},
disabled: state.initialTree == state.tree,
Expand Down

0 comments on commit 038dd9d

Please sign in to comment.