Update project list every time we get the project list page.

This commit is contained in:
Philippe PITTOLI 2019-12-06 21:46:40 +01:00
parent 5fa8f32d77
commit fb46723759

View File

@ -163,19 +163,19 @@ model.todod-ws.user-on-socket-error ++= [ on-websocket-error ]
model.todod-ws.user-on-socket-close ++= [ on-websocket-close ] model.todod-ws.user-on-socket-close ++= [ on-websocket-close ]
model.todod-ws.add-event-listener \lists-list, (message) -> model.todod-ws.add-event-listener \lists-list, (message) ->
# console.log message console.log "Project list received", message
model.project-list := message.lists.map (x) -> model.project-list := message.lists.map (x) ->
Project x, model.todod-ws Project x, model.todod-ws
projector.schedule-render! projector.schedule-render!
model.todod-ws.add-event-listener \new-list, (message) -> model.todod-ws.add-event-listener \new-list, (message) ->
console.log message console.log "New project", message
model.project-list := model.project-list ++ [ (Project message.list, model.todod-ws) ] model.project-list := model.project-list ++ [ (Project message.list, model.todod-ws) ]
projector.schedule-render! projector.schedule-render!
model.todod-ws.add-event-listener \list-updated, (message) -> model.todod-ws.add-event-listener \list-updated, (message) ->
console.log message console.log "Project updated", message
new-project = Project message.list, model.todod-ws new-project = Project message.list, model.todod-ws
@ -194,12 +194,11 @@ model.todod-ws.add-event-listener \tasks, (message) ->
console.log "Tasks received", message console.log "Tasks received", message
project = model.project-list.find((.id == message.list)) project = model.project-list.find((.id == message.list))
model.project-list.find((.id == message.list)).tasks := message.tasks.map (e) -> Task e, project, model.todod-ws model.project-list.find((.id == message.list)).tasks := message.tasks.map (e) -> Task e, project, model.todod-ws
console.log "Once done: ", model.project-list.find((.id == message.list)).tasks
projector.schedule-render! projector.schedule-render!
model.todod-ws.add-event-listener \list-removed, (message) -> model.todod-ws.add-event-listener \list-removed, (message) ->
console.log "A list has been removed", message console.log "A list has been removed", message
if model.current-view == "project" && model.viewed-project == message.list if model.current-view == "project" && model.viewed-project.id == message.list
model.current-view := "project-list" model.current-view := "project-list"
model.viewed-project := void model.viewed-project := void
projector.schedule-render! projector.schedule-render!
@ -249,6 +248,7 @@ render-navbar = ->
h \a.navbar-item.is-size-2 { h \a.navbar-item.is-size-2 {
onclick: -> onclick: ->
model.todod-ws.unsubscribe model.viewed-project.id model.todod-ws.unsubscribe model.viewed-project.id
model.todod-ws.list-lists!
model.viewed-project := void model.viewed-project := void
model.current-view := "project-list" model.current-view := "project-list"
} [ "⌂" ] } [ "⌂" ]
@ -269,7 +269,7 @@ render-project-list = ->
key: project.id key: project.id
onclick: -> onclick: ->
model.current-view := "project" model.current-view := "project"
model.viewed-project := project.id model.viewed-project := project
model.todod-ws.subscribe project.id model.todod-ws.subscribe project.id
model.todod-ws.get-list project.id model.todod-ws.get-list project.id
model.todod-ws.get-tasks project.id model.todod-ws.get-tasks project.id
@ -299,14 +299,12 @@ render-new-project-button = ->
} }
} [ "New project!" ] } [ "New project!" ]
render-project = (project-id) -> render-project = (project) ->
project = model.project-list.find((.id == project-id))
if project if project
project.render! project.render!
else else
h \div.notification.is-error [ h \div.notification.is-error [
bulma.title 3 "Error, we did not get the project id " + project-id bulma.title 3 "Error, we did not get the project id " + project.id
] ]
render-body = -> render-body = ->