@@ -1,8 +1,7 @@
11module Components.Navigation
22 ( isDarkDefault_
33 , navigation
4− )
5− where
4+ ) where
65
76import Prelude
87import Web.HTML.HTMLElement
@@ -13,9 +12,10 @@ import Data.Traversable (for_, traverse, traverse_)
1312import Data.Tuple.Nested ((/\))
1413import Debug (spy)
1514import Effect (Effect)
15+import Effect.Uncurried (runEffectFn1)
1616import Next.Router (useRouter)
1717import Next.Router as Router
18−import NextUI.NextUI (switch, useTheme)
18+import NextUI.NextUI (switch, useNextTheme, useTheme)
1919import NextUI.NextUI as NextUI
2020import React.Basic.DOM (css)
2121import React.Basic.DOM.Events (targetChecked)
@@ -32,6 +32,7 @@ import Web.HTML (window)
3232import Web.HTML.HTMLDocument (toDocument)
3333import Web.HTML.HTMLDocument as Doc
3434import Web.HTML.Window (document)
35+
3536-- radial-gradient(20rem 20rem at left 15rem top 20rem, rgba(30, 144, 255,0.5) 0% 10%,#0000 90% 90%),
3637mkBackgroundImage isDark =
3738 if isDark then
@@ -44,29 +45,29 @@ mkBackgroundImage isDark =
4445 radial-gradient(25rem 25rem at left 15rem top 20rem, rgba(32, 178, 170, 0.25) 0% 10%,#0000 90% 90%),
4546 radial-gradient(45rem 45rem at left 70rem top 40rem, rgba(30, 144, 255, 0.25) 0% 10%,#0000 70% 80%);
4647 """
48+
4749foreign import isDarkDefault_ :: Effect Boolean
4850
4951navigation :: Component Unit
5052navigation = do
5153 component "Navbar" \_props -> React.do
5254
53− { theme } <- useTheme
55+ { theme, isDark } <- useTheme
56+ { setTheme } <- useNextTheme
5457 router <- useRouter
5558 let
5659 dispatchRoute = Router.push router
57− isDarkPreference /\ setIsDarkPreference <- useState' true
58− isDark /\ setDark <- useState' isDarkPreference
59− _ <- useEffectOnce do
60− isDarkDefault <- isDarkDefault_
61− setIsDarkPreference $ spy "Setting isDarkDefault " isDarkDefault
62− pure mempty
60+ currentRoute = Router.route router
61+
62+ setDark false = setTheme "light"
63+ setDark true = setTheme "dark"
64+
6365 _ <- useEffect [ isDark ] do
6466 w <- window
6567 htmlDocument <- document w
6668 maybeElem <- htmlDocument # toDocument # documentElement
6769 case maybeElem of
6870 Just el -> do
69− (DOMEL.setAttribute "class" if (spy "isDark" $ isDark) then "dark-theme" else "light-theme") el
7071 bodyElem <- runMaybeT do
7172 body <- MaybeT $ Doc.body htmlDocument
7273 pure $ toElement body
@@ -80,31 +81,33 @@ navigation = do
8081 }
8182 $ icon siPurescript { style: css { color: getColorValue theme "neutral" }, size: "3rem" }
8283 , el NextUI.navbarContent { hideIn: "xs" } $ map (mkLink theme)
83− [ { onClick: dispatchRoute "/packages", title: "Getting started" }
84− , { onClick: dispatchRoute "/packages", title: "Try Purescript" }
85− , { onClick: dispatchRoute "/packages", title: "Packages" }
84+ [ { onClick: dispatchRoute "/getting-started", title: "Getting started", isActive: currentRoute == "/getting-started" }
85+ , { onClick: dispatchRoute "/try", title: "Try", isActive: currentRoute == "/try" }
86+ , { onClick: dispatchRoute "/packages", title: "Packages", isActive: currentRoute == "/packages" }
8687 ]
8788 , el NextUI.navbarContent {}
8889 [ el NextUI.navbarLink
8990 { href: "https://purescript.org/chat"
9091 }
91− $ icon siDiscord { style: css { color: spy "color value" $ getColorValue theme "neutral" }, size: "1.5rem" }
92+ $ icon siDiscord { style: css { color: getColorValue theme "neutral" }, size: "1.5rem" }
9293 , el NextUI.navbarLink
9394 { href: "https://discourse.purescript.org/"
9495 , target: "_blank"
9596 }
96− $ icon siDiscourse { style: css { color: spy "color value" $ getColorValue theme "neutral" }, size: "1.5rem" }
97+ $ icon siDiscourse { style: css { color: getColorValue theme "neutral" }, size: "1.5rem" }
9798 , el NextUI.navbarLink
9899 { href: "https://github.com/purescript/purescript"
99100 , target: "_blank"
100101 }
101− $ icon siGithub { style: css { color: spy "color value" $ getColorValue theme "neutral" }, size: "1.5rem" }
102+ $ icon siGithub { style: css { color: getColorValue theme "neutral" }, size: "1.5rem" }
102103 , el switch { checked: isDark, onChange: handler targetChecked $ traverse_ setDark } ""
103104 ]
104105 ]
105− where
106− mkLink theme { onClick, title } =
107− el NextUI.navbarLink
108− { onClick
109− }
110− $ el NextUI.text { size: "$xl", color: getColorValue theme "neutral" } title
106+ where
107+ mkLink theme { onClick, title, isActive } =
108+ el NextUI.navbarLink
109+ { onClick
110+ , isActive
111+ , variant: "underline"
112+ }
113+ $ el NextUI.text { size: "$xl", color: getColorValue theme "neutral" } title