|
|
@@ -1,21 +1,15 @@
|
|
|
module LinkedIn.JobsUnifiedTopCard where
|
|
|
|
|
|
-import Control.Alt
|
|
|
-import Control.Alt
|
|
|
import Prelude
|
|
|
|
|
|
import Control.Monad.Error.Class (throwError)
|
|
|
-import Data.Either (Either(..), hush)
|
|
|
import Data.Foldable (class Foldable, foldMap, foldlDefault, foldrDefault)
|
|
|
import Data.Generic.Rep (class Generic)
|
|
|
import Data.List.Types (NonEmptyList)
|
|
|
import Data.Maybe (Maybe(..))
|
|
|
import Data.Show.Generic (genericShow)
|
|
|
import Data.Traversable (class Traversable, sequence, traverse, traverseDefault)
|
|
|
-import LinkedIn (DetachedNode(..))
|
|
|
import LinkedIn.QueryRunner (QueryError(..), QueryRunner, chooseOne, chooseOne3, ignoreNotFound, queryAll, queryOne, queryText)
|
|
|
-import LinkedIn.Types (ParseError(..), Parser)
|
|
|
-import LinkedIn.Utils (detachNonEmptyTextChild, parseDetachedNode, queryAndDetachMany, queryAndDetachOne, queryManyAndParse, queryOneAndParse)
|
|
|
import Web.DOM (Node)
|
|
|
import Web.DOM.Node as N
|
|
|
|
|
|
@@ -183,27 +177,9 @@ instance Traversable TopCardAction where
|
|
|
|
|
|
traverse = \x -> traverseDefault x
|
|
|
|
|
|
-parseTopCardAction :: Parser (TopCardAction DetachedNode)
|
|
|
-parseTopCardAction n = do
|
|
|
- self <- parseDetachedNode n
|
|
|
-
|
|
|
- pure $ ado
|
|
|
- s <- self
|
|
|
- in TopCardActionApplyButton s
|
|
|
-
|
|
|
queryTopCardAction :: QueryRunner (TopCardAction Node)
|
|
|
queryTopCardAction n = pure $ TopCardActionApplyButton n
|
|
|
|
|
|
-parseTopCardSecondaryInsight :: Parser (TopCardSecondaryInsight DetachedNode)
|
|
|
-parseTopCardSecondaryInsight n = do
|
|
|
- nested <- queryAndDetachOne ":scope span[aria-hidden=true]" n
|
|
|
- plain <- parseDetachedNode n
|
|
|
-
|
|
|
- pure $ case nested, plain of
|
|
|
- Right p@(DetachedElement _), _ -> Right $ TopCardSecondaryInsightNested p
|
|
|
- _, Right p@(DetachedElement _) -> Right $ TopCardSecondaryInsightPlain p
|
|
|
- _, _ -> Left TextNotFoundError
|
|
|
-
|
|
|
queryTopCardSecondaryInsightNested :: QueryRunner (TopCardSecondaryInsight Node)
|
|
|
queryTopCardSecondaryInsightNested n = do
|
|
|
nested <- queryOne ":scope span[aria-hidden=true]" n
|
|
|
@@ -216,21 +192,6 @@ queryTopCardSecondaryInsight :: QueryRunner (TopCardSecondaryInsight Node)
|
|
|
queryTopCardSecondaryInsight n =
|
|
|
chooseOne queryTopCardSecondaryInsightNested queryTopCardSecondaryInsightPlain n
|
|
|
|
|
|
-parseTopCardInsightContent :: Parser (TopCardInsightContent DetachedNode)
|
|
|
-parseTopCardInsightContent n = do
|
|
|
- primary <- queryAndDetachOne ":scope > span:first-child span[aria-hidden=true]" n
|
|
|
- secondary <- queryManyAndParse
|
|
|
- ":scope > span.job-details-jobs-unified-top-card__job-insight-view-model-secondary"
|
|
|
- parseTopCardSecondaryInsight
|
|
|
- n
|
|
|
- self <- parseDetachedNode n
|
|
|
-
|
|
|
- pure $ case primary, secondary, self of
|
|
|
- _, _, Right b@(DetachedElement {tag: "BUTTON"}) -> Right $ TopCardInsightContentButton b
|
|
|
- Right p@(DetachedElement _), Right s, _ -> Right $ TopCardInsightContentSecondary {primary: p, secondary: s}
|
|
|
- _, _, Right el@(DetachedElement _) -> Right $ TopCardInsightContentSingle el
|
|
|
- _, _, _ -> Left TextNotFoundError
|
|
|
-
|
|
|
queryTopCardInsightContentSingle :: QueryRunner (TopCardInsightContent Node)
|
|
|
queryTopCardInsightContentSingle n = pure $ TopCardInsightContentSingle n
|
|
|
|
|
|
@@ -253,18 +214,6 @@ queryTopCardInsightContent :: QueryRunner (TopCardInsightContent Node)
|
|
|
queryTopCardInsightContent n =
|
|
|
chooseOne3 queryTopCardInsightContentSecondary queryTopCardInsightContentButton queryTopCardInsightContentSingle n
|
|
|
|
|
|
-parseTopCardInsight :: Parser (TopCardInsight DetachedNode)
|
|
|
-parseTopCardInsight n = do
|
|
|
- icon <- queryAndDetachOne ":scope li-icon" n
|
|
|
- svg <- queryAndDetachOne ":scope svg" n
|
|
|
- content <- queryOneAndParse ":scope > span" parseTopCardInsightContent n
|
|
|
- actionButton <- queryOneAndParse ":scope > button" parseTopCardInsightContent n
|
|
|
-
|
|
|
- pure $ ado
|
|
|
- i <- icon <|> svg
|
|
|
- c <- content <|> actionButton
|
|
|
- in TopCardInsight {icon: i, content: c}
|
|
|
-
|
|
|
queryTopCardInsight :: QueryRunner (TopCardInsight Node)
|
|
|
queryTopCardInsight n = do
|
|
|
icon <- chooseOne (queryOne ":scope li-icon") (queryOne ":scope svg") n
|
|
|
@@ -273,17 +222,6 @@ queryTopCardInsight n = do
|
|
|
|
|
|
pure $ TopCardInsight {icon, content: c}
|
|
|
|
|
|
-parseTopCardPrimaryDescription :: Parser (TopCardPrimaryDescription DetachedNode)
|
|
|
-parseTopCardPrimaryDescription n = do
|
|
|
- link <- queryAndDetachOne ":scope > a" n
|
|
|
- text <- detachNonEmptyTextChild n
|
|
|
- tvmText <- queryAndDetachMany "span.tvm__text" n
|
|
|
-
|
|
|
- pure $ ado
|
|
|
- l <- link
|
|
|
- t <- text
|
|
|
- in TopCardPrimaryDescription {link: l, text: t, tvmText: hush tvmText}
|
|
|
-
|
|
|
queryTopCardPrimaryDescription :: QueryRunner (TopCardPrimaryDescription Node)
|
|
|
queryTopCardPrimaryDescription n = do
|
|
|
link <- queryOne ":scope > a" n
|
|
|
@@ -292,32 +230,6 @@ queryTopCardPrimaryDescription n = do
|
|
|
|
|
|
pure $ TopCardPrimaryDescription {link, text, tvmText: tvmText}
|
|
|
|
|
|
-parseJobsUnifiedTopCardElement :: Parser (JobsUnifiedTopCardElement DetachedNode)
|
|
|
-parseJobsUnifiedTopCardElement n = do
|
|
|
- h1 <- queryAndDetachOne "h1.job-details-jobs-unified-top-card__job-title" n
|
|
|
- primary <- queryOneAndParse
|
|
|
- "div.job-details-jobs-unified-top-card__primary-description-container > div"
|
|
|
- parseTopCardPrimaryDescription
|
|
|
- n
|
|
|
- insights <- queryManyAndParse
|
|
|
- "li.job-details-jobs-unified-top-card__job-insight"
|
|
|
- parseTopCardInsight
|
|
|
- n
|
|
|
- actions <- queryManyAndParse
|
|
|
- ".mt5 button"
|
|
|
- parseTopCardAction
|
|
|
- n
|
|
|
-
|
|
|
- pure $ ado
|
|
|
- h <- h1
|
|
|
- p <- primary
|
|
|
- in JobsUnifiedTopCardElement {
|
|
|
- header: h,
|
|
|
- primaryDescription: p,
|
|
|
- insights: hush insights,
|
|
|
- actions: hush actions
|
|
|
- }
|
|
|
-
|
|
|
queryJobsUnifiedTopCardElement :: QueryRunner (JobsUnifiedTopCardElement Node)
|
|
|
queryJobsUnifiedTopCardElement n = do
|
|
|
h1 <- queryOne "h1.job-details-jobs-unified-top-card__job-title" n
|
|
|
@@ -353,5 +265,3 @@ toPrimaryDescriptionText ∷ forall a. JobsUnifiedTopCardElement a → a
|
|
|
toPrimaryDescriptionText (JobsUnifiedTopCardElement {
|
|
|
primaryDescription: TopCardPrimaryDescription {text}
|
|
|
}) = text
|
|
|
-
|