Skip to content

Commit 6e86b33

Browse files
author
Andika Demas Riyandi
committed
Preliminary fix for routing
1 parent 66c69d4 commit 6e86b33

File tree

4 files changed

+319
-59
lines changed

4 files changed

+319
-59
lines changed

src-ui.v3/matrix-ui.cabal

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ executable matrix-ui
3838
, vector ^>= 0.12.0.1
3939
, uuid-types ^>= 1.0.3
4040
, servant ^>= 0.16
41+
, primitive ^>= 0.6.4.0
42+
, monad-control ^>= 1.0.2.3
43+
, mtl ^>= 2.2.2
44+
, ref-tf ^>= 0.4
4145

4246
-- unreleased Git snapshots of deps; see cabal.project for provenance
4347
-- , ghcjs-dom-jsffi

src-ui.v3/src/Main.hs

Lines changed: 22 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ import qualified Data.List as List
3131
import qualified Data.Map.Strict as Map
3232
import qualified Data.Maybe as M
3333
import Data.Monoid (Endo (Endo), appEndo)
34+
import qualified Data.List.NonEmpty as NE
35+
import Data.List.NonEmpty (NonEmpty)
3436
import Data.Proxy
3537
import qualified Data.Set as Set
3638
import Data.Set (Set)
@@ -64,6 +66,7 @@ import Servant.Reflex
6466

6567
import API
6668
import PkgId
69+
import Router
6770

6871

6972
main :: IO ()
@@ -103,13 +106,18 @@ utc2unix :: UTCTime -> Int
103106
utc2unix x = ceiling (realToFrac (utcTimeToPOSIXSeconds x) :: Double)
104107

105108
bodyElement4 :: forall t m . (SupportsServantReflex t m, MonadFix m, MonadIO m, MonadHold t m, PostBuild t m, DomBuilder t m, Adjustable t m, DomBuilderSpace m ~ GhcjsDomSpace) => m ()
106-
bodyElement4 = mdo
107-
dynLoc <- browserHistoryWith getLocationUri
108-
let dynFrag = decodeFrag . T.pack . uriFragment <$> dynLoc
109-
109+
bodyElement4 = do
110+
--dynLoc <- browserHistoryWith getLocationUri
111+
--let dynFrag = decodeFrag . T.pack . uriFragment <$> dynLoc
112+
_ <- runRouteViewT app
113+
pure ()
110114
-- ticker1 <- tickLossy 1 =<< liftIO getCurrentTime
111115
-- ticker1cnt <- count ticker1
112116

117+
app :: forall t r m. (SetRoute t (NonEmpty FragRoute) m, SupportsServantReflex t m, MonadFix m, MonadIO m, MonadHold t m, PostBuild t m, DomBuilder t m, Adjustable t m, DomBuilderSpace m ~ GhcjsDomSpace)
118+
=> Dynamic t FragRoute
119+
-> m ()
120+
app dynFrag = do
113121
-- top-level PB event
114122
evPB0 <- getPostBuild
115123

@@ -132,11 +140,11 @@ bodyElement4 = mdo
132140
-- pseudo navbar
133141
el "nav" $ do
134142
text "[ "
135-
elAttr "a" ("href" =: "#/") $ text "HOME"
143+
routeLink False "#/" (text "HOME")
136144
text " | "
137-
elAttr "a" ("href" =: "#/queue") $ text "Build Queue"
145+
routeLink False "#/queue" (text "Build Queue")
138146
text " | "
139-
elAttr "a" ("href" =: "#/packages") $ text "Packages"
147+
routeLink False "#/packages" (text "Packages")
140148
text " ]"
141149
text " (current index-state: "
142150
dynText (pkgIdxTsToText <$> dynIdxStLast)
@@ -360,7 +368,8 @@ bodyElement4 = mdo
360368

361369

362370
let xs = Map.fromList . fmap (\x -> (x, pkgIdxTsToText x)) . Set.toList <$> dynReports
363-
x0 = (\s -> if Set.null s then PkgIdxTs 0 else findInitialDropDown idxSt s) <$> dynReports
371+
x0 = (\s -> if Set.null s then PkgIdxTs 0
372+
else (findInitialDropDown idxSt s)) <$> dynReports
364373

365374

366375
let ddCfg = DropdownConfig (updated x0) (constDyn mempty)
@@ -371,7 +380,7 @@ bodyElement4 = mdo
371380
ddReports <- el "p" $ do
372381
evQButton <- button "Queue a build"
373382
text " for the index-state "
374-
tmp <- dropdown (PkgIdxTs 0) xs ddCfg
383+
tmp <- routePkgIdxTs pn (PkgIdxTs 0) (current dynReports) xs ddCfg
375384
text " shown below"
376385

377386
_ <- putQueue (constDyn $ Right pn) (Right <$> _dropdown_value tmp) (constDyn $ Right (QEntryUpd (-1))) evQButton
@@ -402,26 +411,10 @@ bodyElement4 = mdo
402411
pure $ tagPromptlyDyn tVal addResult
403412
pure ()
404413

