chore: make title modifiable, fix inital db value
This commit is contained in:
@@ -34,4 +34,4 @@ $ prettier -w '**/*.ts' '**/*.tsx'
|
|||||||
|
|
||||||
# TODO
|
# TODO
|
||||||
|
|
||||||
- [ ] Autenticazione vera magari con OAuth dell'ateneo o Google
|
- [x] Autenticazione vera magari con OAuth dell'ateneo o Google
|
||||||
@@ -14,13 +14,14 @@ import { useCurrentUser } from '../hooks/useCurrentUser'
|
|||||||
|
|
||||||
const CreateProblem = ({}) => {
|
const CreateProblem = ({}) => {
|
||||||
const [source, setSource] = useState('')
|
const [source, setSource] = useState('')
|
||||||
|
const [title, setTitle] = useState('')
|
||||||
|
|
||||||
type ProblemFields = {
|
type ProblemFields = {
|
||||||
title?: string
|
title?: string
|
||||||
content: string
|
content: string
|
||||||
}
|
}
|
||||||
|
|
||||||
const createProblem = async () => {
|
const handleCreateProblem = async () => {
|
||||||
if (source.trim().length === 0) {
|
if (source.trim().length === 0) {
|
||||||
alert('Il campo di testo è vuoto!')
|
alert('Il campo di testo è vuoto!')
|
||||||
return
|
return
|
||||||
@@ -28,6 +29,7 @@ const CreateProblem = ({}) => {
|
|||||||
|
|
||||||
const id = await server.post<ProblemFields>('/api/problem', {
|
const id = await server.post<ProblemFields>('/api/problem', {
|
||||||
content: source,
|
content: source,
|
||||||
|
title,
|
||||||
})
|
})
|
||||||
|
|
||||||
route(prependBaseUrl(`/problem/${id}`))
|
route(prependBaseUrl(`/problem/${id}`))
|
||||||
@@ -35,8 +37,17 @@ const CreateProblem = ({}) => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
<div class="problem-title">
|
||||||
|
<label>Titolo</label>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
value={title}
|
||||||
|
onInput={e => setTitle(e.target instanceof HTMLInputElement ? e.target.value : '')}
|
||||||
|
placeholder="Problema..."
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
<MarkdownEditor placeholder="Scrivi un nuovo problema..." {...{ source, setSource }} />
|
<MarkdownEditor placeholder="Scrivi un nuovo problema..." {...{ source, setSource }} />
|
||||||
<button onClick={createProblem}>Aggiungi Problema</button>
|
<button onClick={handleCreateProblem}>Aggiungi Problema</button>
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -123,6 +134,8 @@ export const AdminPage = ({}) => {
|
|||||||
<>
|
<>
|
||||||
<hr />
|
<hr />
|
||||||
<div class="subtitle">Controlli speciali solo per Admin</div>
|
<div class="subtitle">Controlli speciali solo per Admin</div>
|
||||||
|
|
||||||
|
{/* TODO: make this work */}
|
||||||
<div class="scrollable">
|
<div class="scrollable">
|
||||||
<div class="users-table" style={{ '--cols': 4 }}>
|
<div class="users-table" style={{ '--cols': 4 }}>
|
||||||
<div class="cell header">Username Ateneo</div>
|
<div class="cell header">Username Ateneo</div>
|
||||||
|
|||||||
@@ -53,6 +53,7 @@ export const ProblemPage = ({ id }: RouteProps) => {
|
|||||||
|
|
||||||
const [editing, setEditing] = useState<boolean>(false)
|
const [editing, setEditing] = useState<boolean>(false)
|
||||||
const [modifiedProblemSource, setModifiedProblemSource] = useState<string>('')
|
const [modifiedProblemSource, setModifiedProblemSource] = useState<string>('')
|
||||||
|
const [modifiedProblemTitle, setModifiedProblemTitle] = useState<string>(problem?.title ?? '')
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (problem) {
|
if (problem) {
|
||||||
@@ -63,6 +64,7 @@ export const ProblemPage = ({ id }: RouteProps) => {
|
|||||||
const updateProblem = async () => {
|
const updateProblem = async () => {
|
||||||
await server.patch(`/api/problem/${id}`, {
|
await server.patch(`/api/problem/${id}`, {
|
||||||
content: modifiedProblemSource,
|
content: modifiedProblemSource,
|
||||||
|
title: modifiedProblemTitle,
|
||||||
})
|
})
|
||||||
refreshProblem()
|
refreshProblem()
|
||||||
setEditing(false)
|
setEditing(false)
|
||||||
@@ -92,6 +94,15 @@ export const ProblemPage = ({ id }: RouteProps) => {
|
|||||||
</>
|
</>
|
||||||
) : (
|
) : (
|
||||||
<>
|
<>
|
||||||
|
<div class="problem-title">
|
||||||
|
<label>Titolo</label>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
value={modifiedProblemTitle}
|
||||||
|
onInput={e => setModifiedProblemTitle(e.target instanceof HTMLInputElement ? e.target.value : '')}
|
||||||
|
placeholder="Problema..."
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
<MarkdownEditor
|
<MarkdownEditor
|
||||||
placeholder="Modifica testo del problema..."
|
placeholder="Modifica testo del problema..."
|
||||||
source={modifiedProblemSource}
|
source={modifiedProblemSource}
|
||||||
|
|||||||
+17
-7
@@ -281,6 +281,18 @@ $heading-scale: 1.25;
|
|||||||
// Components
|
// Components
|
||||||
//
|
//
|
||||||
|
|
||||||
|
.row {
|
||||||
|
display: flex;
|
||||||
|
gap: 0.5rem;
|
||||||
|
align-items: center;
|
||||||
|
|
||||||
|
@media screen and (max-width: $device-s-width), (pointer: coarse) {
|
||||||
|
flex-direction: column;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
.text-body {
|
.text-body {
|
||||||
font-family: 'EB Garamond', serif;
|
font-family: 'EB Garamond', serif;
|
||||||
font-weight: 400;
|
font-weight: 400;
|
||||||
@@ -362,7 +374,7 @@ main.page-home {
|
|||||||
// min-width: 0;
|
// min-width: 0;
|
||||||
|
|
||||||
display: grid;
|
display: grid;
|
||||||
grid-template-columns: repeat(auto-fit, minmax(auto, 70ch));
|
grid-template-columns: repeat(auto-fit, minmax(auto, 71ch));
|
||||||
gap: 2rem;
|
gap: 2rem;
|
||||||
|
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
@@ -699,12 +711,6 @@ header {
|
|||||||
font-weight: 400;
|
font-weight: 400;
|
||||||
}
|
}
|
||||||
|
|
||||||
.row {
|
|
||||||
display: flex;
|
|
||||||
gap: 0.5rem;
|
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
|
|
||||||
.pending {
|
.pending {
|
||||||
color: #1653a3;
|
color: #1653a3;
|
||||||
font-style: italic;
|
font-style: italic;
|
||||||
@@ -810,6 +816,10 @@ header {
|
|||||||
//
|
//
|
||||||
|
|
||||||
main.page-admin {
|
main.page-admin {
|
||||||
|
.problem-title {
|
||||||
|
@extend .row;
|
||||||
|
}
|
||||||
|
|
||||||
.users-table {
|
.users-table {
|
||||||
@extend .table;
|
@extend .table;
|
||||||
|
|
||||||
|
|||||||
@@ -121,11 +121,10 @@ export const createUser: (db: DatabaseConnection, user: User) => Promise<void> =
|
|||||||
|
|
||||||
export const createProblem = (db: DatabaseConnection, { title, content, createdBy }: Omit<Problem, MetaProps>): Promise<ProblemId> =>
|
export const createProblem = (db: DatabaseConnection, { title, content, createdBy }: Omit<Problem, MetaProps>): Promise<ProblemId> =>
|
||||||
withDatabase(db, state => {
|
withDatabase(db, state => {
|
||||||
const problemIds = Object.keys(state.problems)
|
const id = crypto.randomBytes(4).toString('hex') as ProblemId
|
||||||
const nextId = (problemIds.length > 0 ? String(parseInt(problemIds.at(-1)!) + 1) : '1') as ProblemId
|
|
||||||
|
|
||||||
state.problems[nextId] = {
|
state.problems[id] = {
|
||||||
id: nextId,
|
id,
|
||||||
createdAt: new Date().toJSON(),
|
createdAt: new Date().toJSON(),
|
||||||
deleted: false,
|
deleted: false,
|
||||||
|
|
||||||
@@ -134,7 +133,7 @@ export const createProblem = (db: DatabaseConnection, { title, content, createdB
|
|||||||
createdBy,
|
createdBy,
|
||||||
}
|
}
|
||||||
|
|
||||||
return nextId
|
return id
|
||||||
})
|
})
|
||||||
|
|
||||||
export const getProblem = (db: DatabaseConnection, id: string): Promise<Problem | null> =>
|
export const getProblem = (db: DatabaseConnection, id: string): Promise<Problem | null> =>
|
||||||
|
|||||||
@@ -2,16 +2,7 @@ import { UserId } from '../../shared/model'
|
|||||||
import { Database } from './database'
|
import { Database } from './database'
|
||||||
|
|
||||||
export const initialDatabaseValue: Database = {
|
export const initialDatabaseValue: Database = {
|
||||||
users: {
|
users: {},
|
||||||
['BachoSeven']: {
|
|
||||||
id: 'BachoSeven' as UserId,
|
|
||||||
role: 'admin',
|
|
||||||
},
|
|
||||||
['aziis98']: {
|
|
||||||
id: 'aziis98' as UserId,
|
|
||||||
role: 'admin',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
problems: {},
|
problems: {},
|
||||||
solutions: {},
|
solutions: {},
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user