Bläddra i källkod

Another approach without subQueryOne/Many

jherve 1 år sedan
förälder
incheckning
3d6937fd3b
1 ändrade filer med 17 tillägg och 20 borttagningar
  1. 17 20
      src/LinkedIn/JobsUnifiedTopCard.purs

+ 17 - 20
src/LinkedIn/JobsUnifiedTopCard.purs

@@ -9,7 +9,7 @@ import Data.List.Types (NonEmptyList)
 import Data.Maybe (Maybe(..))
 import Data.Show.Generic (genericShow)
 import Data.Traversable (class Traversable, sequence, traverse, traverseDefault)
-import LinkedIn.QueryRunner (QueryError(..), QueryRunner, chooseOne, chooseOne3, ignoreNotFound, queryAll, queryOne, queryText, subQueryMany, subQueryOne)
+import LinkedIn.QueryRunner (QueryError(..), QueryRunner, chooseOne, chooseOne3, ignoreNotFound, queryAll, queryOne, queryText)
 import Web.DOM (Node)
 import Web.DOM.Node as N
 
@@ -206,11 +206,9 @@ queryTopCardInsightContentButton n =
 queryTopCardInsightContentSecondary :: QueryRunner (TopCardInsightContent Node)
 queryTopCardInsightContentSecondary n = do
   primary <- queryOne ":scope > span:first-child span[aria-hidden=true]" n
-  s <- subQueryMany
-        queryTopCardSecondaryInsight
-        ":scope > span.job-details-jobs-unified-top-card__job-insight-view-model-secondary"
-        n
-  pure $ TopCardInsightContentSecondary {primary, secondary: s}
+  secondary <- traverse queryTopCardSecondaryInsight
+                =<< queryAll ":scope > span.job-details-jobs-unified-top-card__job-insight-view-model-secondary" n
+  pure $ TopCardInsightContentSecondary {primary, secondary}
 
 queryTopCardInsightContent :: QueryRunner (TopCardInsightContent Node)
 queryTopCardInsightContent n =
@@ -219,9 +217,9 @@ queryTopCardInsightContent n =
 queryTopCardInsight :: QueryRunner (TopCardInsight Node)
 queryTopCardInsight n = do
   icon <- chooseOne (queryOne ":scope li-icon") (queryOne ":scope svg") n
-  c <- queryTopCardInsightContent =<< getContentNode n
+  content <- queryTopCardInsightContent =<< getContentNode n
 
-  pure $ TopCardInsight {icon, content: c}
+  pure $ TopCardInsight {icon, content}
 
   where
     getContentNode = chooseOne (queryOne ":scope > span") (queryOne ":scope > button")
@@ -236,20 +234,19 @@ queryTopCardPrimaryDescription n = do
 
 queryJobsUnifiedTopCardElement :: QueryRunner (JobsUnifiedTopCardElement Node)
 queryJobsUnifiedTopCardElement n = do
-  h1 <- queryOne "h1.job-details-jobs-unified-top-card__job-title" n
-  p <- subQueryOne
-        queryTopCardPrimaryDescription
-        "div.job-details-jobs-unified-top-card__primary-description-container > div"
-        n
-  i <- ignoreNotFound $
-        subQueryMany queryTopCardInsight "li.job-details-jobs-unified-top-card__job-insight" n
-  a <- ignoreNotFound $ subQueryMany queryTopCardAction ".mt5 button" n
+  header <- queryOne "h1.job-details-jobs-unified-top-card__job-title" n
+  primaryDescription <- queryTopCardPrimaryDescription
+                          =<< queryOne "div.job-details-jobs-unified-top-card__primary-description-container > div" n
+  insights <- ignoreNotFound
+                <<< traverse queryTopCardInsight
+                =<< queryAll "li.job-details-jobs-unified-top-card__job-insight" n
+  actions <- ignoreNotFound <<< traverse queryTopCardAction =<< queryAll ".mt5 button" n
 
   pure $ JobsUnifiedTopCardElement {
-    header: h1,
-    primaryDescription: p,
-    insights: i,
-    actions: a
+    header,
+    primaryDescription,
+    insights,
+    actions
   }
 
 toHeader ∷ forall a. JobsUnifiedTopCardElement a → a