diff --git a/client/App.tsx b/client/App.tsx index d377ecf..53ee53f 100644 --- a/client/App.tsx +++ b/client/App.tsx @@ -11,6 +11,7 @@ import { LoginPage } from './pages/LoginPage' import { ProblemPage } from './pages/ProblemPage' import { ProfilePage } from './pages/ProfilePage' import { ScoresPage } from './pages/ScoresPage' +import { UserPage } from './pages/UserPage' const Redirect = ({ to }: { to: string }) => { useEffect(() => { @@ -47,6 +48,10 @@ export const App = ({ url }: { url?: string }) => { // @ts-ignore path={pbu('/problem/:id')} /> + {' '} - di @{sentBy} + di @{sentBy} )} {forProblem && ( diff --git a/client/pages/UserPage.tsx b/client/pages/UserPage.tsx new file mode 100644 index 0000000..ea9cb36 --- /dev/null +++ b/client/pages/UserPage.tsx @@ -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(`/api/solutions?user=${uid}`, []) + const sortedSolutions = sortByStringKey(solutions, s => s.createdAt, false) + + return ( + <> +
+
+
Soluzioni di @{uid}
+
+ {sortedSolutions.map(solution => ( + + ))} +
+
+ + ) +} \ No newline at end of file diff --git a/server.ts b/server.ts index 9f364f3..8b42fe9 100644 --- a/server.ts +++ b/server.ts @@ -14,7 +14,7 @@ import { RenderFunction } from './shared/ssr' // Load ".env" dotenv.config() -const HTML_ROUTES = ['/', '/login', '/problem/:id', '/admin', '/profile', '/scores'] +const HTML_ROUTES = ['/', '/login', '/problem/:id', '/u/:uid', '/admin', '/profile', '/scores'] const config = { isDevelopment: process.env.MODE === 'development', diff --git a/server/db/database.ts b/server/db/database.ts index e6feedb..14b689a 100644 --- a/server/db/database.ts +++ b/server/db/database.ts @@ -2,7 +2,7 @@ import crypto from 'crypto' 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 any>(fn: T, message: string): T { let flag = false diff --git a/server/routes.ts b/server/routes.ts index 9358f27..b4a686f 100644 --- a/server/routes.ts +++ b/server/routes.ts @@ -24,7 +24,6 @@ import { } from './db/database' import { - Id, isAdministrator, isStudent, Opaque,