diff --git a/src/components/NextProblem.js b/src/components/NextProblem.js index da53acf..d739828 100644 --- a/src/components/NextProblem.js +++ b/src/components/NextProblem.js @@ -7,8 +7,8 @@ import { useMutation } from "@apollo/react-hooks"; import { gql } from "apollo-boost"; const PROBLEM_COMPLETED = gql` - mutation ProblemCompleted($width: Int!, $height: Int!) { - next: problemCompleted(width: $width, height: $height) @client { + mutation ProblemCompleted($problemSpec: ProblemSpec) { + next: problemCompleted(problemSpec: $problemSpec) @client { gridSpec teamsSpec } @@ -29,9 +29,16 @@ export const NextProblem = observer(() => { function startLoading() { setLoading(true); const problem = store.toProblem(); - const { width, height } = problem.grid; + const problemSpec = { + gridSpec: problem.grid.toVersion2Format(), + teamsSpec: problem.teams.toVersion1Format(), + }; setTimeout(() => { - problemCompleted({ variables: { width, height } }); + problemCompleted({ + variables: { + problemSpec, + }, + }); }, fakeDelay); } diff --git a/src/model/contexts.js b/src/model/contexts.js index 284f403..c86f316 100644 --- a/src/model/contexts.js +++ b/src/model/contexts.js @@ -6,6 +6,7 @@ import { randomEasyProblem, randomHardProblem, randomProblemWithGridSize, + parseProblemFrom, } from "../model/problem"; import {} from "../model/problem.js"; import { loader } from "graphql.macro"; @@ -58,12 +59,18 @@ export const GraphQLProvider = ({ children }) => { }, Mutation: { problemCompleted: (_root, args, _context, _info) => { - const { width, height } = args; - const problem = randomProblemWithGridSize(width, height); + const { + problemSpec: { gridSpec, teamsSpec }, + } = args; + const completedProblem = parseProblemFrom(gridSpec, teamsSpec); + const nextProblem = randomProblemWithGridSize( + completedProblem.grid.width, + completedProblem.grid.height + ); return { __typename: "ProblemSpec", - gridSpec: problem.grid.toVersion2Format(), - teamsSpec: problem.teams.toVersion1Format(), + gridSpec: nextProblem.grid.toVersion2Format(), + teamsSpec: nextProblem.teams.toVersion1Format(), }; }, }, diff --git a/src/model/types.graphql b/src/model/types.graphql index 29418dd..b131673 100644 --- a/src/model/types.graphql +++ b/src/model/types.graphql @@ -1,5 +1,6 @@ type Query { current_user: User! + recently_completed(limit: Int!): [ProblemSpec] } type User { @@ -18,5 +19,5 @@ type ProblemLink { } type Mutation { - problemCompleted(width: Int!, height: Int!): ProblemSpec! + problemCompleted(problemSpec: ProblemSpec): ProblemSpec! }