You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
48 lines
1.3 KiB
TypeScript
48 lines
1.3 KiB
TypeScript
2 years ago
|
import { route } from 'preact-router'
|
||
2 years ago
|
import { useEffect, useState } from 'preact/hooks'
|
||
2 years ago
|
import { isAdministrator, isStudent } from '../../shared/constants.js'
|
||
2 years ago
|
import { server } from '../api.jsx'
|
||
|
import { Header } from '../components/Header.jsx'
|
||
|
import { MarkdownEditor } from '../components/MarkdownEditor.jsx'
|
||
2 years ago
|
import { useCurrentUser } from '../hooks.jsx'
|
||
|
|
||
2 years ago
|
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 = ({}) => {
|
||
2 years ago
|
const [user] = useCurrentUser(user => {
|
||
2 years ago
|
if (!user) {
|
||
|
route('/login', true)
|
||
2 years ago
|
} else if (isStudent(user.role)) {
|
||
2 years ago
|
route('/', true)
|
||
|
}
|
||
|
})
|
||
|
|
||
|
return (
|
||
2 years ago
|
user && (
|
||
|
<main class="page-admin">
|
||
|
<Header {...{ user }} />
|
||
|
<div class="subtitle">Nuovo problema</div>
|
||
|
<CreateProblem />
|
||
|
<div class="subtitle">Soluzioni ancora da approvare/rifiutare</div>
|
||
|
...
|
||
|
</main>
|
||
|
)
|
||
2 years ago
|
)
|
||
|
}
|