Bladeren bron

Move conversion to UI elements into ArtDeco

jherve 1 jaar geleden
bovenliggende
commit
af03978220

+ 35 - 0
src/LinkedIn/ArtDeco.purs

@@ -4,12 +4,17 @@ import Prelude
 
 
 import Data.Either (Either(..), hush)
 import Data.Either (Either(..), hush)
 import Data.Generic.Rep (class Generic)
 import Data.Generic.Rep (class Generic)
+import Data.List (List)
 import Data.List.NonEmpty (NonEmptyList)
 import Data.List.NonEmpty (NonEmptyList)
+import Data.List.NonEmpty as NEL
 import Data.Maybe (Maybe)
 import Data.Maybe (Maybe)
 import Data.Show.Generic (genericShow)
 import Data.Show.Generic (genericShow)
 import LinkedIn (DetachedNode)
 import LinkedIn (DetachedNode)
+import LinkedIn.Profile.Utils (toUIElement)
 import LinkedIn.Types (Parser)
 import LinkedIn.Types (Parser)
+import LinkedIn.UIElements.Types (UIElement)
 import LinkedIn.Utils (queryAndDetachMany, queryAndDetachOne, queryManyAndParse, queryOneAndParse)
 import LinkedIn.Utils (queryAndDetachMany, queryAndDetachOne, queryManyAndParse, queryOneAndParse)
