Skip to content

Commit fb4f15d

Browse files
Add save chosen and final comment feature
Comment selector can now handle selecting multiple suggestions
1 parent 730cb35 commit fb4f15d

File tree

3 files changed

+59
-5
lines changed

3 files changed

+59
-5
lines changed

src/commons/sagas/RequestsSaga.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1350,7 +1350,33 @@ export const postGenerateComments = async (
13501350
return await resp.json();
13511351
};
13521352

1353+
export const saveFinalComment = async (
1354+
tokens: Tokens,
1355+
submission_id: integer,
1356+
question_id: integer,
1357+
comment: string
1358+
): Promise<Response | null> => {
1359+
const resp = await request(`${courseId()}/admin/save-final-comment/${submission_id}/${question_id}`, 'POST', {
1360+
body: {"comment": comment},
1361+
...tokens
1362+
})
1363+
1364+
return resp
1365+
}
13531366

1367+
export const saveChosenComments = async (
1368+
tokens: Tokens,
1369+
submission_id: integer,
1370+
question_id: integer,
1371+
comments: string[]
1372+
): Promise<Response | null> => {
1373+
const resp = await request(`${courseId()}/admin/save-chosen-comments/${submission_id}/${question_id}`, 'POST', {
1374+
body: {"comments": comments},
1375+
...tokens
1376+
})
1377+
1378+
return resp
1379+
}
13541380

13551381
/**
13561382
* GET /courses/{courseId}/admin/users

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React from "react";
22

33
type Props = {
44
comments: string[],
5-
setEditor: React.Dispatch<React.SetStateAction<string>>
5+
onSelect: (comment: string) => void
66
};
77

88
const GradingCommentSelector : React.FC<Props> = (prop) => {
@@ -15,7 +15,7 @@ const GradingCommentSelector : React.FC<Props> = (prop) => {
1515
{prop.comments.map(el => {
1616
return <div
1717
className="grading-comment-selector-item"
18-
onClick={() => {prop.setEditor(el)}}
18+
onClick={() => {prop.onSelect(el)}}
1919
>
2020
{el}
2121
</div>

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

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ import GradingCommentSelector from './GradingCommentSelector';
2929

3030
import { useTokens } from 'src/commons/utils/Hooks';
3131
import { postGenerateComments } from '../../../../commons/sagas/RequestsSaga';
32+
import { saveFinalComment } from '../../../../commons/sagas/RequestsSaga';
33+
import { saveChosenComments } from '../../../../commons/sagas/RequestsSaga';
3234

3335
type GradingSaveFunction = (
3436
submissionId: number,
@@ -109,13 +111,38 @@ const GradingEditor: React.FC<Props> = props => {
109111

110112
const getCommentSuggestions = async () => {
111113
const resp = await postGenerateComments(
112-
tokens,props.submissionId,props.questionId
114+
tokens, props.submissionId, props.questionId
113115
)
114116
return resp
115117
}
116118

119+
const onSelectGeneratedComments = (comment: string) => {
120+
if (!selectedSuggestions.includes(comment)) {
121+
setSelectedSuggestions([comment, ...selectedSuggestions])
122+
}
123+
124+
setEditorValue(editorValue + comment)
125+
}
126+
127+
const postSaveFinalComment = async (comment : string) => {
128+
const resp = await saveFinalComment(
129+
tokens, props.submissionId, props.questionId, comment
130+
)
131+
return resp
132+
}
133+
134+
const postSaveChosenComments = async (comments : string[]) => {
135+
const resp = await saveChosenComments(
136+
tokens, props.submissionId, props.questionId, comments
137+
)
138+
139+
return resp
140+
}
141+
117142
const [suggestions, setSuggestions] = useState<string[]>([])
118143

144+
const [selectedSuggestions, setSelectedSuggestions] = useState<string[]>([])
145+
119146
const makeInitialState = () => {
120147
setXpAdjustmentInput(props.xpAdjustment.toString());
121148
setEditorValue(props.comments);
@@ -144,6 +171,8 @@ const GradingEditor: React.FC<Props> = props => {
144171
() => {
145172
const newXpAdjustmentInput = convertParamToInt(xpAdjustmentInput || undefined) || undefined;
146173
const xp = props.initialXp + (newXpAdjustmentInput || 0);
174+
postSaveFinalComment(editorValue);
175+
postSaveChosenComments(selectedSuggestions);
147176
if (xp < 0 || xp > props.maxXp) {
148177
showWarningMessage(
149178
`XP ${xp.toString()} is out of bounds. Maximum xp is ${props.maxXp.toString()}.`
@@ -322,13 +351,12 @@ const GradingEditor: React.FC<Props> = props => {
322351
{props.is_llm &&
323352
<div>
324353
<GradingCommentSelector
325-
setEditor={setEditorValue}
354+
onSelect={onSelectGeneratedComments}
326355
comments={suggestions}
327356
/>
328357
<Button
329358
onClick={async ()=>{
330359
const resp = await getCommentSuggestions();
331-
console.log(resp!.comments)
332360
setSuggestions(resp!.comments);
333361
}}>
334362
Get comments

0 commit comments

Comments
 (0)