|
|
|
import { route } from 'preact-router'
|
|
|
|
import { useState } from 'preact/hooks'
|
|
|
|
import { isStudent } from '../../shared/model'
|
|
|
|
import { server } from '../api'
|
|
|
|
import { Header } from '../components/Header'
|
|
|
|
import { MarkdownEditor } from '../components/MarkdownEditor'
|
|
|
|
import { useCurrentUser } from '../hooks'
|
|
|
|
|
|
|
|
const CreateProblem = ({}) => {
|
|
|
|
const [source, setSource] = useState('')
|
|
|
|
const createProblem = async () => {
|
|
|
|
const id = await server.post('/api/problem', {
|
|
|
|
content: source,
|
|
|
|
})
|
|
|
|
|
|
|
|
route(`/problem/${id}`)
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<MarkdownEditor {...{ source, setSource }} />
|
|
|
|
<button onClick={createProblem}>Aggiungi Problema</button>
|
|
|
|
</>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export const AdminPage = ({}) => {
|
|
|
|
const [user] = useCurrentUser(user => {
|
|
|
|
if (!user) {
|
|
|
|
route('/login', true)
|
|
|
|
} else if (isStudent(user.role)) {
|
|
|
|
route('/', true)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
return (
|
|
|
|
user && (
|
|
|
|
<main class="page-admin">
|
|
|
|
<Header {...{ user }} />
|
|
|
|
<div class="subtitle">Nuovo problema</div>
|
|
|
|
<CreateProblem />
|
|
|
|
<div class="subtitle">Soluzioni ancora da approvare/rifiutare</div>
|
|
|
|
...
|
|
|
|
</main>
|
|
|
|
)
|
|
|
|
)
|
|
|
|
}
|