mirror of
https://github.com/He4eT/huge-link.git
synced 2026-05-04 16:37:23 +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 {Link} from 'preact-router/match'
|
||||||
import ReactMarkdown from 'react-markdown'
|
import ReactMarkdown from 'react-markdown'
|
||||||
|
|
||||||
const emptyControls = null
|
const previewContorls = content => (
|
||||||
const previewContorls = 'controls placeholder'
|
<header><nav>
|
||||||
|
<ul>
|
||||||
|
<li><Link href='/'>
|
||||||
|
Edit
|
||||||
|
</Link></li>
|
||||||
|
<li><Link href={ `/p/${content}` }>
|
||||||
|
Publish
|
||||||
|
</Link></li>
|
||||||
|
</ul>
|
||||||
|
</nav></header>)
|
||||||
|
|
||||||
const noop = _ => _
|
const noop = _ => null
|
||||||
const decode = noop
|
const ident = _ => _
|
||||||
|
|
||||||
|
const decode = x => decodeURIComponent(atob(x))
|
||||||
|
const encode = x => btoa(encodeURIComponent(x))
|
||||||
|
|
||||||
const Post = ({mode, payload, setMarkdown}) => {
|
const Post = ({mode, payload, setMarkdown}) => {
|
||||||
const [controls, decodeFn] = {
|
const [controls, decodeFn, encodeFn] = {
|
||||||
preview: [previewContorls, noop],
|
preview: [previewContorls, ident, encode],
|
||||||
post: [emptyControls, decode]
|
post: [noop, decode, ident]
|
||||||
}[mode]
|
}[mode]
|
||||||
|
|
||||||
const markdown = decodeFn(payload)
|
const markdown = decodeFn(payload)
|
||||||
|
const encoded = encodeFn(payload)
|
||||||
|
|
||||||
setMarkdown(markdown)
|
setMarkdown(markdown)
|
||||||
|
|
||||||
return (<section>
|
return (<section>
|
||||||
{ controls }
|
{ controls(encoded) }
|
||||||
|
|
||||||
<article>
|
<article>
|
||||||
<ReactMarkdown>
|
<ReactMarkdown>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue