File tree Expand file tree Collapse file tree 4 files changed +66
-105
lines changed
Expand file tree Collapse file tree 4 files changed +66
-105
lines changed Original file line number Diff line number Diff line change @@ -12,7 +12,7 @@ import HistoryModal from "@/components/modals/history-modal"
1212import LoadingQuestionModal from "@/components/modals/loading-question-modal"
1313import { useState , useEffect , useCallback } from "react"
1414import type { Question , UserAnswer , QuestionHistory } from "@/lib/types"
15- import { generateRandomQuestion } from "@/lib/data "
15+ import { generateRandomQuestion } from "@/lib/question "
1616import { useTranslation } from "@/lib/i18n"
1717import { useToast } from "@/hooks/use-toast"
1818// Update the onSubmit function to use the OpenAI API for evaluation
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1+ import { generateQuestion } from "./api"
2+ import { Question , QuestionCategory , QuestionDifficulty , QuestionType } from "./types"
3+
4+ // In-memory storage for generated questions
5+ let generatedQuestions : Question [ ] = [ ]
6+
7+ export async function generateRandomQuestion ( ) : Promise < Question > {
8+ const type = Object . keys ( QuestionType ) . filter ( key => isNaN ( Number ( key ) ) ) as QuestionType [ ]
9+ const category = Object . keys ( QuestionCategory ) . filter ( key => isNaN ( Number ( key ) ) ) as QuestionCategory [ ]
10+ const difficulty = Object . keys ( QuestionDifficulty ) . filter ( key => isNaN ( Number ( key ) ) ) as QuestionDifficulty [ ]
11+ const randomType = type [ Math . floor ( Math . random ( ) * type . length ) ]
12+ const randomCategory = category [ Math . floor ( Math . random ( ) * category . length ) ]
13+ const randomDifficulty = difficulty [ Math . floor ( Math . random ( ) * difficulty . length ) ]
14+ return await generateQuestion ( randomType , randomCategory , randomDifficulty )
15+ }
16+
17+ // Add a new function to add a generated question to our collection
18+ export function addGeneratedQuestion ( question : Question ) : void {
19+ generatedQuestions . push ( question )
20+ }
Original file line number Diff line number Diff line change 11export interface Question {
2- id : string
3- type : "Coding" | "Question"
4- category : string
5- difficulty : "Easy" | "Medium" | "Hard"
6- translations : {
7- [ key : string ] : {
8- title : string
9- description : string
10- topic : string
2+ id : string
3+ type : QuestionType
4+ category : string
5+ difficulty : "Easy" | "Medium" | "Hard"
6+ translations : {
7+ [ key : string ] : {
8+ title : string
9+ description : string
10+ topic : string
11+ }
1112 }
12- }
13- testCases ?: Array < {
14- input : any
15- output : any
16- } >
13+ testCases ?: Array < {
14+ input : any
15+ output : any
16+ } >
17+ }
18+
19+ export enum QuestionType {
20+ Coding = "Coding" ,
21+ Question = "Question"
22+ }
23+
24+ export enum QuestionDifficulty {
25+ Easy = "Easy" ,
26+ Medium = "Medium" ,
27+ Hard = "Hard"
28+ }
29+
30+ export enum QuestionCategory {
31+ Algorithms = "Algorithms" ,
32+ TCP = "TCP" ,
33+ UDP = "UDP" ,
34+ DataStructures = "Data Structures" ,
35+ LeetCode = "LeetCode" ,
36+ Java = "Java" ,
37+ SystemDesign = "System Design" ,
38+ Behavioral = "Behavioral" ,
39+ OperationSystem = "Operation System" ,
40+ Spring = "Spring"
1741}
1842
1943export interface UserAnswer {
20- content : string
44+ content : string
2145}
2246
2347export interface QuestionHistory {
24- id : string
25- title : string
26- timestamp : string
27- answered : boolean
28- language : string
29- question : Question
48+ id : string
49+ title : string
50+ timestamp : string
51+ answered : boolean
52+ language : string
53+ question : Question
3054}
3155
You can’t perform that action at this time.
0 commit comments