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.
40 lines
1.2 KiB
TypeScript
40 lines
1.2 KiB
TypeScript
2 years ago
|
import { route } from 'preact-router'
|
||
|
import { useState } from 'preact/hooks'
|
||
|
import { server } from '../api.jsx'
|
||
|
import { Header } from '../components/Header.jsx'
|
||
|
import { Solution } from '../components/Solution.jsx'
|
||
|
import { useCurrentUser, useReadResource } from '../hooks.jsx'
|
||
|
|
||
|
export const ProfilePage = ({}) => {
|
||
|
const [solutions, setSolutions] = useState([])
|
||
|
|
||
|
const [user, logout] = useCurrentUser(async user => {
|
||
|
if (!user) {
|
||
|
route('/login', true)
|
||
|
}
|
||
|
|
||
2 years ago
|
setSolutions(await server.get(`/api/solutions?user=${user.id}`))
|
||
2 years ago
|
})
|
||
|
|
||
|
const handleLogout = () => {
|
||
|
logout()
|
||
|
route('/')
|
||
|
}
|
||
|
|
||
|
return (
|
||
|
user && (
|
||
|
<main class="page-profile">
|
||
|
<Header {...{ user }} />
|
||
|
<div class="subtitle">Le tue soluzioni</div>
|
||
|
<div class="solution-list">
|
||
2 years ago
|
{solutions.map(({ forProblem, content }) => (
|
||
|
<Solution {...{ forProblem, content }} />
|
||
2 years ago
|
))}
|
||
|
</div>
|
||
|
<div class="subtitle">Altro</div>
|
||
|
<button onClick={handleLogout}>Logout</button>
|
||
|
</main>
|
||
|
)
|
||
|
)
|
||
|
}
|