The frontend/UI server, written in JS using the MarkoJS library
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

68 lines
1.4 KiB

const moment = require("moment")
const {postApi} = require("../../../../../rpdata/api/Post")
module.exports = class {
onCreate(input) {
this.state = {
error: null,
loading: false,
values: {
time: "",
kind: "",
nick: "",
text: "",
},
}
this.first = false
}
onInput(input) {
if (input.post) {
const {kind, nick, text} = input.post
const time = moment(input.post.time).format("YYYY-MM-DD HH:mm:ss")
this.state.values = {time, kind, nick, text}
}
}
change(key, ev) {
this.state.values[key] = ev.target.value
}
open() {
}
close() {
this.first = false
this.emit("close")
}
save() {
if (this.state.loading) {
return
}
const values = this.state.values
let time = new Date(values.time)
if (Number.isNaN(time)) {
this.state.error = `Could not parse ${values.time} as date`
return
}
const input = {id: this.input.post.id, time, kind: this.state.values.kind, nick: this.state.values.nick, text: this.state.values.text}
this.state.loading = true
postApi.edit(input).then(data => {
this.emit("edited", data)
this.emit("close")
}).catch(errs => {
console.warn("Failed to edit:", errs)
this.state.error = "Failed to edit: " + errs[0].message
}).then(() => {
this.state.loading = false
})
}
}