Browse Source

Make ArtDecoPvsEntitySubComponent content optional

jherve 1 năm trước cách đây
mục cha
commit
0b509ad9b4
2 tập tin đã thay đổi với 12 bổ sung10 xóa
  1. 3 5
      src/LinkedIn/ArtDecoCard.purs
  2. 9 5
      src/LinkedIn/Profile/WorkExperience.purs

+ 3 - 5
src/LinkedIn/ArtDecoCard.purs

@@ -2,7 +2,7 @@ module LinkedIn.ArtDecoCard where
 
 import Prelude
 
-import Data.Either (hush)
+import Data.Either (Either(..), hush)
 import Data.Generic.Rep (class Generic)
 import Data.List.NonEmpty (NonEmptyList)
 import Data.Maybe (Maybe)
@@ -34,7 +34,7 @@ data ArtDecoCenterHeader = ArtDecoCenterHeader {
 
 data ArtDecoCenterContent = ArtDecoCenterContent (NonEmptyList ArtDecoPvsEntitySubComponent)
 
-data ArtDecoPvsEntitySubComponent = ArtDecoPvsEntitySubComponent DetachedNode
+data ArtDecoPvsEntitySubComponent = ArtDecoPvsEntitySubComponent (Maybe DetachedNode)
 
 
 derive instance Generic ArtDecoPvsEntitySubComponent _
@@ -71,9 +71,7 @@ instance Show ArtDecoCardElement where
 parseArtDecoPvsEntitySubComponent ∷ Parser ArtDecoPvsEntitySubComponent
 parseArtDecoPvsEntitySubComponent n = do
   content <- queryAndDetachOne "span[aria-hidden=true]" n
-  pure $ ado
-    c <- content
-  in ArtDecoPvsEntitySubComponent c
+  pure $ Right $ ArtDecoPvsEntitySubComponent $ hush content
 
 parseArtDecoCenterContent ∷ Parser ArtDecoCenterContent
 parseArtDecoCenterContent n = do

+ 9 - 5
src/LinkedIn/Profile/WorkExperience.purs

@@ -5,6 +5,8 @@ import Prelude
 
 import Data.Either (Either(..), hush, note)
 import Data.Generic.Rep (class Generic)
+import Data.List (List(..))
+import Data.List as L
 import Data.List.NonEmpty (NonEmptyList)
 import Data.List.NonEmpty as NEL
 import Data.Maybe (Maybe(..))
@@ -52,8 +54,9 @@ fromUI (ArtDecoCardElement {
   } where
   bold' = toUIElement bold
 
-  content' :: NonEmptyList (Either ParseError UIElement)
-  content' = map (\(ArtDecoPvsEntitySubComponent c) -> toUIElement c) subComponents
+  content' :: List (Either ParseError UIElement)
+  content' = map toUIElement subC
+    where subC = NEL.catMaybes $ map (\(ArtDecoPvsEntitySubComponent c) -> c) subComponents :: List (DetachedNode)
 
   normal' :: Maybe (Either ParseError UIElement)
   normal' = toUIElement <$> normal
@@ -93,9 +96,10 @@ extractDuration light = case light of
     getDuration (Right (UIDotSeparated _ (UIDuration d))) = Just d
     getDuration _ = Nothing
 
-extractDescription ∷ NonEmptyList (Either ParseError UIElement) → Either String String
-extractDescription  content = case NEL.head content of
-    Right (UIPlainText d) -> Right d
+extractDescription ∷ List (Either ParseError UIElement) → Either String String
+extractDescription Nil = Left "no description"
+extractDescription cs = case L.head cs of
+    Just (Right (UIPlainText d)) -> Right d
     _ -> Left "No description"
 
 toUIElement ∷ DetachedNode → Either ParseError UIElement