Add user pages
This commit is contained in:
@@ -11,6 +11,7 @@ import { LoginPage } from './pages/LoginPage'
|
|||||||
import { ProblemPage } from './pages/ProblemPage'
|
import { ProblemPage } from './pages/ProblemPage'
|
||||||
import { ProfilePage } from './pages/ProfilePage'
|
import { ProfilePage } from './pages/ProfilePage'
|
||||||
import { ScoresPage } from './pages/ScoresPage'
|
import { ScoresPage } from './pages/ScoresPage'
|
||||||
|
import { UserPage } from './pages/UserPage'
|
||||||
|
|
||||||
const Redirect = ({ to }: { to: string }) => {
|
const Redirect = ({ to }: { to: string }) => {
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -47,6 +48,10 @@ export const App = ({ url }: { url?: string }) => {
|
|||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
path={pbu('/problem/:id')}
|
path={pbu('/problem/:id')}
|
||||||
/>
|
/>
|
||||||
|
<UserPage
|
||||||
|
// @ts-ignore
|
||||||
|
path={pbu('/u/:uid')}
|
||||||
|
/>
|
||||||
<AdminPage
|
<AdminPage
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
path={pbu('/admin')}
|
path={pbu('/admin')}
|
||||||
|
|||||||
@@ -93,7 +93,7 @@ export const Solution = ({
|
|||||||
{sentBy && (
|
{sentBy && (
|
||||||
<>
|
<>
|
||||||
{' '}
|
{' '}
|
||||||
di <a href={prependBaseUrl(`/user/${sentBy}`)}>@{sentBy}</a>
|
di <a href={prependBaseUrl(`/u/${sentBy}`)}>@{sentBy}</a>
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
{forProblem && (
|
{forProblem && (
|
||||||
|
|||||||
@@ -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>
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -14,7 +14,7 @@ import { RenderFunction } from './shared/ssr'
|
|||||||
// Load ".env"
|
// Load ".env"
|
||||||
dotenv.config()
|
dotenv.config()
|
||||||
|
|
||||||
const HTML_ROUTES = ['/', '/login', '/problem/:id', '/admin', '/profile', '/scores']
|
const HTML_ROUTES = ['/', '/login', '/problem/:id', '/u/:uid', '/admin', '/profile', '/scores']
|
||||||
|
|
||||||
const config = {
|
const config = {
|
||||||
isDevelopment: process.env.MODE === 'development',
|
isDevelopment: process.env.MODE === 'development',
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import crypto from 'crypto'
|
|||||||
|
|
||||||
import { readFile, writeFile, access, constants } from 'fs/promises'
|
import { readFile, writeFile, access, constants } from 'fs/promises'
|
||||||
|
|
||||||
import { MetadataProps as MetaProps, Problem, ProblemId, Solution, SolutionId, User, UserId } from '../../shared/model'
|
import { MetadataProps as MetaProps, Problem, ProblemId, Solution, SolutionId, User } from '../../shared/model'
|
||||||
|
|
||||||
function once<T extends (...args: any) => any>(fn: T, message: string): T {
|
function once<T extends (...args: any) => any>(fn: T, message: string): T {
|
||||||
let flag = false
|
let flag = false
|
||||||
|
|||||||
@@ -24,7 +24,6 @@ import {
|
|||||||
} from './db/database'
|
} from './db/database'
|
||||||
|
|
||||||
import {
|
import {
|
||||||
Id,
|
|
||||||
isAdministrator,
|
isAdministrator,
|
||||||
isStudent,
|
isStudent,
|
||||||
Opaque,
|
Opaque,
|
||||||
|
|||||||
Reference in New Issue
Block a user