Full refactor to Typescript
parent
de3f10b3ee
commit
ffd3c99292
@ -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<T>(url: string, body?: T) {
|
||||
const res = await fetch(url, {
|
||||
method: 'POST',
|
||||
credentials: 'include',
|
@ -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<UserRole, string> = {
|
||||
['admin']: 'Admin',
|
||||
['moderator']: 'Moderatore',
|
||||
['student']: 'Studente',
|
||||
}
|
||||
|
||||
export const Header = ({ user, noLogin }) => (
|
||||
type Props = {
|
||||
user?: User | null
|
||||
noLogin?: boolean
|
||||
}
|
||||
|
||||
export const Header = ({ user, noLogin }: Props) => (
|
||||
<header>
|
||||
<div class="logo">
|
||||
<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 { Markdown } from './Markdown.jsx'
|
||||
import { ProblemId, SolutionStatus, UserId } from '../../shared/model'
|
||||
import { Markdown } from './Markdown'
|
||||
|
||||
export const Solution = ({ sentBy, forProblem, content }) => {
|
||||
const userId = refToUserId(sentBy)
|
||||
const problemId = refToUserId(forProblem)
|
||||
type Props = {
|
||||
sentBy?: UserId
|
||||
forProblem: ProblemId
|
||||
content: string
|
||||
status?: SolutionStatus
|
||||
}
|
||||
|
||||
export const Solution = ({ sentBy, forProblem, content }: Props) => {
|
||||
return (
|
||||
<div class="solution">
|
||||
<div class="solution-header">
|
||||
<div>
|
||||
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>
|
@ -1,4 +1,4 @@
|
||||
import { hydrate } from 'preact'
|
||||
import { App } from './App'
|
||||
|
||||
// hydrate(<App />, document.body)
|
||||
hydrate(<App />, document.body)
|
||||
|
Loading…
Reference in New Issue