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.

46 lines
998 B

  1. module.exports = class {
  2. onCreate(input) {
  3. this.state = {
  4. publics: input.publics.sort(byDate),
  5. privates: input.privates.sort(byDate),
  6. modal: null,
  7. }
  8. }
  9. onMount() {
  10. }
  11. open(modal) {
  12. this.state.modal = modal
  13. }
  14. close() {
  15. this.state.modal = null
  16. }
  17. fileRemoved({id}) {
  18. this.state.publics = this.state.publics.filter(f => f.id !== id)
  19. this.state.privates = this.state.privates.filter(f => f.id !== id)
  20. }
  21. fileEdited(file, patch) {
  22. this.fileRemoved({id: file.id})
  23. this.fileAdded(Object.assign({}, file, patch))
  24. console.log(Object.assign({}, file, patch))
  25. }
  26. fileAdded(file) {
  27. if (file.public) {
  28. this.state.publics = [].concat(...this.state.publics).concat(file).sort(byDate)
  29. } else {
  30. this.state.privates = [].concat(...this.state.privates).concat(file).sort(byDate)
  31. }
  32. }
  33. }
  34. function byDate(a, b) {
  35. const ad = new Date(a.time)
  36. const bd = new Date(b.time)
  37. return ad.getTime() - bd.getTime()
  38. }