aboutsummaryrefslogtreecommitdiffstats
path: root/frontend/app/Main.hs
diff options
context:
space:
mode:
authorLibravatar Alexander Foremny <aforemny@posteo.de>2024-06-07 17:08:01 +0200
committerLibravatar Alexander Foremny <aforemny@posteo.de>2024-06-08 09:56:20 +0200
commit2e67bf911533a66b5a5b7b50481b426adff8c7db (patch)
tree71481ebe7602ea3d5c84438d0ca829e26ca75a2a /frontend/app/Main.hs
parent8a34cc822c2c508472fe29ab2be1b74ba06e59e6 (diff)
reload collections when creating
Diffstat (limited to 'frontend/app/Main.hs')
-rw-r--r--frontend/app/Main.hs23
1 files changed, 21 insertions, 2 deletions
diff --git a/frontend/app/Main.hs b/frontend/app/Main.hs
index 3a2c5a6..67f1938 100644
--- a/frontend/app/Main.hs
+++ b/frontend/app/Main.hs
@@ -5,9 +5,12 @@ import Language.Javascript.JSaddle.Warp as JSaddle
#endif
import Api
+import Control.Monad.Trans
import Data.Bifunctor
import Data.Default
import Data.Function
+import Effect (Eff)
+import Effect qualified as E
import Miso
import Miso.String (toMisoString)
import NeatInterpolation qualified as Q
@@ -41,6 +44,8 @@ data Action
| HandleURI URI
| HandlePage Page.Action
| SetPage (Either String Page)
+ | HandleEff Eff
+ | SetCollections (Either String [String])
deriving (Show, Eq)
#ifndef ghcjs_HOST_OS
@@ -90,9 +95,23 @@ updateModel (HandlePage action) (Loaded s) =
case s.page of
Just (Right page) ->
fmap Loaded $
- updatePage action page
- & bimap HandlePage (\page -> s {page = Just (Right page)})
+ ( case updatePage action page
+ & first (bimap HandlePage (\page -> s {page = Just (Right page)}))
+ & second (map HandleEff)
+ & second (map (\eff -> (\sink -> liftIO (sink eff)))) of
+ (Effect s' ss, ss') ->
+ Effect s' (ss ++ ss')
+ )
_ -> noEff (Loaded s)
+updateModel (HandleEff eff) (Loaded s) = Loaded s <# handleEff eff
+updateModel (SetCollections (Left err)) (Loaded s) =
+ Loaded s <# do
+ pure NoOp <* consoleLog (toMisoString err)
+updateModel (SetCollections (Right collections)) (Loaded s) =
+ noEff (Loaded s {collections})
+
+handleEff :: Eff -> JSM Action
+handleEff E.ReloadCollections = SetCollections <$> fetchCollections
viewModel :: Model -> View Action
viewModel Loading = text ".."