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.

44 lines
1.2 KiB
React

import { route } from 'preact-router'
import { useEffect, useState } from 'preact/hooks'
2 years ago
import { Problem } from '../components/Problem.jsx'
import { useReadResource, useCurrentUser } from '../hooks.jsx'
export const HomePage = () => {
const [user, logout] = useCurrentUser()
2 years ago
const handleLogout = async () => {
2 years ago
await fetch(`/api/logout`, {
method: 'POST',
})
logout()
2 years ago
}
const [problems] = useReadResource('/api/problems', [])
2 years ago
return (
2 years ago
<main class="home">
<div class="logo">PHC / Problemi</div>
2 years ago
<div class="subtitle">
{user ? (
2 years ago
<>
Logged in as {user.role} @{user.username} (
<span class="link" onClick={handleLogout}>
2 years ago
Logout
</span>
)
</>
) : (
<a href="/login">Login</a>
2 years ago
)}
</div>
2 years ago
<div class="board">
2 years ago
{problems.map(p => (
<Problem {...p} />
2 years ago
))}
</div>
</main>
)
}