|
|
@@ -2,7 +2,8 @@ module LinkedIn.Profile.Utils where
|
|
|
|
|
|
import Prelude
|
|
|
|
|
|
-import Data.Either (Either, hush)
|
|
|
+import Control.Alt ((<|>))
|
|
|
+import Data.Either (Either(..), hush)
|
|
|
import Data.Foldable (class Foldable, findMap)
|
|
|
import Data.List (List)
|
|
|
import Data.List as L
|
|
|
@@ -10,7 +11,7 @@ import Data.Maybe (Maybe(..))
|
|
|
import LinkedIn.DetachedNode (DetachedNode(..))
|
|
|
import LinkedIn.UIElements.Parser (uiElementP)
|
|
|
import LinkedIn.UIElements.Types (UIElement(..))
|
|
|
-import Parsing (runParser, ParseError)
|
|
|
+import Parsing (ParseError(..), initialPos, runParser)
|
|
|
|
|
|
maybeGetInList ::
|
|
|
∀ a. (UIElement → Maybe a)
|
|
|
@@ -34,11 +35,18 @@ maybeFindInMaybeNEL extract = case _ of
|
|
|
Just nel -> findMap (hush >>> (extract =<< _)) nel
|
|
|
Nothing -> Nothing
|
|
|
|
|
|
+-- TODO : should certainly use another type than ParseError here
|
|
|
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 (DetachedButton {content, role}) = map toButton $ runParser content uiElementP
|
|
|
where toButton ui = UIButton role ui
|
|
|
+
|
|
|
toUIElement (DetachedA {content, href}) = map toLink $ runParser content uiElementP
|
|
|
where toLink ui = UILink href ui
|