Преглед изворни кода

Use new SubQuery functions in TopCard

jherve пре 1 година
родитељ
комит
163313fe88
1 измењених фајлова са 16 додато и 17 уклоњено
  1. 16 17
      src/LinkedIn/JobsUnifiedTopCard.purs

+ 16 - 17
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)
+import LinkedIn.QueryRunner (QueryError(..), QueryRunner, chooseOne, chooseOne3, ignoreNotFound, queryAll, queryOne, queryText, subQueryMany, subQueryOne)
 import Web.DOM (Node)
 import Web.DOM.Node as N
 
@@ -206,8 +206,10 @@ queryTopCardInsightContentButton n =
 queryTopCardInsightContentSecondary :: QueryRunner (TopCardInsightContent Node)
 queryTopCardInsightContentSecondary n = do
   primary <- queryOne ":scope > span:first-child span[aria-hidden=true]" n
-  secondary <- queryAll ":scope > span.job-details-jobs-unified-top-card__job-insight-view-model-secondary" n
-  s <- traverse queryTopCardSecondaryInsight secondary
+  s <- subQueryMany
+        queryTopCardSecondaryInsight
+        ":scope > span.job-details-jobs-unified-top-card__job-insight-view-model-secondary"
+        n
   pure $ TopCardInsightContentSecondary {primary, secondary: s}
 
 queryTopCardInsightContent :: QueryRunner (TopCardInsightContent Node)
@@ -217,11 +219,13 @@ queryTopCardInsightContent n =
 queryTopCardInsight :: QueryRunner (TopCardInsight Node)
 queryTopCardInsight n = do
   icon <- chooseOne (queryOne ":scope li-icon") (queryOne ":scope svg") n
-  content <- chooseOne (queryOne ":scope > span") (queryOne ":scope > button") n
-  c <- queryTopCardInsightContent content
+  c <- queryTopCardInsightContent =<< getContentNode n
 
   pure $ TopCardInsight {icon, content: c}
 
+  where
+    getContentNode = chooseOne (queryOne ":scope > span") (queryOne ":scope > button")
+
 queryTopCardPrimaryDescription :: QueryRunner (TopCardPrimaryDescription Node)
 queryTopCardPrimaryDescription n = do
   link <- queryOne ":scope > a" n
@@ -233,18 +237,13 @@ queryTopCardPrimaryDescription n = do
 queryJobsUnifiedTopCardElement :: QueryRunner (JobsUnifiedTopCardElement Node)
 queryJobsUnifiedTopCardElement n = do
   h1 <- queryOne "h1.job-details-jobs-unified-top-card__job-title" n
-  primary <- queryOne
-    "div.job-details-jobs-unified-top-card__primary-description-container > div"
-    n
-  p <- queryTopCardPrimaryDescription primary
-  insights <- queryAll
-    "li.job-details-jobs-unified-top-card__job-insight"
-    n
-  i <- ignoreNotFound $ traverse queryTopCardInsight insights
-  actions <- queryAll
-    ".mt5 button"
-    n
-  a <- ignoreNotFound $ traverse queryTopCardAction actions
+  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
 
   pure $ JobsUnifiedTopCardElement {
     header: h1,