-
Notifications
You must be signed in to change notification settings - Fork 6
Pseudocode Response Area (Re-opened) #10
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
HongleiGu
wants to merge
9
commits into
lambda-feedback:main
Choose a base branch
from
lambda-feedback:main
base: main
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
Changes from 7 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
dce9e6b
feat: basic codeMirror setup
HongleiGu 7afeda1
feat: fixed types and folding
HongleiGu c9f3416
feat: checkpointing before doing fastapi for the checkpoint
HongleiGu 91eac9f
fix: better UI and test cases
HongleiGu 22a0a26
Merge branch 'main' into sync
HongleiGu 2c06501
Merge branch 'main' of github.com:lambda-feedback/pseudocode-response…
HongleiGu f41c2aa
Merge branch 'sync' of github.com:lambda-feedback/pseudocode-response…
HongleiGu bce1dff
fix: should fix PR
HongleiGu 3a57244
fix: fix typing issues, add a collapse button for taking a screenshot…
HongleiGu 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,141 @@ | ||
| import { foldGutter, foldService, syntaxHighlighting } from '@codemirror/language'; | ||
| import { EditorState } from '@codemirror/state'; | ||
| import { placeholder } from '@codemirror/view'; | ||
| import { EditorView, basicSetup } from 'codemirror'; | ||
| import { useEffect, useRef, useState } from 'react'; | ||
|
|
||
| import { BaseResponseAreaProps } from '../base-props.type'; | ||
|
|
||
| import { PseudocodeFeedbackPanel } from './components/PseudocodeFeedbackPanel'; | ||
| import { autoIndentAfterColon } from './plugins/autoIndent'; | ||
| import { pseudocodeFoldFunc } from './plugins/fold'; | ||
| import { pseudocodeHighlightStyle } from './plugins/highlight'; | ||
| import { pseudocodeLanguage } from './plugins/language'; | ||
| import { pseudocodeTheme } from './plugins/pseudocode.theme'; | ||
| import { StudentResponse } from './types/input'; | ||
| // import { defaultStudentResponse } from './utils/consts'; | ||
| import { EvaluationResult } from './types/output'; | ||
| import { usePseudocodeStyles } from './utils/styles'; | ||
|
|
||
| type PseudocodeInputProps = Omit<BaseResponseAreaProps, 'handleChange' | 'answer' | 'feedback'> & { | ||
| handleChange: (val: StudentResponse) => void; | ||
| answer?: StudentResponse; // optional, only used for initial load | ||
| // callAPI: () => void; | ||
|
HongleiGu marked this conversation as resolved.
Outdated
|
||
| feedback: EvaluationResult | null; | ||
| }; | ||
|
|
||
| export const PseudocodeInput: React.FC<PseudocodeInputProps> = ({ | ||
| handleChange, | ||
| // callAPI, | ||
| feedback, | ||
| }) => { | ||
| const { classes } = usePseudocodeStyles(); | ||
|
|
||
| // Internal state fully managed in this component | ||
| const [internalAnswer, setInternalAnswer] = useState<StudentResponse>({ | ||
| pseudocode: '', | ||
| time_complexity: '', | ||
| space_complexity: '', | ||
| explanation: '', | ||
| }); | ||
|
|
||
| const editorRef = useRef<HTMLDivElement | null>(null); | ||
| const viewRef = useRef<EditorView | null>(null); | ||
|
|
||
| // Initialize CodeMirror once | ||
| useEffect(() => { | ||
| if (!editorRef.current) return; | ||
|
|
||
| const state = EditorState.create({ | ||
| doc: internalAnswer.pseudocode, | ||
| extensions: [ | ||
| foldGutter(), | ||
| foldService.of(pseudocodeFoldFunc), | ||
| autoIndentAfterColon, | ||
| basicSetup, | ||
| pseudocodeLanguage, | ||
| syntaxHighlighting(pseudocodeHighlightStyle), | ||
| pseudocodeTheme, | ||
| placeholder('Write your pseudocode here...'), | ||
| EditorView.updateListener.of((update) => { | ||
| if (!update.docChanged) return; | ||
| const newCode = update.state.doc.toString(); | ||
| setInternalAnswer((prev) => { | ||
| const updated = { ...prev, pseudocode: newCode }; | ||
| handleChange(updated); // notify parent immediately | ||
| return updated; | ||
| }); | ||
| }), | ||
| EditorView.theme({ | ||
| '&': { height: '100%' }, | ||
| '.cm-scroller': { overflow: 'auto' }, | ||
| }), | ||
| ], | ||
| }); | ||
|
|
||
| const view = new EditorView({ | ||
| state, | ||
| parent: editorRef.current, | ||
| }); | ||
|
|
||
| viewRef.current = view; | ||
| return () => { | ||
| view.destroy(); | ||
| viewRef.current = null; | ||
| }; | ||
| }, []); // only runs once | ||
|
|
||
| // Report change for complexity/explanation fields | ||
| const handleFieldChange = (field: keyof StudentResponse, value: string) => { | ||
| setInternalAnswer((prev) => { | ||
| const updated = { ...prev, [field]: value }; | ||
| handleChange(updated); // immediate update to parent | ||
| return updated; | ||
| }); | ||
| }; | ||
|
|
||
| return ( | ||
| <div className={classes.root}> | ||
| {/* ================= Editor ================= */} | ||
| <div className={classes.editorWrapper}> | ||
| <div ref={editorRef} className={classes.editor} /> | ||
| </div> | ||
|
|
||
| {/* ================= Complexity Inputs ================= */} | ||
| <div className={classes.complexityRow}> | ||
| <input | ||
| className={classes.field} | ||
| value={internalAnswer.time_complexity ?? ''} | ||
| placeholder="Time Complexity (e.g. O(n log n))" | ||
| onChange={(e) => handleFieldChange('time_complexity', e.target.value)} | ||
| /> | ||
| <input | ||
| className={classes.field} | ||
| value={internalAnswer.space_complexity ?? ''} | ||
| placeholder="Space Complexity (e.g. O(n))" | ||
| onChange={(e) => handleFieldChange('space_complexity', e.target.value)} | ||
| /> | ||
| </div> | ||
|
|
||
| {/* ================= Explanation ================= */} | ||
| <textarea | ||
| className={classes.textarea} | ||
| value={internalAnswer.explanation ?? ''} | ||
| placeholder="Explain your reasoning (optional)" | ||
| onChange={(e) => handleFieldChange('explanation', e.target.value)} | ||
| /> | ||
|
|
||
| {/* ================= Action ================= | ||
| <button onClick={callAPI}> | ||
| Check Answer | ||
| </button> */} | ||
|
|
||
| {/* ================= Feedback ================= */} | ||
| {feedback && ( | ||
| <div className={classes.feedbackPanel}> | ||
| <PseudocodeFeedbackPanel result={feedback} /> | ||
| </div> | ||
| )} | ||
| </div> | ||
| ); | ||
| }; | ||
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.
Uh oh!
There was an error while loading. Please reload this page.