mirror of
https://github.com/He4eT/huge-link.git
synced 2026-05-05 00:47:27 +00:00
Add encoding for posts
This commit is contained in:
parent
49a57910dd
commit
ac2051a104
1 changed files with 22 additions and 9 deletions
|
|
@ -2,24 +2,37 @@ import {h} from 'preact'
|
|||
import {Link} from 'preact-router/match'
|
||||
import ReactMarkdown from 'react-markdown'
|
||||
|
||||
const emptyControls = null
|
||||
const previewContorls = 'controls placeholder'
|
||||
const previewContorls = content => (
|
||||
<header><nav>
|
||||
<ul>
|
||||
<li><Link href='/'>
|
||||
Edit
|
||||
</Link></li>
|
||||
<li><Link href={ `/p/${content}` }>
|
||||
Publish
|
||||
</Link></li>
|
||||
</ul>
|
||||
</nav></header>)
|
||||
|
||||
const noop = _ => _
|
||||
const decode = noop
|
||||
const noop = _ => null
|
||||
const ident = _ => _
|
||||
|
||||
const decode = x => decodeURIComponent(atob(x))
|
||||
const encode = x => btoa(encodeURIComponent(x))
|
||||
|
||||
const Post = ({mode, payload, setMarkdown}) => {
|
||||
const [controls, decodeFn] = {
|
||||
preview: [previewContorls, noop],
|
||||
post: [emptyControls, decode]
|
||||
const [controls, decodeFn, encodeFn] = {
|
||||
preview: [previewContorls, ident, encode],
|
||||
post: [noop, decode, ident]
|
||||
}[mode]
|
||||
|
||||
const markdown = decodeFn(payload)
|
||||
const encoded = encodeFn(payload)
|
||||
|
||||
setMarkdown(markdown)
|
||||
|
||||
return (<section>
|
||||
{ controls }
|
||||
{ controls(encoded) }
|
||||
|
||||
<article>
|
||||
<ReactMarkdown>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue