aboutsummaryrefslogtreecommitdiff
path: root/client/src/Component/Link.hs
diff options
context:
space:
mode:
authorJoris2019-10-12 11:23:10 +0200
committerJoris2019-10-12 11:23:10 +0200
commit52331eeadce8d250564851c25fc965172640bc55 (patch)
treee634c6d232d9a28384499fe19caeb80288d05df9 /client/src/Component/Link.hs
parent7529a18ff0ac443e7f9764b5e2d0f57a5d3a850b (diff)
downloadbudget-52331eeadce8d250564851c25fc965172640bc55.tar.gz
budget-52331eeadce8d250564851c25fc965172640bc55.tar.bz2
budget-52331eeadce8d250564851c25fc965172640bc55.zip
Implement client routing
Diffstat (limited to 'client/src/Component/Link.hs')
-rw-r--r--client/src/Component/Link.hs33
1 files changed, 33 insertions, 0 deletions
diff --git a/client/src/Component/Link.hs b/client/src/Component/Link.hs
new file mode 100644
index 0000000..7e8558b
--- /dev/null
+++ b/client/src/Component/Link.hs
@@ -0,0 +1,33 @@
+module Component.Link
+ ( link
+ ) where
+
+import Data.Map (Map)
+import qualified Data.Map as M
+import Data.Text (Text)
+import qualified Data.Text as T
+import Reflex.Dom (Dynamic, MonadWidget)
+import qualified Reflex.Dom as R
+
+link :: forall t m a. MonadWidget t m => Text -> Dynamic t (Map Text Text) -> Text -> m ()
+link href inputAttrs content =
+ R.elDynAttr "a" attrs (R.text content)
+ where
+
+ onclickHandler =
+ T.intercalate ";"
+ [ "history.pushState(0, '', event.target.href)"
+ , "dispatchEvent(new PopStateEvent('popstate', {cancelable: true, bubbles: true, view: window}))"
+ , "return false"
+ ]
+
+ attrs =
+ R.ffor inputAttrs (\as ->
+ (M.union
+ (M.fromList
+ [ ("onclick", onclickHandler)
+ , ("href", href)
+ ]
+ )
+ as)
+ )