import { useEffect, useRef, useState } from 'preact/hooks' import { Markdown } from '../components/Markdown.jsx' import { Problem } from '../components/Problem.jsx' export const ProblemPage = ({ id }) => { const [source, setSource] = useState('') const editorRef = useRef() const sendSolution = async () => { const res = await fetch(`/api/problem/${id}/new-solution`, { headers: { 'Content-Type': 'application/json', }, credentials: 'include', body: JSON.stringify({ source, }), }) console.log(await res.json()) } useEffect(() => { if (editorRef.current) { // settare questo ad "auto" toglie l'altezza al contenitore che passa alla sua // dimensione minima iniziale, ciò serve per permettere all'autosize della textarea di // crescere e ridursi ma ha il problema che resetta lo scroll della pagina che deve // essere preservato a mano const oldScrollY = window.scrollY editorRef.current.style.height = 'auto' editorRef.current.style.height = editorRef.current.scrollHeight + 'px' window.scrollTo(0, oldScrollY) } }, [source]) return (
Testo del problema
Invia una soluzione al problema

Editor

Preview

{source.trim().length ? ( ) : (
Scrivi una nuova soluzione...
)}
) }