Skip to content

Commit 05b449a

Browse files
Connect to backend
1 parent be85663 commit 05b449a

File tree

4 files changed

+58
-19
lines changed

4 files changed

+58
-19
lines changed

src/commons/sagas/RequestsSaga.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1331,6 +1331,26 @@ export const removeAssessmentConfig = async (
13311331
return resp;
13321332
};
13331333

1334+
/**
1335+
* POST /courses/{courseId}/admin/generate-comments/{submissionId}/{questionId}
1336+
*/
1337+
export const postGenerateComments = async (
1338+
tokens: Tokens,
1339+
submission_id: integer,
1340+
question_id: integer
1341+
): Promise<{comments:string[]} | null> => {
1342+
const resp = await request(`${courseId()}/admin/generate-comments/${submission_id}/${question_id}`, 'POST', {
1343+
...tokens
1344+
});
1345+
if (!resp || !resp.ok) {
1346+
return null;
1347+
}
1348+
1349+
return await resp.json();
1350+
};
1351+
1352+
1353+
13341354
/**
13351355
* GET /courses/{courseId}/admin/users
13361356
*/

src/pages/academy/grading/subcomponents/GradingCommentSelector.tsx

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,22 @@ type Props = {
66
};
77

88
const GradingCommentSelector : React.FC<Props> = (prop) => {
9-
return (
10-
<div className="grading-comment-selector">
11-
<div className="grading-comment-selector-title">
12-
Comment Suggestions:
13-
</div>
14-
{prop.comments.map(el => {
15-
return <div
16-
className="grading-comment-selector-item"
17-
onClick={() => {prop.setEditor(el)}}
18-
>
19-
{el}
9+
10+
return (
11+
<div className="grading-comment-selector">
12+
<div className="grading-comment-selector-title">
13+
Comment Suggestions:
2014
</div>
21-
})}
22-
</div>
23-
)
15+
{prop.comments.map(el => {
16+
return <div
17+
className="grading-comment-selector-item"
18+
onClick={() => {prop.setEditor(el)}}
19+
>
20+
{el}
21+
</div>
22+
})}
23+
</div>
24+
)
2425
}
2526

2627
export default GradingCommentSelector

src/pages/academy/grading/subcomponents/GradingEditor.tsx

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ import {
2727
import { convertParamToInt } from '../../../../commons/utils/ParamParseHelper';
2828
import GradingCommentSelector from './GradingCommentSelector';
2929

30+
import { useTokens } from 'src/commons/utils/Hooks';
31+
import { postGenerateComments } from '../../../../commons/sagas/RequestsSaga';
32+
3033
type GradingSaveFunction = (
3134
submissionId: number,
3235
questionId: number,
@@ -52,6 +55,7 @@ const gradingEditorButtonClass = 'grading-editor-button';
5255

5356
const GradingEditor: React.FC<Props> = props => {
5457
const dispatch = useDispatch();
58+
const tokens = useTokens();
5559
const { handleGradingSave, handleGradingSaveAndContinue, handleReautogradeAnswer } = useMemo(
5660
() =>
5761
({
@@ -102,6 +106,15 @@ const GradingEditor: React.FC<Props> = props => {
102106
// eslint-disable-next-line react-hooks/exhaustive-deps
103107
}, [props.submissionId, props.questionId]);
104108

109+
const getCommentSuggestions = async () => {
110+
const resp = await postGenerateComments(
111+
tokens,props.submissionId,props.questionId
112+
)
113+
return resp
114+
}
115+
116+
const [suggestions, setSuggestions] = useState<string[]>([])
117+
105118
const makeInitialState = () => {
106119
setXpAdjustmentInput(props.xpAdjustment.toString());
107120
setEditorValue(props.comments);
@@ -307,8 +320,16 @@ const GradingEditor: React.FC<Props> = props => {
307320

308321
<GradingCommentSelector
309322
setEditor={setEditorValue}
310-
comments={["Test comment 1", "Test comment 3"]}
323+
comments={suggestions}
311324
/>
325+
<Button
326+
onClick={async ()=>{
327+
const resp = await getCommentSuggestions();
328+
console.log(resp!.comments)
329+
setSuggestions(resp!.comments);
330+
}}>
331+
Get comments
332+
</Button>
312333

313334
<div className="react-mde-parent">
314335
<ReactMde

src/pages/playground/Playground.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ import {
9898
makeSubstVisualizerTabFrom,
9999
mobileOnlyTabIds
100100
} from './PlaygroundTabs';
101-
import GradingWorkspace from '../academy/grading/subcomponents/GradingWorkspace';
102101

103102
export type PlaygroundProps = {
104103
isSicpEditor?: boolean;
@@ -1038,9 +1037,7 @@ const Playground: React.FC<PlaygroundProps> = props => {
10381037
) : (
10391038

10401039
<div className={classNames('Playground', Classes.DARK, isGreen && 'GreenScreen')}>
1041-
1042-
<GradingWorkspace submissionId={1} questionId={1}/>
1043-
{false && <Workspace {...workspaceProps} />}
1040+
<Workspace {...workspaceProps} />
10441041
</div>
10451042
);
10461043
};

0 commit comments

Comments
 (0)