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 { prependBaseUrl, server } from '../api' import { Header } from '../components/Header' import { MarkdownEditor } from '../components/MarkdownEditor' import { Select } from '../components/Select' import { Solution } from '../components/Solution' import { useListResource } from '../hooks' import { useCurrentUser } from '../hooks/useCurrentUser' const CreateProblem = ({}) => { const [source, setSource] = useState('') type ProblemFields = { title?: string content: string } const createProblem = async () => { if (source.trim().length === 0) { alert('Il campo di testo è vuoto!') return } const id = await server.post('/api/problem', { content: source, }) route(prependBaseUrl(`/problem/${id}`)) } return ( <> ) } type SortOrder = 'latest' | 'oldest' export const AdminPage = ({}) => { const [user, ready] = useCurrentUser() if (!ready) { return <> } if (user === null) { route(prependBaseUrl('/login'), true) return <> } if (!isAdministrator(user.role)) { route(prependBaseUrl('/'), true) return <> } 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 ( <>
Nuovo problema

Soluzioni da correggere
{hasUntrackedPending ? (