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.
|
|
const moment = require("moment")
module.exports = class { onCreate() { this.state = {text: null, color: "color-menu", href: null, tooltip: null} }
onInput(input) { if (this.state != null) { this.updateState(input) } }
updateState({kind, weak, value, updated}) { this.state = {text: null, color: "color-menu", href: null, tooltip: null}
if (value == null || value == "") { return }
switch (kind) { case "date": { const m = moment(value) if (m.year() < 2) { break }
if (!weak) { this.state.tooltip = `See all stories set during ${m.format("MMMM YYYY")}` this.state.href = `/story/by-month/${m.format("YYYY-MM")}/` }
const dateStr = m.format("MMM D, YYYY")
this.state.text = dateStr
if (updated != null && Date.parse(updated) > Date.parse(value)) { const m2 = moment(updated) this.state.tooltip = "Originally posted: " + dateStr this.state.text = m2.format("MMM D, YYYY") + " *" }
break } case "author": { this.state.text = value this.state.tooltip = "See all stories by " + value this.state.href = `/story/by-author/${value}/`
break } default: { this.state.color = "color-menu" this.state.text = value
break } } } }
|