Got working preact SSR

This commit is contained in:
2022-11-07 02:02:23 +01:00
parent 5142d4c551
commit ddad7fe746
16 changed files with 229 additions and 200 deletions
+10 -6
View File
@@ -1,15 +1,19 @@
import { route } from 'preact-router'
import { Problem } from '../components/Problem.jsx'
import { useUser } from '../hooks.jsx'
export const HomePage = () => {
const { username } = useUser()
console.log('rendering homepage')
const logout = async () => {
const [user, logout] = useUser()
const handleLogout = async () => {
await fetch(`/api/logout`, {
method: 'POST',
})
location.reload()
logout()
}
const problems = Array.from({ length: 20 }, (_, i) => ({
@@ -24,10 +28,10 @@ export const HomePage = () => {
<main class="home">
<div class="logo">PHC / Problemi</div>
<div class="subtitle">
{username ? (
{user ? (
<>
Logged in as {username} (
<span class="link" onClick={() => logout()}>
Logged in as {user.username} (
<span class="link" onClick={handleLogout}>
Logout
</span>
)
+3 -1
View File
@@ -1,3 +1,5 @@
import { route } from 'preact-router'
import { useState } from 'preact/hooks'
export const LoginPage = () => {
@@ -14,7 +16,7 @@ export const LoginPage = () => {
}),
})
location.href = '/#/'
route('/')
}
return (