import { route } from 'preact-router' import { isAdministrator, Solution as SolutionModel, User } from '../../shared/model' import { sortByStringKey } from '../../shared/utils' import { prependBaseUrl } from '../api' import { Header } from '../components/Header' import { Solution } from '../components/Solution' import { useResource } from '../hooks' import { useCurrentUser, useUserFunctions } from '../hooks/useCurrentUser' export const ProfilePage = ({}) => { const [user, ready] = useCurrentUser() if (!ready) { return <> } if (!user) { route(prependBaseUrl('/login'), true) return <> } const { logout } = useUserFunctions()! const handleLogout = async () => { await logout() route(prependBaseUrl('/')) } const [solutions, refreshSolutions] = useResource(`/api/solutions?user=${user.id}`, []) const sortedSolutions = sortByStringKey(solutions, s => s.createdAt, false) return ( <>
Profilo
Vai alla tua pagina pubblica {sortedSolutions.length > 0 && ( <>
Le tue soluzioni
{sortedSolutions.map(solution => ( ))}
)}
) }