Skip to content

Commit 0a93b79

Browse files
authored
Merge pull request #120 from danielemery/117-add-a-way-for-a-user-to-mark-a-quiz-with-inaccurrate-ai-ocr-and-display-when-someone-has-marked-it
Implement reporting of inaccurate OCR and display a warning when a user has reported it
2 parents df4a15c + d54dac6 commit 0a93b79

File tree

4 files changed

+35
-10
lines changed

4 files changed

+35
-10
lines changed

src/QuizDetails.tsx

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ import {
1616
formatDateTimeShortTime,
1717
userIdentifier,
1818
} from './helpers';
19-
import { AI_PROCESS_QUIZ_IMAGES, QUIZ, QUIZZES } from './queries/quiz';
20-
import { MARK_QUIZ_ILLEGIBLE } from './queries/quiz';
19+
import { AI_PROCESS_QUIZ_IMAGES, MARK_INACCURATE_OCR, MARK_QUIZ_ILLEGIBLE, QUIZ, QUIZZES } from './queries/quiz';
2120
import { userCanPerformAction } from './services/authorization';
2221
import { Quiz as QuizType } from './types/quiz';
2322

@@ -44,6 +43,9 @@ export default function Quiz() {
4443
navigate('/');
4544
},
4645
});
46+
const [markInaccurateOCR, { loading: isMarkingQuizInaccurateOCR }] = useMutation(MARK_INACCURATE_OCR, {
47+
refetchQueries: [{ query: QUIZ, variables: { id } }],
48+
});
4749
const [aiProcessQuizImages, { loading: isProcessingQuizImages }] = useMutation(AI_PROCESS_QUIZ_IMAGES, {
4850
refetchQueries: [{ query: QUIZ, variables: { id } }],
4951
});
@@ -78,7 +80,9 @@ export default function Quiz() {
7880
</div>
7981
)}
8082
</dl>
81-
{data.quiz.questions.length > 0 ? <QuizQuestions questions={data.quiz.questions} /> : null}
83+
{data.quiz.questions.length > 0 ? (
84+
<QuizQuestions questions={data.quiz.questions} reportedInaccurateOCR={data.quiz.reportedInaccurateOCR} />
85+
) : null}
8286
{[...data.quiz.images]
8387
.sort((a, b) => {
8488
return imageTypeSortValues[a.type] - imageTypeSortValues[b.type];
@@ -93,13 +97,23 @@ export default function Quiz() {
9397
<Button onClick={() => markQuizIllegible({ variables: { id } })} disabled={isMarkingQuizIllegible} warning>
9498
Mark Quiz Illegible
9599
</Button>
100+
{!data.quiz.reportedInaccurateOCR && (
101+
<Button
102+
onClick={() => markInaccurateOCR({ variables: { id } })}
103+
disabled={isMarkingQuizInaccurateOCR}
104+
warning
105+
>
106+
Mark Inaccurate OCR
107+
</Button>
108+
)}
109+
96110
{userCanPerformAction(user, 'TRIGGER_AI_PROCESSING') && data.quiz.aiProcessingState !== 'QUEUED' && (
97111
<Button
98112
onClick={() => aiProcessQuizImages({ variables: { id } })}
99113
disabled={isProcessingQuizImages}
100114
warning
101115
>
102-
{isProcessingQuizImages ? 'Processing...' : 'Trigger AI Processing'}
116+
Trigger AI Processing
103117
</Button>
104118
)}
105119
</div>

src/QuizQuestions.tsx

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
1+
import classNames from 'classnames';
2+
13
import { ExpandCollapseSection } from './components/ExpandCollapseSection';
24
import { QuizQuestion } from './types/quiz';
35

46
export interface QuizQuestionsProps {
57
questions: QuizQuestion[];
8+
reportedInaccurateOCR: boolean;
69
}
710

8-
export default function QuizQuestions({ questions }: QuizQuestionsProps) {
11+
export default function QuizQuestions({ questions, reportedInaccurateOCR }: QuizQuestionsProps) {
912
return (
1013
<>
11-
<ExpandCollapseSection title='Questions' initiallyShown={true}>
12-
<div className='font-bold italic text-sm mb-4'>
14+
<ExpandCollapseSection title='Questions' initiallyShown={!reportedInaccurateOCR}>
15+
<div className={classNames('font-bold italic text-sm mb-4', { 'text-red-500': reportedInaccurateOCR })}>
1316
Please note these questions have been extracted using google gemini, there is no guarantee on the accuracy of
14-
the question extraction.
17+
the question extraction.{reportedInaccurateOCR && ' At least one user has reported the OCR to be inaccurate.'}
1518
</div>
1619
<ol>
1720
{questions.map((question) => (
@@ -22,9 +25,9 @@ export default function QuizQuestions({ questions }: QuizQuestionsProps) {
2225
</ol>
2326
</ExpandCollapseSection>
2427
<ExpandCollapseSection title='Answers' fallbackText='Answers are hidden by default.' initiallyShown={false}>
25-
<div className='font-bold italic text-sm mb-4'>
28+
<div className={classNames('font-bold italic text-sm mb-4', { 'text-red-500': reportedInaccurateOCR })}>
2629
Please note these answers have been extracted using google gemini, there is no guarantee on the accuracy of
27-
the answer extraction.
30+
the answer extraction.{reportedInaccurateOCR && ' At least one user has reported the OCR to be inaccurate.'}
2831
</div>
2932
<ol>
3033
{questions.map((question) => (

src/queries/quiz.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ export const QUIZ = gql`
5858
answer
5959
}
6060
aiProcessingState
61+
reportedInaccurateOCR
6162
}
6263
}
6364
`;
@@ -158,6 +159,12 @@ export const MARK_QUIZ_ILLEGIBLE = gql`
158159
}
159160
`;
160161

162+
export const MARK_INACCURATE_OCR = gql`
163+
mutation MarkInaccurateOCR($id: String!) {
164+
markInaccurateOCR(quizId: $id)
165+
}
166+
`;
167+
161168
export const AI_PROCESS_QUIZ_IMAGES = gql`
162169
mutation AIProcessQuizImages($id: String!) {
163170
aiProcessQuizImages(quizId: $id)

src/types/quiz.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,5 @@ export interface Quiz {
3232
images: QuizImage[];
3333
questions: QuizQuestion[];
3434
aiProcessingState: QuizAIProcessingState;
35+
reportedInaccurateOCR: boolean;
3536
}

0 commit comments

Comments
 (0)