diff options
Diffstat (limited to 'frontend')
-rw-r--r-- | frontend/app/Page.hs | 6 | ||||
-rw-r--r-- | frontend/app/Page/EditValue.hs | 16 | ||||
-rw-r--r-- | frontend/app/Page/ListCollection.hs | 8 |
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 ] |