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.
46 lines
1.4 KiB
TypeScript
46 lines
1.4 KiB
TypeScript
import { route } from 'preact-router'
|
|
import { useState } from 'preact/hooks'
|
|
import { isAdministrator, Solution as SolutionModel, User } from '../../shared/model'
|
|
import { prependBaseUrl, server } from '../api'
|
|
import { Header } from '../components/Header'
|
|
import { Select } from '../components/Select'
|
|
import { Solution } from '../components/Solution'
|
|
import { useCurrentUser, useResource } from '../hooks'
|
|
|
|
const SolutionList = ({ user }: { user: User }) => {
|
|
const [solutions, refresh] = useResource<SolutionModel[]>(`/api/solutions?user=${user.id}`, [])
|
|
|
|
return (
|
|
<div class="solution-list">
|
|
{solutions.map(solution => (
|
|
<Solution {...solution} adminControls={isAdministrator(user.role)} />
|
|
))}
|
|
</div>
|
|
)
|
|
}
|
|
|
|
export const ProfilePage = ({}) => {
|
|
const [user, logout] = useCurrentUser(user => {
|
|
if (!user) {
|
|
route(prependBaseUrl('/login'), true)
|
|
}
|
|
})
|
|
|
|
const handleLogout = async () => {
|
|
await logout()
|
|
route(prependBaseUrl('/'))
|
|
}
|
|
|
|
return (
|
|
user && (
|
|
<main class="page-profile">
|
|
<Header {...{ user }} />
|
|
<div class="subtitle">Profilo</div>
|
|
<button onClick={handleLogout}>Logout</button>
|
|
<div class="subtitle">Le tue soluzioni</div>
|
|
<SolutionList {...{ user }} />
|
|
</main>
|
|
)
|
|
)
|
|
}
|