+import Parsing (ParseError)
 
 
 
 
 data ArtDecoPvsEntity = ArtDecoPvsEntity {
 data ArtDecoPvsEntity = ArtDecoPvsEntity {
@@ -98,3 +103,33 @@ parseArtDecoPvsEntity n = do
   pure $ ado
   pure $ ado
     c <- center
     c <- center
   in ArtDecoPvsEntity {side: unit, center: c}
   in ArtDecoPvsEntity {side: unit, center: c}
+
+toUI ∷
+  ArtDecoPvsEntity
+  → {
+    bold' ∷ Either ParseError UIElement ,
+    content' ∷ List (Either ParseError UIElement) ,
+    light' ∷ Maybe (NonEmptyList (Either ParseError UIElement)) ,
+    normal' ∷ Maybe (Either ParseError UIElement)
+  }
+toUI (ArtDecoPvsEntity {
+    center: ArtDecoCenter {
+      header: ArtDecoCenterHeader {
+        bold,
+        normal,
+        light
+      },
+      content: ArtDecoCenterContent subComponents
+    }
+  }) = {bold', content', normal', light'} where
+  bold' = toUIElement bold
+
+  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
+
+  light' :: Maybe (NonEmptyList (Either ParseError UIElement))
+  light' = (map toUIElement) <$> light

+ 3 - 0
src/LinkedIn/ArtDecoCard.purs

@@ -7,6 +7,7 @@ import Data.Show.Generic (genericShow)
 import LinkedIn.Types (Parser)
 import LinkedIn.Types (Parser)
 import LinkedIn.Utils (queryOneAndParse)
 import LinkedIn.Utils (queryOneAndParse)
 import LinkedIn.ArtDeco (ArtDecoPvsEntity, parseArtDecoPvsEntity)
 import LinkedIn.ArtDeco (ArtDecoPvsEntity, parseArtDecoPvsEntity)
+import LinkedIn.ArtDeco as AD
 
 
 
 
 data ArtDecoCardElement = ArtDecoCardElement {
 data ArtDecoCardElement = ArtDecoCardElement {
@@ -25,3 +26,5 @@ parseArtDecoCard n = do
   pure $ ado
   pure $ ado
     p <- pvs
     p <- pvs
   in ArtDecoCardElement {pvs_entity: p}
   in ArtDecoCardElement {pvs_entity: p}
+
+toUI (ArtDecoCardElement { pvs_entity}) = AD.toUI pvs_entity

+ 3 - 0
src/LinkedIn/ArtDecoTab.purs

@@ -7,6 +7,7 @@ import Data.Show.Generic (genericShow)
 import LinkedIn.Types (Parser)
 import LinkedIn.Types (Parser)
 import LinkedIn.Utils (queryOneAndParse)
 import LinkedIn.Utils (queryOneAndParse)
 import LinkedIn.ArtDeco (ArtDecoPvsEntity, parseArtDecoPvsEntity)
 import LinkedIn.ArtDeco (ArtDecoPvsEntity, parseArtDecoPvsEntity)
+import LinkedIn.ArtDeco as AD
 
 
 
 
 data ArtDecoTabElement = ArtDecoTabElement {
 data ArtDecoTabElement = ArtDecoTabElement {
@@ -25,3 +26,5 @@ parseArtDecoTab n = do
   pure $ ado
   pure $ ado
     p <- pvs
     p <- pvs
   in ArtDecoTabElement {pvs_entity: p}
   in ArtDecoTabElement {pvs_entity: p}
+
+toUI (ArtDecoTabElement { pvs_entity }) = AD.toUI pvs_entity

+ 5 - 31
src/LinkedIn/Profile/Project.purs

@@ -7,16 +7,10 @@ import Prelude
 import Data.Either (Either, note)
 import Data.Either (Either, note)
 import Data.Foldable (findMap)
 import Data.Foldable (findMap)
 import Data.Generic.Rep (class Generic)
 import Data.Generic.Rep (class Generic)
-import Data.List (List)
-import Data.List.NonEmpty (NonEmptyList)
-import Data.List.NonEmpty as NEL
 import Data.Maybe (Maybe(..))
 import Data.Maybe (Maybe(..))
 import Data.Show.Generic (genericShow)
 import Data.Show.Generic (genericShow)
-import LinkedIn (DetachedNode)
-import LinkedIn.ArtDecoCard (ArtDecoCardElement(..))
-import LinkedIn.ArtDeco (ArtDecoCenter(..), ArtDecoCenterContent(..), ArtDecoCenterHeader(..), ArtDecoPvsEntity(..), ArtDecoPvsEntitySubComponent(..))
+import LinkedIn.ArtDecoCard (ArtDecoCardElement, toUI)
 import LinkedIn.UIElements.Types (TimeSpan, UIElement(..))
 import LinkedIn.UIElements.Types (TimeSpan, UIElement(..))
-import Parsing (ParseError)
 
 
 data Project = Project {
 data Project = Project {
   name :: String,
   name :: String,
@@ -29,36 +23,16 @@ instance Show Project where
   show = genericShow
   show = genericShow
 
 
 fromUI ∷ ArtDecoCardElement → Either String Project
 fromUI ∷ ArtDecoCardElement → Either String Project
-fromUI (ArtDecoCardElement {
-  pvs_entity: ArtDecoPvsEntity {
-    center: ArtDecoCenter {
-      header: ArtDecoCenterHeader {
-        bold,
-        normal,
-        light
-      },
-      content: ArtDecoCenterContent subComponents
-    }
-  }
-}) = ado
+fromUI card = ado
     name <- note "No position found" $ findMap extractName bold'
     name <- note "No position found" $ findMap extractName bold'
   in
   in
     Project {
     Project {
     name,
     name,
     timeSpan: maybeExtractFromMaybe extractTimeSpan normal',
     timeSpan: maybeExtractFromMaybe extractTimeSpan normal',
     description: maybeGetInList extractDescription content' 0
     description: maybeGetInList extractDescription content' 0
-  } where
-  bold' = toUIElement bold
-
-  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
-
-  light' :: Maybe (NonEmptyList (Either ParseError UIElement))
-  light' = (map toUIElement) <$> light
+  }
+  where
+    {bold', content', normal'} = toUI card
 
 
 extractName :: UIElement -> Maybe String
 extractName :: UIElement -> Maybe String
 extractName = case _ of
 extractName = case _ of

+ 5 - 11
src/LinkedIn/Profile/Skill.purs

@@ -9,8 +9,7 @@ import Data.Foldable (findMap)
 import Data.Generic.Rep (class Generic)
 import Data.Generic.Rep (class Generic)
 import Data.Maybe (Maybe(..))
 import Data.Maybe (Maybe(..))
 import Data.Show.Generic (genericShow)
 import Data.Show.Generic (genericShow)
-import LinkedIn.ArtDecoTab (ArtDecoTabElement(..))
-import LinkedIn.ArtDeco (ArtDecoCenter(..), ArtDecoCenterHeader(..), ArtDecoPvsEntity(..))
+import LinkedIn.ArtDecoTab (ArtDecoTabElement, toUI)
 import LinkedIn.UIElements.Types (UIElement(..))
 import LinkedIn.UIElements.Types (UIElement(..))
 
 
 data Skill = Skill {
 data Skill = Skill {
@@ -22,17 +21,12 @@ instance Show Skill where
   show = genericShow
   show = genericShow
 
 
 fromUI ∷ ArtDecoTabElement → Either String Skill
 fromUI ∷ ArtDecoTabElement → Either String Skill
-fromUI (ArtDecoTabElement {
-  pvs_entity: ArtDecoPvsEntity {
-    center: ArtDecoCenter {
-      header: ArtDecoCenterHeader { bold }
-    }
-  }
-}) = ado
+fromUI (tab) = ado
     name <- note "No position found" $ findMap extractName bold'
     name <- note "No position found" $ findMap extractName bold'
   in
   in
-    Skill { name } where
-  bold' = toUIElement bold
+    Skill { name }
+  where
+    {bold'} = toUI tab
 
 
 extractName :: UIElement -> Maybe String
 extractName :: UIElement -> Maybe String
 extractName = case _ of
 extractName = case _ of

+ 6 - 32
src/LinkedIn/Profile/WorkExperience.purs

@@ -1,22 +1,16 @@
 module LinkedIn.Profile.WorkExperience where
 module LinkedIn.Profile.WorkExperience where
 
 
+import LinkedIn.Profile.Utils
 import LinkedIn.UIElements.Parser
 import LinkedIn.UIElements.Parser
 import Prelude
 import Prelude
 
 
 import Data.Either (Either, note)
 import Data.Either (Either, note)
 import Data.Foldable (findMap)
 import Data.Foldable (findMap)
 import Data.Generic.Rep (class Generic)
 import Data.Generic.Rep (class Generic)
-import Data.List (List)
-import Data.List.NonEmpty (NonEmptyList)
-import Data.List.NonEmpty as NEL
 import Data.Maybe (Maybe(..))
 import Data.Maybe (Maybe(..))
 import Data.Show.Generic (genericShow)
 import Data.Show.Generic (genericShow)
-import LinkedIn (DetachedNode)
-import LinkedIn.ArtDecoCard (ArtDecoCardElement(..))
-import LinkedIn.ArtDeco (ArtDecoCenter(..), ArtDecoCenterContent(..), ArtDecoCenterHeader(..), ArtDecoPvsEntity(..), ArtDecoPvsEntitySubComponent(..))
+import LinkedIn.ArtDecoCard (ArtDecoCardElement, toUI)
 import LinkedIn.UIElements.Types (Duration, TimeSpan, UIElement(..))
 import LinkedIn.UIElements.Types (Duration, TimeSpan, UIElement(..))
-import LinkedIn.Profile.Utils
-import Parsing (ParseError)
 
 
 data WorkExperience = WorkExperience {
 data WorkExperience = WorkExperience {
   position :: String,
   position :: String,
@@ -33,18 +27,7 @@ instance Show WorkExperience where
   show = genericShow
   show = genericShow
 
 
 fromUI ∷ ArtDecoCardElement → Either String WorkExperience
 fromUI ∷ ArtDecoCardElement → Either String WorkExperience
-fromUI (ArtDecoCardElement {
-  pvs_entity: ArtDecoPvsEntity {
-    center: ArtDecoCenter {
-      header: ArtDecoCenterHeader {
-        bold,
-        normal,
-        light
-      },
-      content: ArtDecoCenterContent subComponents
-    }
-  }
-}) = ado
+fromUI (card) = ado
     position <- note "No position found" $ findMap extractPosition bold'
     position <- note "No position found" $ findMap extractPosition bold'
   in
   in
     WorkExperience {
     WorkExperience {
@@ -54,18 +37,9 @@ fromUI (ArtDecoCardElement {
     timeSpan: maybeFindInMaybeNEL extractTimeSpan light',
     timeSpan: maybeFindInMaybeNEL extractTimeSpan light',
     duration: maybeFindInMaybeNEL extractDuration light',
     duration: maybeFindInMaybeNEL extractDuration light',
     description: maybeGetInList extractDescription content' 0
     description: maybeGetInList extractDescription content' 0
-  } where
-  bold' = toUIElement bold
-
-  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
-
-  light' :: Maybe (NonEmptyList (Either ParseError UIElement))
-  light' = (map toUIElement) <$> light
+  }
+  where
+    {bold', content', normal', light'} = toUI card
 
 
 extractPosition :: UIElement -> Maybe String
 extractPosition :: UIElement -> Maybe String
 extractPosition = case _ of
 extractPosition = case _ of