Add new compose view for writing root messages

This commit is contained in:
Christian Bundy 2019-09-19 13:18:48 -07:00
parent 270f62f57a
commit 28f62c8360
No known key found for this signature in database
GPG Key ID: EB541AAEF4366237
5 changed files with 51 additions and 0 deletions

View File

@ -23,6 +23,8 @@ const mentions = require('./pages/mentions')
const reply = require('./pages/reply')
const publishReply = require('./pages/publish-reply')
const image = require('./pages/image')
const compose = require('./pages/compose')
const publish = require('./pages/publish')
module.exports = (config) => {
const assets = new Koa()
@ -101,12 +103,20 @@ module.exports = (config) => {
const { message } = ctx.params
ctx.body = await reply(message, false)
})
.get('/compose/', async (ctx) => {
ctx.body = await compose()
})
.post('/reply/:message', koaBody(), async (ctx) => {
const { message } = ctx.params
const text = String(ctx.request.body.text)
ctx.body = await publishReply({ message, text })
ctx.redirect('/')
})
.post('/publish/', koaBody(), async (ctx) => {
const text = String(ctx.request.body.text)
ctx.body = await publish({ text })
ctx.redirect('/')
})
.post('/like/:message', koaBody(), async (ctx) => {
const { message } = ctx.params
// TODO: convert all so `message` is full message and `messageKey` is key

7
src/pages/compose.js Normal file
View File

@ -0,0 +1,7 @@
'use strict'
const composeView = require('./views/compose')
module.exports = async function composePage () {
return composeView()
}

12
src/pages/publish.js Normal file
View File

@ -0,0 +1,12 @@
'use strict'
const ssbMentions = require('ssb-mentions')
const post = require('./models/post')
module.exports = async function publishPage ({ text }) {
const mentions = ssbMentions(text) || undefined
return post.publish({
text,
mentions
})
}

View File

@ -30,6 +30,7 @@ module.exports = (...elements) => {
nav(
a({ href: '/' }, 'home'),
a({ href: '/mentions' }, 'mentions'),
a({ href: '/compose' }, 'compose'),
a({ href: '/profile' }, 'profile'),
a({ href: '/status' }, 'status'),
a({ href: 'https://github.com/fraction/oasis' }, 'source'),

View File

@ -0,0 +1,21 @@
'use strict'
const {
button,
form,
textarea
} = require('hyperaxe')
const template = require('./components/template')
module.exports = () => {
const publishForm = '/publish/'
return template(
form({ action: publishForm, method: 'post' },
textarea({ autofocus: true, required: true, name: 'text' }),
button({
type: 'submit'
}, 'publish (public!!!)'))
)
}