all: Aggiunte varie feature e riscritte svariate cose

This commit is contained in:
2022-12-01 03:45:29 +01:00
parent bd055f484d
commit 8fdef2981d
22 changed files with 714 additions and 422 deletions
+7 -10
View File
@@ -3,11 +3,14 @@ import { StateUpdater, useEffect, useRef } from 'preact/hooks'
import { Markdown } from './Markdown'
type Props = {
placeholder?: string
source: string
setSource: StateUpdater<string>
}
export const MarkdownEditor = ({ source, setSource }: Props) => {
export const MarkdownEditor = ({ placeholder, source, setSource }: Props) => {
placeholder ??= 'Scrivi qualcosa...'
const editorRef = useRef<HTMLTextAreaElement>(null)
useEffect(() => {
@@ -28,23 +31,17 @@ export const MarkdownEditor = ({ source, setSource }: Props) => {
<div class="editor">
<h1>Editor</h1>
<textarea
onInput={e =>
setSource(e.target instanceof HTMLTextAreaElement ? e.target.value : '')
}
onInput={e => setSource(e.target instanceof HTMLTextAreaElement ? e.target.value : '')}
value={source}
cols={60}
ref={editorRef}
placeholder="Scrivi una nuova soluzione..."
placeholder={placeholder}
></textarea>
</div>
<div class="preview">
<h1>Preview</h1>
<div class="preview-content">
{source.trim().length ? (
<Markdown source={source} />
) : (
<div class="placeholder">Scrivi una nuova soluzione...</div>
)}
{source.trim().length ? <Markdown source={source} /> : <div class="placeholder">{placeholder}</div>}
</div>
</div>
</div>