Skip to content

Instantly share code, notes, and snippets.

@agocorona
Created June 30, 2016 15:02
Show Gist options
  • Save agocorona/b39bbfed90ab8c048c2f9999a030545c to your computer and use it in GitHub Desktop.
Save agocorona/b39bbfed90ab8c048c2f9999a030545c to your computer and use it in GitHub Desktop.
module Main where
import Lib
import Model
import GHCJS.HPlay.View hiding (input, option, pack)
import qualified GHCJS.Perch as P (input)
import Transient.Base
import Transient.Move
import Control.Monad.IO.Class (liftIO)
import Data.Text (pack, unpack)
import Database.Persist
import Control.Monad (forM_)
import Data.Monoid ((<>))
import Data.String (fromString)
main :: IO ()
main = keep . initNode . onBrowser $
do op <- products <|> productCategories <|> manufacturers
atRemote . lliftIO . putStrLn $ op <> " finished"
manufacturers = do
local . render $ wlink () $ p "manufacturers"
local . render $ rawHtml $ GHCJS.HPlay.View.div ! GHCJS.HPlay.View.id (fs "manufactlist") $ noHtml
showManufacturers <|> newManufacturer
where
showManufacturers= do
mfrs <- allManufacturers
local . render $ at (fs "#manufactlist") Insert $ do
rawHtml $ do h1 "Manufacturers"
ul $ forM_ mfrs $ \ (Entity _mid mfr) -> li . unpack $ manufacturerName mfr
empty
newManufacturer=do
name <- local. render $ h1 "Add New Manufacturer"
++> inputString Nothing ! placeholder "Name" `fire` OnChange
<** inputSubmit "Save"
let newMfr = Manufacturer (pack name)
atRemote $
do newId <- local . db $ insert newMfr
lliftIO $
do putStr "saved "
putStr $ show (newId :: ManufacturerId) ++ " "
print newMfr
showManufacturers
return "add manufacturer"
fs= fromString
products = local $
do render . wlink () $ p "products"
liftIO . alert $ fromString "not implemented"
empty
productCategories = local $
do render . wlink () $ p "product categories"
liftIO . alert $ fromString "not implemented"
empty
placeholder = atr "placeholder" . fromString
allManufacturers :: Cloud [Entity Manufacturer]
allManufacturers = atRemote . local . db $ selectList [] []
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment