import { route } from 'preact-router' import { useState } from 'preact/hooks' import { isAdministrator, isStudent, Solution as SolutionModel, SolutionId } from '../../shared/model' import { sortByStringKey } from '../../shared/utils' import { server } from '../api' import { Header } from '../components/Header' import { MarkdownEditor } from '../components/MarkdownEditor' import { Select } from '../components/Select' 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 ( <> ) } type SortOrder = 'latest' | 'oldest' 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`) const [sortOrder, setSortOrder] = useState('oldest') const sortedSolutions = sortByStringKey(solutions, s => s.createdAt, sortOrder === 'oldest') const [trackInteracted, setTrackedInteracted] = useState>(new Set()) const hasUntrackedPending = sortedSolutions.filter(s => s.status === 'pending' || trackInteracted.has(s.id)).length > 0 return ( user && (
Nuovo problema
Soluzioni da correggere
{hasUntrackedPending ? (