405-
let evReports' = updated (_dropdown_value ddReports)
406-
dynIdxSt = ddReports ^. dropdown_value
407-
evIdxChange = updated dynIdxSt --ddReports ^. dropdown_change
408-
_ <- mdo
409-
historyState <- manageHistory $ HistoryCommand_PushState <$> setState
410-
let
411-
f (currentSet, currentHistoryState, oldRoute) idxChange =
412-
let newRoute = switchPkgRoute currentSet oldRoute idxChange
413-
in
414-
HistoryStateUpdate
415-
{ _historyStateUpdate_state = DOM.SerializedScriptValue jsNull
416-
, _historyStateUpdate_title = ""
417-
, _historyStateUpdate_uri = newRoute
418-
}
419-
setState = attachWith f ((\a b c -> (a,b,c)) <$> current dynReports
420-
<*> current historyState
421-
<*> current dynLoc
422-
) evIdxChange
423-
pure historyState
424-
display dynIdxSt
414+
let dynIdxSt = ddReports ^. dropdown_value
415+
evReports' = updated (_dropdown_value ddReports)
416+
--evIdxChange = updated dynIdxSt --ddReports ^. dropdown_change
417+
425418
--display $ holdDyn (PkgIdxTs 0) evIdxChange
426419
evRepSum <- getPackageReportSummary (constDyn $ Right pn) (Right <$> dynIdxSt) (leftmost [evReports' $> (), ticker4 $> ()])
427420
dynRepSum <- holdUniqDyn =<< holdDyn (PkgIdxTsReport pn (PkgIdxTs 0) [] mempty) evRepSum
@@ -478,35 +471,6 @@ bodyElement4 = mdo
478471
delResult <- deleteTags (constDyn $ Right (TagN tId)) (constDyn $ Right pn) rmTag
479472
pure $ (TagN tId) <$ delResult
480473

481-
data FragRoute = RouteHome
482-
| RouteQueue
483-
| RoutePackages
484-
| RoutePackage (PkgN, Maybe PkgIdxTs)
485-
| RouteUser UserName
486-
| RouteUnknown T.Text
487-
deriving (Eq)
488-
489-
decodeFrag :: T.Text -> FragRoute
490-
decodeFrag frag = case frag of
491-
"" -> RouteHome
492-
"#" -> RouteHome
493-
"#/" -> RouteHome
494-
"#/queue" -> RouteQueue
495-
"#/packages" -> RoutePackages
496-
497-
_ | Just sfx <- T.stripPrefix "#/package/" frag
498-
, not (T.null frag)
499-
, (Just pn, idx) <- pkgNFromText sfx
500-
-> RoutePackage (pn , idx)
501-
502-
| Just sfx <- T.stripPrefix "#/user/" frag
503-
, not (T.null frag)
504-
, T.all (\c -> C.isAsciiLower c || C.isAsciiUpper c || C.isDigit c || c == '_') sfx
505-
-> RouteUser sfx
506-
507-
| otherwise -> RouteUnknown frag
508-
509-
510474
-- | Renders alpha-tabbed package index
511475
packagesPageWidget :: forall t m. (MonadFix m, MonadHold t m, PostBuild t m, DomBuilder t m)
512476
=> Dynamic t (Vector PkgN)

src-ui.v3/src/PkgId.hs

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ module PkgId
3333
, PkgRev
3434

3535
, UserName
36+
, FragRoute(..), decodeFrag
3637
) where
3738

3839
import Control.Monad (fail)
@@ -171,6 +172,39 @@ data Matches = Matches
171172
deriving (Eq,Ord)
172173

173174
matchesEmpty :: Matches
174-
matchesEmpty = Matches { matchesInput = T.empty, matchesExact = Map.empty, matchesInfix = Map.empty}
175+
matchesEmpty = Matches { matchesInput = T.empty, matchesExact = Map.empty, matchesInfix = Map.empty}
176+
177+
---------------------------------
178+
179+
data FragRoute = RouteHome
180+
| RouteQueue
181+
| RoutePackages
182+
| RoutePackage (PkgN, Maybe PkgIdxTs)
183+
| RouteUser UserName
184+
| RouteUnknown T.Text
185+
deriving (Eq, Ord)
186+
187+
decodeFrag :: T.Text -> FragRoute
188+
decodeFrag frag = case frag of
189+
"" -> RouteHome
190+
"#" -> RouteHome
191+
"#/" -> RouteHome
192+
"#/queue" -> RouteQueue
193+
"#/packages" -> RoutePackages
194+
195+
_ | Just sfx <- T.stripPrefix "#/package/" frag
196+
, not (T.null frag)
197+
, (Just pn, idx) <- pkgNFromText sfx
198+
-> RoutePackage (pn , idx)
199+
200+
| Just sfx <- T.stripPrefix "#/user/" frag
201+
, not (T.null frag)
202+
, T.all (\c -> C.isAsciiLower c || C.isAsciiUpper c || C.isDigit c || c == '_') sfx
203+
-> RouteUser sfx
204+
205+
| otherwise -> RouteUnknown frag
206+
207+
--encodeFrag :: FragRoute -> Maybe
208+
175209

176210

0 commit comments

Comments
 (0)