Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to miso refactor #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion default.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
{ nixpkgs ? import <nixpkgs> {}, compiler ? "ghcjs" }:
let
pkgs = nixpkgs.pkgs.haskell.packages.${compiler};
misoRepo = /Users/elliot/a/mine/miso;
miso = misoRepo + "/miso/miso.nix";
misoHtml = misoRepo + "/miso-html/miso-html.nix";
in
pkgs.callPackage ./product-chart-demo.nix {
miso = pkgs.callPackage /Users/elliot/a/mine/miso/miso.nix {};
miso = pkgs.callPackage miso {
miso-html = pkgs.callPackage misoHtml {};
};
miso-html = pkgs.callPackage misoHtml {};
}

1 change: 1 addition & 0 deletions product-chart-demo.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ executable main
, ghcjs-base
, ghcjs-dom
, miso
, miso-html
, text
default-language: Haskell2010
6 changes: 2 additions & 4 deletions product-chart-demo.nix
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
{ mkDerivation, base, containers, ghcjs-base, ghcjs-dom, miso, stdenv, text,
closurecompiler
}:
{ mkDerivation, stdenv, base, containers, ghcjs-base, ghcjs-dom, text, miso, miso-html, closurecompiler }:
mkDerivation {
pname = "product-chart-demo";
version = "0.1.0.0";
src = ./.;
isLibrary = false;
isExecutable = true;
executableHaskellDepends = [
base containers ghcjs-base ghcjs-dom miso text
base containers ghcjs-base ghcjs-dom miso miso-html text
];
license = stdenv.lib.licenses.unfree;
}
39 changes: 21 additions & 18 deletions src/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import GHCJS.DOM.Element
import GHCJS.DOM.Document
import GHCJS.DOM.Node
import Miso

import Miso.Html

addCss :: String -> IO ()
addCss urlLocal = do
Expand Down Expand Up @@ -142,7 +142,7 @@ main :: IO ()
main = do
addAllCss
clearBody
startApp model' view update defaultEvents (Proxy :: Proxy '[]) []
startApp model' view update defaultSettings
where
model' :: Model
model' = Model chart' deletedRows' Nothing
Expand Down Expand Up @@ -190,10 +190,10 @@ chartModifier :: DragType -> Int -> Int -> Chart -> Chart
chartModifier DragColumn from to chart = chart{chartOrder=shift from to (chart & chartOrder)}
chartModifier DragRow from to chart = chart{chartData=shift from to (chart & chartData)}

view :: Model -> VTree ChartAction
view :: Model -> View ChartAction
view model = master (tableView model)

tableView :: Model -> [VTree ChartAction]
tableView :: Model -> [View ChartAction]
tableView (Model modelChart _ dragInfo) =
[ div_ [classes ["row"]]
[ div_ [classes ["col-xs-12"]]
Expand Down Expand Up @@ -236,7 +236,7 @@ tableView (Model modelChart _ dragInfo) =
Just info -> chartModifier (dragType info) (sourceIndex info) (destIndex info) modelChart


toHead :: Maybe DragInfo -> [T.Text] -> VTree ChartAction
toHead :: Maybe DragInfo -> [T.Text] -> View ChartAction
toHead dragInfo columnNames =
thead_ []
[ tr_ []
Expand All @@ -255,7 +255,7 @@ toHead dragInfo columnNames =
])
[ text_ columnName ]

toBody :: Maybe DragInfo -> Chart -> VTree ChartAction
toBody :: Maybe DragInfo -> Chart -> View ChartAction
toBody dragInfo Chart{chartData=rows, chartOrder=columnNames} =
tbody_ [] $
for (zip [1..] rows) $ \(rowIndex, row) ->
Expand All @@ -281,15 +281,15 @@ toBody dragInfo Chart{chartData=rows, chartOrder=columnNames} =
]
]

showColData :: ColumnName -> T.Text -> VTree a
showColData :: ColumnName -> T.Text -> View a
showColData col content
| col == "Image" = span_ [] [img_ [class_ "img-thumbnail", src_ content, alt_ "Amazon Product Image" ]]
| col == "Price" = text_ ("$" <> content)
| col == "Rating" = toStars (read $ T.unpack content)
| otherwise = text_ content


toStars :: Float -> VTree a
toStars :: Float -> View a
toStars amount =
span_ []
[ star (amount - 0)
Expand Down Expand Up @@ -318,36 +318,39 @@ shift fromIndex toIndex xs = left ++ (item : right)
(left, right) = splitAt (toIndex - 1) xs'


fa :: T.Text -> VTree a
fa :: T.Text -> View a
fa icon = span_ [class_ $ "fa fa-" <> icon] []


nav_ = mkNode "nav"
i_ = mkNode "i"
button_ = mkNode "button"
img_ attrs = mkNode "img" attrs []
mkNodeTxt :: T.Text -> [Attribute a] -> [View a] -> View a
mkNodeTxt = mkNode HTML

nav_ = mkNodeTxt "nav"
i_ = mkNodeTxt "i"
button_ = mkNodeTxt "button"
img_ attrs = mkNodeTxt "img" attrs []

src_, role_, alt_ :: T.Text -> Attribute a
src_ url = prop "src" url
role_ = prop "role"
alt_ = prop "alt"

br_ attrs = mkNode "br" attrs []
h5_ = mkNode "h5"
h2_ = mkNode "h2"
br_ attrs = mkNodeTxt "br" attrs []
h5_ = mkNodeTxt "h5"
h2_ = mkNodeTxt "h2"


classes :: [T.Text] -> Attribute a
classes = class_ . T.unwords

master :: [VTree a] -> VTree a
master :: [View a] -> View a
master content = div_ []
[ topnav
, div_ [class_ "container"] content
]


topnav :: VTree a
topnav :: View a
topnav =
div_ [classes ["navbar", "navbar-inverse", "navbar-static-top"], role_ "navigation"]
[ div_ [classes ["container"]]
Expand Down