feat: pre-populate generator with problem samples on open

This commit is contained in:
2026-05-19 04:22:23 -06:00
parent 06738f6e29
commit 874a6fbe90
2 changed files with 11 additions and 3 deletions

View File

@@ -13,6 +13,7 @@ interface FileEntry {
interface Props { interface Props {
answers: { language: LANGUAGE; code: string }[] answers: { language: LANGUAGE; code: string }[]
samples?: { input: string; output: string }[]
} }
const props = defineProps<Props>() const props = defineProps<Props>()
@@ -23,9 +24,15 @@ const emit = defineEmits<{
const message = useMessage() const message = useMessage()
let nextId = 0 let nextId = 0
const files = ref<FileEntry[]>(
Array.from({ length: 5 }, () => ({ id: nextId++, in: "", out: "", error: false })), function makeInitialFiles(): FileEntry[] {
) if (props.samples?.length) {
return props.samples.map((s) => ({ id: nextId++, in: s.input, out: s.output, error: false }))
}
return Array.from({ length: 5 }, () => ({ id: nextId++, in: "", out: "", error: false }))
}
const files = ref<FileEntry[]>(makeInitialFiles())
const selectedLanguage = ref<LANGUAGE>("Python3") const selectedLanguage = ref<LANGUAGE>("Python3")

View File

@@ -706,6 +706,7 @@ watch(
> >
<TestcaseGenerator <TestcaseGenerator
:answers="problem.answers" :answers="problem.answers"
:samples="problem.samples"
@uploaded="handleTestcasesGenerated" @uploaded="handleTestcasesGenerated"
/> />
</n-modal> </n-modal>