diff --git a/client/App.tsx b/client/App.tsx index 28dace6..2d67f83 100644 --- a/client/App.tsx +++ b/client/App.tsx @@ -8,7 +8,7 @@ import { LoginPage } from './pages/Login' import { ProblemPage } from './pages/Problem' import { ProfilePage } from './pages/Profile' -const Redirect = ({ to }: { default: boolean; to: string }) => { +const Redirect = ({ to }: { to: string }) => { useEffect(() => { route(to, true) }, []) @@ -23,12 +23,31 @@ const Redirect = ({ to }: { default: boolean; to: string }) => { export const App = ({ url }: { url?: string }) => { return ( - - - - - - + + + + + + ) } diff --git a/client/api.jsx b/client/api.tsx similarity index 85% rename from client/api.jsx rename to client/api.tsx index b2e3135..dfb264a 100644 --- a/client/api.jsx +++ b/client/api.tsx @@ -1,9 +1,9 @@ export const server = { - async get(url) { + async get(url: string) { const res = await fetch(url, { credentials: 'include' }) return await res.json() }, - async post(url, body) { + async post(url: string, body?: T) { const res = await fetch(url, { method: 'POST', credentials: 'include', diff --git a/client/components/Header.jsx b/client/components/Header.tsx similarity index 77% rename from client/components/Header.jsx rename to client/components/Header.tsx index bd08868..238ad30 100644 --- a/client/components/Header.jsx +++ b/client/components/Header.tsx @@ -1,12 +1,18 @@ import { Link } from 'preact-router/match' -import { isAdministrator, USER_ROLE_ADMIN, USER_ROLE_MODERATOR } from '../../shared/constants.js' +import { isAdministrator, User, UserRole } from '../../shared/model' -const ROLE_LABEL = { - [USER_ROLE_ADMIN]: 'Admin', - [USER_ROLE_MODERATOR]: 'Moderatore', +const ROLE_LABEL: Record = { + ['admin']: 'Admin', + ['moderator']: 'Moderatore', + ['student']: 'Studente', } -export const Header = ({ user, noLogin }) => ( +type Props = { + user?: User | null + noLogin?: boolean +} + +export const Header = ({ user, noLogin }: Props) => (