Skip to content

Commit 1dc9c69

Browse files
author
Andika Demas Riyandi
committed
update the code based on the change request
1 parent c4b6d90 commit 1dc9c69

File tree

2 files changed

+19
-20
lines changed

2 files changed

+19
-20
lines changed

src-ui.v3/src/Main.hs

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import Data.Monoid (Endo (Endo), appEndo)
3434
import Data.Proxy
3535
import qualified Data.Set as Set
3636
import qualified Data.Text as T
37+
import Data.Text (Text)
3738
import Data.Time (UTCTime)
3839
import Data.Time (getCurrentTime)
3940
import Data.Time.Clock.POSIX (POSIXTime, posixSecondsToUTCTime,
@@ -691,7 +692,7 @@ mkButton s alt' = do
691692
mkWorkerStat :: (Vector WorkerRow) -> (PkgN -> PkgIdxTs -> Int)
692693
mkWorkerStat ws = \x1 x2 -> Map.findWithDefault 0 (x1,x2) (Map.fromListWith (+) [ ((pn,is),1) | WorkerRow { wrPkgname = Just pn, wrIdxState = Just is } <- V.toList ws ])
693694

694-
tshow :: Show a => a -> T.Text
695+
tshow :: Show a => a -> Text
695696
tshow = T.pack . show
696697

697698
data LR = L | R | LR
@@ -737,7 +738,7 @@ pkgTagList m = Map.fromListWith (List.++) $ do
737738
joinE :: forall t m a. (Reflex t, MonadHold t m) => Event t (Event t a) -> m (Event t a)
738739
joinE = fmap switch . hold never
739740

740-
clickElement_ :: forall t m. (DomBuilder t m, PostBuild t m) => T.Text -> T.Text -> m (Event t ())
741+
clickElement_ :: forall t m. (DomBuilder t m, PostBuild t m) => Text -> Text -> m (Event t ())
741742
clickElement_ elm t = do
742743
let cfg = (def :: ElementConfig EventResult t (DomBuilderSpace m))
743744
& elementConfig_eventSpec %~ addEventSpecFlags (Proxy :: Proxy (DomBuilderSpace m)) Click (\_ -> preventDefault)
@@ -750,38 +751,36 @@ stripSearch sJ
750751
| Just sJ' <- JSS.stripSuffix "$" sJ = sJ'
751752
| otherwise = sJ
752753

753-
splitInfixPkg :: JSS.JSString -> JSS.JSString -> (T.Text, T.Text, T.Text)
754+
splitInfixPkg :: JSS.JSString -> JSS.JSString -> (Text, Text, Text)
754755
splitInfixPkg stripSJ pkg = (frontT, midT, backT)
755756
where
756757
textS = JSS.textFromJSString stripSJ
757758
(frontT, reminderT) = T.breakOn textS (JSS.textFromJSString pkg)
758759
(midT, backT) = T.breakOnEnd textS reminderT
759760

760-
calcMatch :: JSS.JSString -> JSS.JSString -> (Map.Map T.Text (), Map.Map T.Text (T.Text,T.Text,T.Text))
761-
calcMatch sJss pkg =
762-
let stripSJ = stripSearch sJss
763-
in
764-
case stripSJ == pkg of
765-
True -> (Map.singleton (JSS.textFromJSString pkg) (), Map.empty)
766-
False -> filterPkgSearch stripSJ pkg
761+
calcMatch :: JSS.JSString -> JSS.JSString -> (Map.Map Text (), Map.Map Text (Text,Text,Text))
762+
calcMatch sJss pkg
763+
| stripSJ == pkg = (Map.singleton (JSS.textFromJSString pkg) (), Map.empty)
764+
| otherwise = filterPkgSearch stripSJ pkg
765+
where
766+
stripSJ = stripSearch sJss
767767

768-
filterPkgSearch :: JSS.JSString -> JSS.JSString -> (Map.Map T.Text (), Map.Map T.Text (T.Text,T.Text,T.Text))
768+
filterPkgSearch :: JSS.JSString -> JSS.JSString -> (Map.Map Text (), Map.Map Text (Text,Text,Text))
769769
filterPkgSearch sJss pkg
770770
| Just sJ' <- JSS.stripPrefix "^" sJss = if JSS.isPrefixOf sJ' pkg
771771
then (Map.empty, Map.singleton (JSS.textFromJSString pkg) (splitInfixPkg sJ' pkg))
772-
else (Map.empty, Map.empty)
772+
else mempty
773773
| Just sJ' <- JSS.stripSuffix "$" sJss = if JSS.isSuffixOf sJ' pkg
774774
then (Map.empty, Map.singleton (JSS.textFromJSString pkg) (splitInfixPkg sJ' pkg))
775-
else (Map.empty, Map.empty)
775+
else mempty
776776
| otherwise = if JSS.isInfixOf sJss pkg
777777
then (Map.empty, Map.singleton (JSS.textFromJSString pkg) (splitInfixPkg sJss pkg))
778-
else (Map.empty, Map.empty)
778+
else mempty
779779

780780
calcMatches :: [JSS.JSString] -> JSS.JSString -> Matches
781-
calcMatches pkgs sJss =
782-
if JSS.length sJss < 3
783-
then matchesEmpty
784-
else Matches { matchesInput = textS, matchesExact = exactMap, matchesInfix = othersMap}
781+
calcMatches pkgs sJss
782+
| JSS.length sJss < 3 = matchesEmpty
783+
| otherwise = Matches { matchesInput = textS, matchesExact = exactMap, matchesInfix = othersMap}
785784
where
786785
textS = JSS.textFromJSString sJss
787786
(exactMap,othersMap) = F.foldMap (calcMatch sJss) pkgs
@@ -804,7 +803,7 @@ searchBoxWidget dynPkgs0 = mdo
804803

805804
searchResultWidget :: forall t m. (MonadFix m, MonadHold t m, PostBuild t m, DomBuilder t m)
806805
=> Dynamic t Matches
807-
-> m (Event t T.Text)
806+
-> m (Event t Text)
808807
searchResultWidget mDyn =
809808
el "ul" $ do
810809
exactE <- listViewWithKey (matchesExact <$> mDyn) $ \eId _ -> do

src-ui.v3/src/PkgId.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,6 @@ data Matches = Matches
157157
deriving (Eq,Ord)
158158

159159
matchesEmpty :: Matches
160-
matchesEmpty = Matches { matchesInput = T.empty :: T.Text, matchesExact = Map.empty, matchesInfix = Map.empty}
160+
matchesEmpty = Matches { matchesInput = T.empty, matchesExact = Map.empty, matchesInfix = Map.empty}
161161

162162

0 commit comments

Comments
 (0)