-
Notifications
You must be signed in to change notification settings - Fork 2
Problem History #39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Elscrux
wants to merge
24
commits into
develop
Choose a base branch
from
feat/history
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Problem History #39
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
e53a0e9
Remove logical expression parsing
Elscrux 9341dcd
Remove negated variable token and use separate tokens for negate and …
Elscrux 60085dc
Add more logical expression validations
Elscrux 5d550c8
Refactor text synchronization
Elscrux 820b1f5
Add fetchSolution API call
Elscrux 6b52dd6
Add history
Elscrux a220fbc
Give the ListItem key a proper value
Elscrux 23b0da7
Add tooltip to be able to see the full text for long problems
Elscrux 4d6fbe0
Add load spinner for loading solutions too
Elscrux 59786da
Add cookie library
Elscrux dcc7725
Add cookie to store history
Elscrux 98bc3c2
Fix using wrong variable for MaxCut text
Elscrux 297877a
Use different cookies for different problem types and useEffect loop
Elscrux ce58623
Don't try to load an existing solution when clicking then Go button
Elscrux 7b723a0
Revert "Add cookie library"
Elscrux 4e254b8
Replace cookie approach with local storage
Elscrux 1af6a83
Reduce History api to one function onRequestRollback
Elscrux b1d51b2
Rename content to problemInput
Elscrux a516efc
Rename setText to onTextChanged
Elscrux fb71ba4
Extract history storage to own file
Elscrux 3be04be
Rename getSolution to startSolving
Elscrux 53e60be
Rename ProblemTypeSolutionId to SolutionIds
Elscrux 2f5b411
Remove code that is commented out
Elscrux de8cfb8
Remove unused import
Elscrux File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { | ||
Button, | ||
Divider, | ||
Heading, | ||
List, | ||
ListItem, | ||
Stack, | ||
Tooltip, | ||
} from "@chakra-ui/react"; | ||
import { ProblemState } from "./HistoryStorage"; | ||
|
||
interface HistoryProps<T> { | ||
problemStates: ProblemState<T>[]; | ||
|
||
onRequestRollback: (problemState: ProblemState<T>) => void; | ||
} | ||
|
||
export const History = <T extends {}>(props: HistoryProps<T>) => { | ||
if (props.problemStates.length == 0) return null; | ||
|
||
function reloadState(state: ProblemState<T>) { | ||
props.onRequestRollback(state); | ||
} | ||
|
||
return ( | ||
<Stack> | ||
<Heading as="h3" size="md" textAlign="center"> | ||
History | ||
</Heading> | ||
<List> | ||
{props.problemStates.map((x) => { | ||
let problemString = x.problemInput.toString(); | ||
return ( | ||
<ListItem key={problemString}> | ||
<Tooltip label={problemString}> | ||
<Button | ||
width="200px" | ||
overflow="hidden" | ||
variant="link" | ||
onClick={(_) => reloadState(x)} | ||
> | ||
{problemString} | ||
</Button> | ||
</Tooltip> | ||
<Divider /> | ||
</ListItem> | ||
); | ||
})} | ||
</List> | ||
</Stack> | ||
); | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { SolutionIds } from "./ProgressHandler"; | ||
|
||
export interface ProblemState<T> { | ||
/** | ||
* Problem input | ||
*/ | ||
problemInput: T; | ||
/** | ||
* Ids of the solutions of the problem input per problem type | ||
*/ | ||
solutionIds: SolutionIds; | ||
} | ||
|
||
export function getHistory<T>(problemTypes: string[]): ProblemState<T>[] { | ||
let historyItem = localStorage.getItem(getStoreId(problemTypes)); | ||
if (historyItem === null) return []; | ||
|
||
return JSON.parse(historyItem); | ||
} | ||
|
||
export function storeHistory<T>( | ||
problemTypes: string[], | ||
history: ProblemState<T>[] | ||
) { | ||
localStorage.setItem(getStoreId(problemTypes), JSON.stringify(history)); | ||
} | ||
|
||
export function getStoreId(problemTypes: string[]) { | ||
return `problemStates-${problemTypes}`; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,21 @@ | ||
import { Divider, Text, Textarea } from "@chakra-ui/react"; | ||
import { Divider, Textarea } from "@chakra-ui/react"; | ||
import Head from "next/head"; | ||
import React, { ReactElement, useState } from "react"; | ||
import { ReactElement, useState } from "react"; | ||
import { Container } from "../Container"; | ||
import { Main } from "../Main"; | ||
import { Help } from "./SAT/Help"; | ||
import { EditorControls } from "./EditorControls"; | ||
|
||
export interface TextInputMaskProperties { | ||
textPlaceholder: string; | ||
onTextChanged: (text: string) => void; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why did you rename this? passing events is much more conventional than passing setters in react There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't remember. I changed it back. |
||
text: string; | ||
onTextChanged: (value: string) => void; | ||
body?: ReactElement; | ||
} | ||
|
||
export const TextInputMask = (props: TextInputMaskProperties) => { | ||
const [text, setText] = useState<string>(""); | ||
const [errorString, setErrorString] = useState(""); | ||
|
||
function onTextChanged(text: string): void { | ||
try { | ||
setText(text); | ||
props.onTextChanged(text); | ||
|
||
setErrorString(""); | ||
|
@@ -40,11 +37,11 @@ export const TextInputMask = (props: TextInputMaskProperties) => { | |
errorText={errorString} | ||
idleText={props.textPlaceholder + " 👇"} | ||
onUpload={onTextChanged} | ||
editorContent={text} | ||
editorContent={props.text} | ||
/> | ||
<Textarea | ||
placeholder={props.textPlaceholder} | ||
value={text} | ||
value={props.text} | ||
minHeight="10rem" | ||
isInvalid={errorString != ""} | ||
onChange={(x) => onTextChanged(x.target.value)} | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code seems to throw a preflight CORS error when a solution is clicked
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed by this toolbox PR that I forgot to make
ProvideQ/toolbox-server#67