Skip to content

Commit

Permalink
ref
Browse files Browse the repository at this point in the history
  • Loading branch information
nakasyou committed Nov 9, 2024
1 parent 230553c commit 3cc79e9
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 4,698 deletions.
4,612 changes: 0 additions & 4,612 deletions deno.lock

This file was deleted.

6 changes: 3 additions & 3 deletions src/islands/ai-quiz/constants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type InferOutput, array, object, string } from 'valibot'
import { type InferOutput, array, number, object, string } from 'valibot'
import selectQuestion from './schemas/select-question.json'

/**
Expand All @@ -15,8 +15,8 @@ ${JSON.stringify(selectQuestion)}
export const CONTENT_SCHEMA = object({
question: string(),
explanation: string(),
correctAnswer: string(),
damyAnswers: array(string()),
choices: array(string()),
corrects: array(number()),
})

export type QuizContent = InferOutput<typeof CONTENT_SCHEMA>
54 changes: 54 additions & 0 deletions src/islands/ai-quiz/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { createSignal, onMount, Show } from 'solid-js'
import type { NoteLoadType } from '../note/note-load-types'
import { loadNoteFromType } from '../shared/storage'
import { load } from '../note/utils/file-format'
import type { MargedNoteData } from '../note/components/notes-utils'
import { Spinner } from '../note/components/utils/Spinner'

export const Navbar = () => {

}

export const InitialScreen = () => {
return <div>
aaa
</div>
}

const LoadingNoteScreen = () => {
return <div class="h-full grid place-items-center">
<div class="flex justify-center items-center">
<Spinner class="border-on-background"/>
ノートを読み込み中...
</div>
</div>
}
export default (props: {
noteLoadType: NoteLoadType
}) => {
const [getNote, setNote] = createSignal<MargedNoteData[]>()
const [getNoteLoadState, setNoteLoadState] = createSignal<'pending' | 'loaded' | 'error'>('pending')

onMount(async () => {
setNoteLoadState('pending')
const loadedNoteFile = await loadNoteFromType(props.noteLoadType)
if (!loadedNoteFile) {
setNoteLoadState('error')
return
}

const loadedNote = await load(new Blob([loadedNoteFile.nnote]))
if (!loadedNote.success) {
setNoteLoadState('error')
return
}

setNote(loadedNote.notes)
setNoteLoadState('loaded')
})
return <div class="h-full">
<Show when={getNoteLoadState() === 'pending'}>
<LoadingNoteScreen />
</Show>
</div>
}
19 changes: 11 additions & 8 deletions src/islands/ai-quiz/schemas/select-question.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,21 @@
"type": "string",
"description": "不正解時に表示される解説"
},
"correctAnswer": {
"type": "string",
"description": "正解。用語などを出題してもよい。しなくてもよい"
},
"damyAnswers": {
"choices": {
"type": "array",
"description": "選択肢。2個から5個まで",
"items": {
"type": "string"
},
"description": "不正解と明らかなダミー"
}
},
"corrects": {
"type": "array",
"description": "正解の選択肢のインデックス。完答形式。",
"items": {
"type": "number"
}
}
},
"required": ["question", "explanation", "correctAnswer", "damyAnswers"]
"required": ["question", "explanation", "choices", "corrects"]
}
}
74 changes: 2 additions & 72 deletions src/islands/ai-quiz/store.ts
Original file line number Diff line number Diff line change
@@ -1,74 +1,4 @@
import { type NoSerialize, createContextId } from '@builder.io/qwik'
import type { TextNoteData } from '../note/components/notes/TextNote/types'
import type { NoteLoadType } from '../note/note-load-types'
import type { QuizContent } from './constants'

/**
* クイズ
*/
export interface Quiz {
content: QuizContent

source: TextNoteData

id: number
}

export interface ScreenState {
note:
| NoSerialize<{
name: string
notes: TextNoteData[]
}>
| 'pending'
| 'notfound'
| 'invalid'

started: boolean

availableAI: boolean | null

noteLoadType: NoteLoadType

/**
* 出題範囲
*/
rangeNotes: Set<string>

lastMissedQuizIds: number[]
}

export type QuizFrom = 'generated' | 'missed' | 'lowRate'
export type QuizState = {
correctQuizzes: Quiz[]
incorrectQuizzes: Quiz[]

generatedQuizzes: number

quizzes: {
quiz: Quiz
from: QuizFrom
}[]

current: {
index: number
quiz: Quiz
choices: string[]
from: QuizFrom
} | null

isFinished: boolean

finishedQuizIndexes: Set<number>

lastMissedQuizzes: number
}

export interface Settings {
quizzesByRound: number
lowRateQuizzesInRound: number
}

export const SCREEN_STATE_CTX = createContextId<ScreenState>('screenState')
export const QUIZ_STATE_CTX = createContextId<QuizState>('quizState')
export const SETTINGS_CTX = createContextId<Settings>('settings')
note: Note
}
9 changes: 7 additions & 2 deletions src/islands/note/components/utils/Spinner.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
export const Spinner = () => {
export const Spinner = (props: {
class?: string
}) => {
return (
<div class="animate-spin h-[1.2rem] w-[1.2rem] border-2 border-surface rounded-full border-t-transparent inline-block" />
<div
classList={{ [props.class ?? '']: true }}
class="animate-spin h-[1.2rem] w-[1.2rem] border-2 rounded-full border-t-transparent inline-block"
/>
)
}
2 changes: 1 addition & 1 deletion src/pages/app/notes/[noteid]/quiz.astro
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
import QuizApp from '../../../../islands/ai-quiz/index.qwik'
import QuizApp from '../../../../islands/ai-quiz/index.tsx'
import type { NoteLoadType } from '../../../../islands/note/note-load-types'
import Base from '../../../../layouts/Base.astro'
Expand Down

0 comments on commit 3cc79e9

Please sign in to comment.