import { route } from 'preact-router' import { useState } from 'preact/hooks' import { isAdministrator, isStudent, Solution as SolutionModel } from '../../shared/model' import { server } from '../api' import { Header } from '../components/Header' import { MarkdownEditor } from '../components/MarkdownEditor' import { Solution } from '../components/Solution' import { useCurrentUser, useListResource, useResource } from '../hooks' const CreateProblem = ({}) => { const [source, setSource] = useState('') const createProblem = async () => { const id = await server.post('/api/problem', { content: source, }) route(`/problem/${id}`) } return ( <> Aggiungi Problema > ) } export const AdminPage = ({}) => { const [user] = useCurrentUser(user => { if (!user) { route('/login', true) } else if (isStudent(user.role)) { route('/', true) } }) const [solutions, refreshSolutions, setSolutionHeuristic] = useListResource(`/api/solutions`) return ( user && ( Nuovo problema Soluzioni ancora da approvare/rifiutare {solutions.map( (s, index) => s.status === 'pending' && ( setSolutionHeuristic(index, solFn)} refreshSolution={refreshSolutions} /> ) )} ) ) }