feat: pre-populate generator with problem samples on open
This commit is contained in:
@@ -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")
|
||||||
|
|
||||||
|
|||||||
@@ -706,6 +706,7 @@ watch(
|
|||||||
>
|
>
|
||||||
<TestcaseGenerator
|
<TestcaseGenerator
|
||||||
:answers="problem.answers"
|
:answers="problem.answers"
|
||||||
|
:samples="problem.samples"
|
||||||
@uploaded="handleTestcasesGenerated"
|
@uploaded="handleTestcasesGenerated"
|
||||||
/>
|
/>
|
||||||
</n-modal>
|
</n-modal>
|
||||||
|
|||||||
Reference in New Issue
Block a user