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.
 
 
 
 

59 lines
1.4 KiB

const moment = require("moment")
const {postApi} = require("../../../../../rpdata/api/Post")
module.exports = class {
onCreate(input) {
this.state = {
log: input.log
}
}
/**
* Patch the posts
*
* @param {{id:string, [x:string]: any}[]} patches
*/
patch(patches) {
const posts = this.state.log.posts.slice()
for (const patch of patches) {
const index = posts.findIndex(p => p.id === patch.id)
if (index == -1) {
console.warn("Post not found for patch:", patch)
// TODO: Force full refresh
continue
}
posts[index] = Object.assign(Object.assign({}, posts[index]), patch)
}
// Sort posts and look for continuity issues (duplicate or skipped positions)
posts.sort((a, b) => a.position - b.position)
for (let i = 1; i < posts.length; ++i) {
if (posts[i].position !== posts[i - 1].position + 1) {
console.warn("Discontinuity detected!")
// TODO: Force full refresh
}
}
this.state.log.posts = posts
this.state.log = Object.assign({}, this.state.log)
}
movePost(post, toPosition) {
postApi.move({id: post.id, toPosition}).then(patches => {
this.patch(patches)
}).catch(err => {
console.warn(err)
})
}
get title() {
if (this.state.log.title) {
return this.state.log.title
}
return `${this.state.log.channel.name}${moment(this.state.log.date).format("MMMM D, YYYY")}`
}
}