feat: aggiunte feature per l'admin e cambiamenti stilistici minori
This commit is contained in:
+42
-39
@@ -11,45 +11,48 @@ type RouteProps = {
|
||||
}
|
||||
|
||||
export const UserPage = ({ uid }: RouteProps) => {
|
||||
const [user] = useCurrentUser()
|
||||
|
||||
const [stats] = useResource<null | Record<string, SolutionStat>>(`/api/stats`, null)
|
||||
if (stats) {
|
||||
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}`)}>@{uid}</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}</div>
|
||||
<div class="info-box">{userStats.correctSolutionsCount}</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>
|
||||
</>
|
||||
)
|
||||
} else {
|
||||
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>
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user