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 import Effect (Eff) 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) updateModel :: Action -> Model -> (Effect Action Model, [Eff]) updateModel NoOp m = (noEff m, []) viewModel :: Model -> View Action viewModel m = div_ [] $ [ h3_ [] [text "entities"], schemaTable m.collection m.schema m.posts, h3_ [] [text "schema"], viewSchema m.schema ]