Full refactor to Typescript
parent
de3f10b3ee
commit
ffd3c99292
@ -1,9 +1,9 @@
|
|||||||
export const server = {
|
export const server = {
|
||||||
async get(url) {
|
async get(url: string) {
|
||||||
const res = await fetch(url, { credentials: 'include' })
|
const res = await fetch(url, { credentials: 'include' })
|
||||||
return await res.json()
|
return await res.json()
|
||||||
},
|
},
|
||||||
async post(url, body) {
|
async post<T>(url: string, body?: T) {
|
||||||
const res = await fetch(url, {
|
const res = await fetch(url, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
credentials: 'include',
|
credentials: 'include',
|
@ -1,12 +1,18 @@
|
|||||||
import { Link } from 'preact-router/match'
|
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 = {
|
const ROLE_LABEL: Record<UserRole, string> = {
|
||||||
[USER_ROLE_ADMIN]: 'Admin',
|
['admin']: 'Admin',
|
||||||
[USER_ROLE_MODERATOR]: 'Moderatore',
|
['moderator']: 'Moderatore',
|
||||||
|
['student']: 'Studente',
|
||||||
}
|
}
|
||||||
|
|
||||||
export const Header = ({ user, noLogin }) => (
|
type Props = {
|
||||||
|
user?: User | null
|
||||||
|
noLogin?: boolean
|
||||||
|
}
|
||||||
|
|
||||||
|
export const Header = ({ user, noLogin }: Props) => (
|
||||||
<header>
|
<header>
|
||||||
<div class="logo">
|
<div class="logo">
|
||||||
<a href="/">PHC / Problemi</a>
|
<a href="/">PHC / Problemi</a>
|
@ -1,12 +0,0 @@
|
|||||||
export const Select = ({ options, value, setValue }) => (
|
|
||||||
<div class="input-select">
|
|
||||||
<select onInput={e => setValue?.(e.target.value)}>
|
|
||||||
{Object.entries(options).map(([k, v]) => (
|
|
||||||
<option value={k} selected={value === k}>
|
|
||||||
{v}
|
|
||||||
</option>
|
|
||||||
))}
|
|
||||||
</select>
|
|
||||||
<span class="material-symbols-outlined">expand_more</span>
|
|
||||||
</div>
|
|
||||||
)
|
|
@ -0,0 +1,23 @@
|
|||||||
|
import { StateUpdater } from 'preact/hooks'
|
||||||
|
import { JSX } from 'preact/jsx-runtime'
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
options: Record<string, string>
|
||||||
|
value: string
|
||||||
|
setValue?: StateUpdater<string>
|
||||||
|
}
|
||||||
|
|
||||||
|
export const Select = ({ options, value, setValue }: Props) => (
|
||||||
|
<div class="input-select">
|
||||||
|
<select
|
||||||
|
onInput={e => setValue?.(e.target instanceof HTMLSelectElement ? e.target.value : '')}
|
||||||
|
>
|
||||||
|
{Object.entries(options).map(([k, v]) => (
|
||||||
|
<option value={k} selected={value === k}>
|
||||||
|
{v}
|
||||||
|
</option>
|
||||||
|
))}
|
||||||
|
</select>
|
||||||
|
<span class="material-symbols-outlined">expand_more</span>
|
||||||
|
</div>
|
||||||
|
)
|
@ -1,25 +1,29 @@
|
|||||||
import { refToUserId } from '../../shared/db-refs.js'
|
import { ProblemId, SolutionStatus, UserId } from '../../shared/model'
|
||||||
import { Markdown } from './Markdown.jsx'
|
import { Markdown } from './Markdown'
|
||||||
|
|
||||||
export const Solution = ({ sentBy, forProblem, content }) => {
|
type Props = {
|
||||||
const userId = refToUserId(sentBy)
|
sentBy?: UserId
|
||||||
const problemId = refToUserId(forProblem)
|
forProblem: ProblemId
|
||||||
|
content: string
|
||||||
|
status?: SolutionStatus
|
||||||
|
}
|
||||||
|
|
||||||
|
export const Solution = ({ sentBy, forProblem, content }: Props) => {
|
||||||
return (
|
return (
|
||||||
<div class="solution">
|
<div class="solution">
|
||||||
<div class="solution-header">
|
<div class="solution-header">
|
||||||
<div>
|
<div>
|
||||||
Soluzione
|
Soluzione
|
||||||
{userId && (
|
{sentBy && (
|
||||||
<>
|
<>
|
||||||
{' '}
|
{' '}
|
||||||
di <a href={`/user/${userId}`}>@{userId}</a>
|
di <a href={`/user/${sentBy}`}>@{sentBy}</a>
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
{problemId && (
|
{forProblem && (
|
||||||
<>
|
<>
|
||||||
{' '}
|
{' '}
|
||||||
per il <a href={`/problem/${problemId}`}>Problema {problemId}</a>
|
per il <a href={`/problem/${forProblem}`}>Problema {forProblem}</a>
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
@ -1,4 +1,4 @@
|
|||||||
import { hydrate } from 'preact'
|
import { hydrate } from 'preact'
|
||||||
import { App } from './App'
|
import { App } from './App'
|
||||||
|
|
||||||
// hydrate(<App />, document.body)
|
hydrate(<App />, document.body)
|
||||||
|
Loading…
Reference in New Issue