Files
acms/frontend/app/Page/ListCollection.hs

49 lines
959 B
Haskell
Raw Permalink Normal View History

2024-06-04 14:36:26 +02:00
module Page.ListCollection
( Model,
initialModel,
Action,
updateModel,
viewModel,
)
where
import Api
import Data.Aeson qualified as A
import Data.Aeson.KeyMap qualified as AM
import Miso
import Schema
2024-06-07 17:08:01 +02:00
import Effect (Eff)
2024-06-04 14:36:26 +02:00
data Model = Model
{ collection :: String,
input :: A.Value,
schema :: Schema,
posts :: [A.Value]
}
deriving (Show, Eq)
initialModel :: String -> JSM (Either String Model)
initialModel collection = do
schema' <- fetchSchema
posts' <- fetchPosts
pure do
schema <- schema'
posts <- posts'
pure $ Model {input = A.Object AM.empty, ..}
data Action
= NoOp
deriving (Eq, Show)
2024-06-07 17:08:01 +02:00
updateModel :: Action -> Model -> (Effect Action Model, [Eff])
updateModel NoOp m = (noEff m, [])
2024-06-04 14:36:26 +02:00
viewModel :: Model -> View Action
viewModel m =
div_ [] $
2024-06-06 15:23:23 +02:00
[ h3_ [] [text "entities"],
2024-06-06 15:31:16 +02:00
schemaTable m.collection m.schema m.posts,
2024-06-06 15:23:23 +02:00
h3_ [] [text "schema"],
viewSchema m.schema
2024-06-04 14:36:26 +02:00
]