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.
59 lines
2.1 KiB
TypeScript
59 lines
2.1 KiB
TypeScript
import { isAdministrator, Solution as SolutionModel, SolutionStat } 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 } from '../hooks/useCurrentUser'
|
|
|
|
type RouteProps = {
|
|
uid: string
|
|
}
|
|
|
|
export const UserPage = ({ uid }: RouteProps) => {
|
|
const [user, ready] = useCurrentUser()
|
|
if (!ready) {
|
|
return <></>
|
|
}
|
|
|
|
const [stats] = useResource<null | Record<string, SolutionStat | undefined>>(`/api/stats`, null)
|
|
if (!stats) {
|
|
return <></>
|
|
}
|
|
|
|
const userStats = stats[uid]
|
|
|
|
const [solutions, refreshSolutions] = useResource<SolutionModel[]>(`/api/solutions?user=${uid}&public`, [])
|
|
const sortedSolutions = sortByStringKey(solutions, s => s.createdAt, false)
|
|
|
|
return (
|
|
<>
|
|
<Header />
|
|
<main class="page-profile">
|
|
<div class="title">
|
|
Profilo di <a href={prependBaseUrl(`/u/${uid}`)}>{user?.fullName}</a>
|
|
</div>
|
|
<hr />
|
|
<div class="subtitle">Statistiche</div>
|
|
<div class="info">
|
|
<div>Soluzioni inviate</div>
|
|
<div>Soluzioni corrette</div>
|
|
<div class="info-box">{userStats?.sentSolutionsCount ?? 0}</div>
|
|
<div class="info-box">{userStats?.correctSolutionsCount ?? 0}</div>
|
|
</div>
|
|
<hr />
|
|
<div class="subtitle">Soluzioni notevoli</div>
|
|
<div class="solution-list">
|
|
{sortedSolutions.map(solution => (
|
|
<Solution
|
|
refreshSolution={refreshSolutions}
|
|
{...solution}
|
|
adminControls={user !== null && isAdministrator(user.role)}
|
|
/>
|
|
))}
|
|
</div>
|
|
</main>
|
|
</>
|
|
)
|
|
}
|