File tree Expand file tree Collapse file tree 8 files changed +40
-2
lines changed Expand file tree Collapse file tree 8 files changed +40
-2
lines changed Original file line number Diff line number Diff line change @@ -53,7 +53,25 @@ update model =
5353 TogglePaperPlaneSection section → togglePaperPlaneSection section model
5454 DisplayFlyingPaperPlanes planes → displayFlyingPaperPlanes planes model
5555 CatchPaperPlane id → catchPaperPlane id model
56- AfterCatchPlane id → afterCatchPlane id model
56+ AfterCatchPlane id → afterCatchPlane id model
57+ PassPaperPlane id → passPaperPlane id model
58+ AfterPassPlane id → afterPassPlane id model
59+
60+ afterPassPlane ∷ Int → ExperimentsModel → ExperimentsModel /\ (Array (Aff (Maybe ExperimentsMessage )))
61+ afterPassPlane id model =
62+ model
63+ { paperPlane = model.paperPlane
64+ { loading = false
65+ , flyingBy = DA .filter ((_ /= id) <<< _.id) model.paperPlane.flyingBy
66+ }
67+ } /\ []
68+
69+ passPaperPlane ∷ Int → ExperimentsModel → ExperimentsModel /\ (Array (Aff (Maybe ExperimentsMessage )))
70+ passPaperPlane id model = model { paperPlane = model.paperPlane { loading = true } } /\ [ setIt ]
71+ where
72+ setIt = do
73+ void <<< CCN .silentResponse $ request.experiments.pass { body: { id } }
74+ pure <<< Just $ AfterPassPlane id
5775
5876afterCatchPlane ∷ Int → ExperimentsModel → ExperimentsModel /\ (Array (Aff (Maybe ExperimentsMessage )))
5977afterCatchPlane id model =
Original file line number Diff line number Diff line change @@ -53,5 +53,8 @@ throwPlane loggedUserId message = do
5353catchPlane ∷ Int → Int → ServerEffect Unit
5454catchPlane loggedUserId id = SED .updatePlaneStatus loggedUserId id Caught
5555
56+ passPlane ∷ Int → Int → ServerEffect Unit
57+ passPlane loggedUserId id = SED .updatePlaneBy loggedUserId id
58+
5659flyingPlanes ∷ Int → ServerEffect (Array PaperPlane )
5760flyingPlanes loggedUserId = SED .fetchPaperPlanesFlying loggedUserId
Original file line number Diff line number Diff line change @@ -74,6 +74,9 @@ countPaperPlanes loggedUserId = do
7474updatePlaneStatus ∷ Int → Int -> PaperPlaneStatus -> ServerEffect Unit
7575updatePlaneStatus loggedUserId id status = SD .execute $ update paper_planes # set (_status .=. status) # wher (_id .=. id .&&. _by .=. loggedUserId)
7676
77+ updatePlaneBy ∷ Int → Int -> ServerEffect Unit
78+ updatePlaneBy loggedUserId id = SD .execute $ update paper_planes # set (_by .=. Nothing ) # wher (_id .=. id .&&. _by .=. loggedUserId)
79+
7780fetchPaperPlanes ∷ Int → ServerEffect (Array PaperPlane )
7881fetchPaperPlanes loggedUserId = SD .query $ select (_id /\ _message /\ _status) # from paper_planes # wher (_thrower .=. loggedUserId .&&. _status .<>. Crashed ) # orderBy _created
7982
Original file line number Diff line number Diff line change @@ -34,6 +34,11 @@ catch request = do
3434 SEA .catchPlane request.guards.loggedUserId request.body.id
3535 pure Empty
3636
37+ pass ∷ { guards ∷ { loggedUserId ∷ Int } , body ∷ { id :: Int } } → ServerEffect Empty
38+ pass request = do
39+ SEA .passPlane request.guards.loggedUserId request.body.id
40+ pure Empty
41+
3742flying ∷ { guards ∷ { loggedUserId ∷ Int } } → ServerEffect (Array PaperPlane )
3843flying request = SEA .flyingPlanes request.guards.loggedUserId
3944
Original file line number Diff line number Diff line change @@ -121,6 +121,7 @@ handlers reading =
121121 , answer: runJson reading SEH .answer
122122 , throw: runJson reading SEH .throw
123123 , catch: runJson reading SEH .catch
124+ , pass: runJson reading SEH .pass
124125 , flying: runJson reading SEH .flying
125126 }
126127 , sw
Original file line number Diff line number Diff line change @@ -51,7 +51,7 @@ flyingBy model =
5151 [ HE .div [ HA .class' " paper-flown-message" ] [ HE .text plane.message ]
5252 ]
5353 , HE .div [ HA .class' " paper-thrown-options" ]
54- [ HE .a [ HA .class' " paper-catch" ] [ HE .text " Pass" ]
54+ [ HE .a [ HA .class' " paper-catch" , HA .onClick $ PassPaperPlane plane.id ] [ HE .text " Pass" ]
5555 , HE .a [ HA .class' " paper-catch" , HA .onClick $ CatchPaperPlane plane.id ] [ HE .text " Catch!" ]
5656 ]
5757 ]
Original file line number Diff line number Diff line change @@ -50,6 +50,8 @@ data ExperimentsMessage
5050 | DisplayFlyingPaperPlanes (Array PaperPlane )
5151 | CatchPaperPlane Int
5252 | AfterCatchPlane Int
53+ | PassPaperPlane Int
54+ | AfterPassPlane Int
5355
5456type Match =
5557 { name ∷ String
Original file line number Diff line number Diff line change @@ -321,6 +321,12 @@ spec ∷
321321 , body ∷ { id ∷ Int }
322322 , response ∷ Empty
323323 }
324+ , pass ∷
325+ POST " /pass"
326+ { guards ∷ Guards (" loggedUserId" : Nil )
327+ , body ∷ { id ∷ Int }
328+ , response ∷ Empty
329+ }
324330 , flying ∷
325331 GET " /flying"
326332 { guards ∷ Guards (" loggedUserId" : Nil )
You can’t perform that action at this time.
0 commit comments