Skip to content

Commit 8fd988b

Browse files
committed
Pass paper planes flying by
1 parent 77e572f commit 8fd988b

File tree

8 files changed

+40
-2
lines changed

8 files changed

+40
-2
lines changed

src/Client/Experiments/Update.purs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff 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

5876
afterCatchPlane Int ExperimentsModel ExperimentsModel /\ (Array (Aff (Maybe ExperimentsMessage)))
5977
afterCatchPlane id model =

src/Server/Experiments/Action.purs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,5 +53,8 @@ throwPlane loggedUserId message = do
5353
catchPlane Int Int ServerEffect Unit
5454
catchPlane loggedUserId id = SED.updatePlaneStatus loggedUserId id Caught
5555

56+
passPlane Int Int ServerEffect Unit
57+
passPlane loggedUserId id = SED.updatePlaneBy loggedUserId id
58+
5659
flyingPlanes Int ServerEffect (Array PaperPlane)
5760
flyingPlanes loggedUserId = SED.fetchPaperPlanesFlying loggedUserId

src/Server/Experiments/Database.purs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ countPaperPlanes loggedUserId = do
7474
updatePlaneStatus Int Int -> PaperPlaneStatus -> ServerEffect Unit
7575
updatePlaneStatus 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+
7780
fetchPaperPlanes Int ServerEffect (Array PaperPlane)
7881
fetchPaperPlanes loggedUserId = SD.query $ select (_id /\ _message /\ _status) # from paper_planes # wher (_thrower .=. loggedUserId .&&. _status .<>. Crashed) # orderBy _created
7982

src/Server/Experiments/Handler.purs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff 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+
3742
flying { guards { loggedUserId Int } } ServerEffect (Array PaperPlane)
3843
flying request = SEA.flyingPlanes request.guards.loggedUserId
3944

src/Server/Handler.purs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff 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

src/Shared/Experiments/PaperPlane.purs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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
]

src/Shared/Experiments/Types.purs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff 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

5456
type Match =
5557
{ name String

src/Shared/Spec.purs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff 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)

0 commit comments

Comments
 (0)