-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement stringified custom JSON type for processed handwritin…
…g task answer (#21) * feat: change answers type for maths single answer tasks * feat: wrap onAnswerChange for updating latex * feat: show updated handwriting in ViewOnlyCanvas * feat: display strokes from database in canvas * feat: scroll view-only canvas content into view on change * feat: save app state to db * chore: run formtter * refactor: move display condition out of ViewOnlyCanvas * chore: remove unnecessary styling * refactor: rename excalidraw field to raw * fix: can't render a dialog trigger with nothing inside Co-authored-by: Alexander Biraben-Renard <[email protected]> * Update src/components/questionStructure/Task/variants/HandwritingTask/HandwritingEditor.tsx Co-authored-by: Ivan Procaccini <[email protected]> --------- Co-authored-by: Matthew Alex <[email protected]> Co-authored-by: nick-bolas <[email protected]> Co-authored-by: Kishan Sambhi <[email protected]> Co-authored-by: Illia Derevianko <[email protected]> Co-authored-by: Ivan Procaccini <[email protected]>
- Loading branch information
1 parent
b374904
commit 3d29a0f
Showing
7 changed files
with
75 additions
and
27 deletions.
There are no files selected for viewing
This file contains 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 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
25 changes: 16 additions & 9 deletions
25
src/components/questionStructure/Task/variants/HandwritingTask/ViewOnlyCanvas.tsx
This file contains 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,31 +1,38 @@ | ||
import { Excalidraw } from '@excalidraw/excalidraw' | ||
import { | ||
ExcalidrawImperativeAPI, | ||
ExcalidrawInitialDataState, | ||
} from '@excalidraw/excalidraw/types/types' | ||
import { ExcalidrawElement } from '@excalidraw/excalidraw/types/element/types' | ||
import { ExcalidrawImperativeAPI } from '@excalidraw/excalidraw/types/types' | ||
import { Box, Card } from '@radix-ui/themes' | ||
import React, { useEffect, useState } from 'react' | ||
|
||
interface ViewOnlyCanvasProps { | ||
initialData: ExcalidrawInitialDataState | ||
initialData: readonly ExcalidrawElement[] | ||
} | ||
|
||
export const ViewOnlyCanvas: React.FC<ViewOnlyCanvasProps> = ({ initialData }) => { | ||
const [excalidrawAPI, setExcalidrawAPI] = useState<ExcalidrawImperativeAPI | null>(null) | ||
|
||
useEffect(() => { | ||
if (excalidrawAPI && initialData) { | ||
excalidrawAPI.updateScene({ | ||
elements: initialData, | ||
}) | ||
} | ||
setTimeout(() => { | ||
excalidrawAPI?.scrollToContent(undefined, { | ||
fitToContent: true, | ||
}) | ||
}) | ||
}, [excalidrawAPI]) | ||
}, [excalidrawAPI, initialData]) | ||
|
||
return initialData && initialData.elements?.length ? ( | ||
return ( | ||
<Card> | ||
<Box className="excalidraw-view-container excalidraw-box"> | ||
<Excalidraw excalidrawAPI={setExcalidrawAPI} viewModeEnabled initialData={initialData} /> | ||
<Excalidraw | ||
excalidrawAPI={setExcalidrawAPI} | ||
viewModeEnabled | ||
initialData={{ elements: initialData }} | ||
/> | ||
</Box> | ||
</Card> | ||
) : null | ||
) | ||
} |
This file contains 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 |
---|---|---|
|
@@ -62,7 +62,7 @@ | |
} | ||
|
||
.excalidraw-box { | ||
margin: '2px'; | ||
margin: 2px; | ||
height: calc(100% - 4px); | ||
} | ||
|
||
|
This file contains 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
10 changes: 10 additions & 0 deletions
10
src/components/questionStructure/Task/variants/HandwritingTask/types.ts
This file contains 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,10 @@ | ||
import { ExcalidrawElement } from '@excalidraw/excalidraw/types/element/types' | ||
import { AppState } from '@excalidraw/excalidraw/types/types' | ||
|
||
export interface HandwritingAnswer { | ||
raw: { | ||
elements: readonly ExcalidrawElement[] | ||
appState?: Omit<AppState, 'offsetTop' | 'offsetLeft' | 'width' | 'height'> | ||
} | ||
latex: string | ||
} |
This file contains 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