Jelajahi Sumber

Handle li-icon nodes

jherve 1 tahun lalu
induk
melakukan
55f380ecb6

+ 5 - 0
src/LinkedIn/DetachedNode.purs

@@ -28,6 +28,7 @@ import Yoga.Tree (Tree, leaf, mkTree)
 data DetachedNode =
   DetachedElement {tag :: String, content :: String, id :: Maybe String, classes :: List String}
   | DetachedSvgElement {tag :: String, id :: Maybe String, dataTestIcon :: Maybe String}
+  | DetachedLiIcon String
   | DetachedA {content :: String, href :: String}
   | DetachedButton {content :: String, role :: Maybe String, classes :: List String}
   | DetachedComment String
@@ -75,6 +76,10 @@ elementToDetached el text = case E.tagName el of
       classes
     }
 
+  "LI-ICON" -> do
+    type_ <- getAttribute "type" el
+    pure $ DetachedLiIcon $ unsafePartial $ fromJust type_
+
   -- On SVG elements "className" returns a weird "SVGString" type that cannot be trimmed
   tag | tag == "svg" || tag == "use" || tag == "path" -> do
     id <- E.id el

+ 3 - 0
src/LinkedIn/Profile/Utils.purs

@@ -40,11 +40,14 @@ toUIElement ∷ DetachedNode → Either ParseError UIElement
 toUIElement (DetachedElement {content}) = runParser content uiElementP
 toUIElement (DetachedComment str) = runParser str uiElementP
 toUIElement (DetachedText str) = runParser str uiElementP
+
 toUIElement (DetachedSvgElement {id, dataTestIcon, tag: "svg"}) = case id <|> dataTestIcon of
   Just i -> Right (UIIcon i)
   Nothing -> Left (ParseError "SVG element could not be identified" initialPos)
 toUIElement (DetachedSvgElement _) = Left (ParseError "SVG element could not be identified" initialPos)
 
+toUIElement (DetachedLiIcon i) = Right (UIIcon i)
+
 toUIElement (DetachedButton {content, role}) =  map toButton $ runParser content uiElementP
   where toButton ui = UIButton role ui
 

+ 4 - 17
test/JobsUnifiedTopCard.purs

@@ -10,9 +10,9 @@ import Data.Maybe (Maybe(..), isJust)
 import Data.NonEmpty (NonEmpty(..))
 import Data.Traversable (traverse)
 import Effect (Effect)
+import LinkedIn (LinkedInUIElement(..), getJobsUnifiedTopCard)
 import LinkedIn.DetachedNode (DetachedNode(..), toDetached)
 import LinkedIn.JobsUnifiedTopCard (JobsUnifiedTopCardElement(..), TopCardAction(..), TopCardInsight(..), TopCardInsightContent(..), TopCardPrimaryDescription(..), TopCardSecondaryInsight(..), queryJobsUnifiedTopCardElement)
-import LinkedIn (LinkedInUIElement(..), getJobsUnifiedTopCard)
 import LinkedIn.QueryRunner (QueryError, runQuery)
 import Node.JsDom (jsDomFromFile)
 import Partial.Unsafe (unsafePartial)
@@ -65,34 +65,21 @@ testJobsUnifiedTopCard = do
                 id: (Just "undefined"),
                 tag: "SPAN"
               })) : Nil))) }),
-            icon: (DetachedElement {
-              classes: ("" : Nil),
-              content: "",
-              id: Nothing,
-              tag: "LI-ICON"
-            })
+            icon: DetachedLiIcon "job"
         }) ((TopCardInsight {
           content: (TopCardInsightContentSingle (DetachedElement {
             classes: ("" : Nil),
             content: "201-500 employés · Technologies et services de l’information",
             id: (Just "undefined"),
             tag: "SPAN" })),
-          icon: (DetachedElement {
-            classes: ("" : Nil),
-            content: "",
-            id: Nothing,
-            tag: "LI-ICON" })
+          icon: DetachedLiIcon "company"
         }) : (TopCardInsight {
             content: (TopCardInsightContentSingle (DetachedElement {
               classes: ("" : Nil),
               content: "2 anciens élèves travaillent ici",
               id: (Just "undefined"),
               tag: "SPAN" })),
-            icon: (DetachedElement {
-              classes: ("" : Nil),
-              content: "",
-              id: Nothing,
-              tag: "LI-ICON" })
+            icon: DetachedLiIcon "people"
             }) : (TopCardInsight {
               content: (TopCardInsightContentSingle (DetachedElement {
                 classes: ("" : Nil),