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.

51 lines
1.4 KiB
React

import { route } from 'preact-router'
2 years ago
import { Problem } from '../components/Problem.jsx'
import { useUser } from '../hooks.jsx'
export const HomePage = () => {
console.log('rendering homepage')
const [user, logout] = useUser()
2 years ago
const handleLogout = async () => {
2 years ago
await fetch(`/api/logout`, {
method: 'POST',
})
logout()
2 years ago
}
const problems = Array.from({ length: 20 }, (_, i) => ({
id: i + 1,
content:
`Lorem ipsum dolor sit amet, consectetur adipisicing elit. Architecto porro commodi cumque ratione sequi reiciendis corrupti a eius praesentium.\n`.repeat(
((i + 2) % 4) + 1
),
}))
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.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>
)
}