Add user pages
parent
0f91536b10
commit
8bd33a8be3
@ -0,0 +1,33 @@
|
|||||||
|
import { isAdministrator, Solution as SolutionModel } 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] = useCurrentUser()
|
||||||
|
|
||||||
|
const [solutions, refreshSolutions] = useResource<SolutionModel[]>(`/api/solutions?user=${uid}`, [])
|
||||||
|
const sortedSolutions = sortByStringKey(solutions, s => s.createdAt, false)
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Header />
|
||||||
|
<main class="page-profile">
|
||||||
|
<div class="subtitle">Soluzioni di <a href={prependBaseUrl(`/u/${uid}`)}>@{uid}</a></div>
|
||||||
|
<div class="solution-list">
|
||||||
|
{sortedSolutions.map(solution => (
|
||||||
|
<Solution refreshSolution={refreshSolutions} {...solution} adminControls={user !== null && isAdministrator(user.role)} />
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</main>
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
Loading…
Reference in New Issue