aboutsummaryrefslogtreecommitdiffstats
path: root/frontend/app
diff options
context:
space:
mode:
authorLibravatar Kierán Meinhardt <kmein@posteo.de>2024-10-13 09:55:20 +0200
committerLibravatar Kierán Meinhardt <kmein@posteo.de>2024-10-13 09:55:24 +0200
commit962db630a81a4040902c23c773df3069a48db0a3 (patch)
tree65c2208cd0fe98aa8979080cb22b84edc35253ef /frontend/app
parent895772f1e76d0cdf12eba5a579ce889d585c9072 (diff)
move Collection types to common
Diffstat (limited to 'frontend/app')
-rw-r--r--frontend/app/Page.hs6
-rw-r--r--frontend/app/Page/EditValue.hs16
-rw-r--r--frontend/app/Page/ListCollection.hs8
3 files changed, 16 insertions, 14 deletions
diff --git a/frontend/app/Page.hs b/frontend/app/Page.hs
index c7b393f..e1c8415 100644
--- a/frontend/app/Page.hs
+++ b/frontend/app/Page.hs
@@ -7,12 +7,14 @@ module Page
)
where
+import Collection
import Control.Monad.Catch (SomeException)
import Data.Bifunctor
import Data.Default
import Data.Function
import Effect (Eff)
import Miso
+import Miso.String (fromMisoString)
import Page.EditValue qualified as EditValue
import Page.ListCollection qualified as ListCollection
import Page.NewCollection qualified as NewCollection
@@ -34,9 +36,9 @@ instance Default Page where
initialPage :: Route -> JSM (Either SomeException Page)
initialPage Route.Home = pure (Right Home)
initialPage (Route.ListCollection c) =
- fmap ListCollection <$> ListCollection.initialModel c
+ fmap ListCollection <$> ListCollection.initialModel (Collection (fromMisoString c))
initialPage (Route.EditValue c f) =
- fmap EditValue <$> EditValue.initialModel c f
+ fmap EditValue <$> EditValue.initialModel (CollectionItem (Collection (fromMisoString c)) (fromMisoString f))
initialPage Route.NewCollection =
fmap NewCollection <$> NewCollection.initialModel
diff --git a/frontend/app/Page/EditValue.hs b/frontend/app/Page/EditValue.hs
index feacd4a..4ff867f 100644
--- a/frontend/app/Page/EditValue.hs
+++ b/frontend/app/Page/EditValue.hs
@@ -15,22 +15,22 @@ import Data.Maybe
import Effect (Eff)
import Form qualified as F
import Miso
-import Miso.String (MisoString, toMisoString)
+import Miso.String (toMisoString)
import Safe (headMay)
import Schema
+import Collection
data Model = Model
- { collection :: MisoString,
- fileName :: MisoString,
+ { collectionItem :: CollectionItem,
input :: Maybe A.Object,
schema :: Schema
}
deriving (Show, Eq)
-initialModel :: MisoString -> MisoString -> JSM (Either SomeException Model)
-initialModel collection fileName = do
- schema' <- try (API.REST.Collection.schema collection)
- input' <- try (headMay <$> API.REST.Collection.read collection fileName)
+initialModel :: CollectionItem -> JSM (Either SomeException Model)
+initialModel collectionItem = do
+ schema' <- try (API.REST.Collection.schema collectionItem.collection)
+ input' <- try (headMay <$> API.REST.Collection.read collectionItem)
pure do
schema <- schema'
input <- input'
@@ -43,7 +43,7 @@ update__formChanged (Just -> input) = Action $ \m -> (noEff m {input}, [])
update__formSubmitted :: A.Object -> Action
update__formSubmitted output = Action $ \m ->
- (m <# do update__entityWritten <$> try (API.REST.Collection.update m.collection m.fileName output), [])
+ (m <# do update__entityWritten <$> try (API.REST.Collection.update m.collectionItem output), [])
update__entityWritten :: Either SomeException A.Object -> Action
update__entityWritten _ = Action $ \m -> (noEff m, [])
diff --git a/frontend/app/Page/ListCollection.hs b/frontend/app/Page/ListCollection.hs
index 47a4649..6b999f0 100644
--- a/frontend/app/Page/ListCollection.hs
+++ b/frontend/app/Page/ListCollection.hs
@@ -13,18 +13,18 @@ import Data.Aeson qualified as A
import Data.Aeson.KeyMap qualified as AM
import Effect (Eff)
import Miso
-import Miso.String (MisoString)
import Schema
+import Collection
data Model = Model
- { collection :: MisoString,
+ { collection :: Collection,
input :: A.Object,
schema :: Schema,
posts :: [A.Object]
}
deriving (Show, Eq)
-initialModel :: MisoString -> JSM (Either SomeException Model)
+initialModel :: Collection -> JSM (Either SomeException Model)
initialModel collection = do
schema' <- try (API.REST.Collection.schema collection)
posts' <- try (API.REST.Collection.list collection)
@@ -42,7 +42,7 @@ viewModel :: Model -> View Action
viewModel m =
div_ [] $
[ h3_ [] [text "entities"],
- schemaTable m.collection m.schema m.posts,
+ schemaTable m.collection.name m.schema m.posts,
h3_ [] [text "schema"],
viewSchema m.schema
]