Browse Source

Make ArtDeco classes generic

jherve 1 year ago
parent
commit
9a90a42bf5

+ 35 - 35
src/LinkedIn/ArtDeco.purs

@@ -17,66 +17,66 @@ import LinkedIn.Utils (queryAndDetachMany, queryAndDetachOne, queryManyAndParse,
 import Parsing (ParseError)
 
 
-data ArtDecoPvsEntity = ArtDecoPvsEntity {
+data ArtDecoPvsEntity a = ArtDecoPvsEntity {
   side :: Unit,
-  center :: ArtDecoCenter
+  center :: ArtDecoCenter a
 }
 
-data ArtDecoCenter = ArtDecoCenter {
-  header :: ArtDecoCenterHeader,
-  content :: ArtDecoCenterContent
+data ArtDecoCenter a = ArtDecoCenter {
+  header :: ArtDecoCenterHeader a,
+  content :: ArtDecoCenterContent a
 }
 
-data ArtDecoCenterHeader = ArtDecoCenterHeader {
-  bold :: DetachedNode,
-  normal :: Maybe DetachedNode,
-  light :: Maybe (NonEmptyList DetachedNode)
+data ArtDecoCenterHeader a = ArtDecoCenterHeader {
+  bold :: a,
+  normal :: Maybe a,
+  light :: Maybe (NonEmptyList a)
 }
 
-data ArtDecoCenterContent = ArtDecoCenterContent (NonEmptyList ArtDecoPvsEntitySubComponent)
+data ArtDecoCenterContent a = ArtDecoCenterContent (NonEmptyList (ArtDecoPvsEntitySubComponent a))
 
-data ArtDecoPvsEntitySubComponent = ArtDecoPvsEntitySubComponent (Maybe DetachedNode)
+data ArtDecoPvsEntitySubComponent a = ArtDecoPvsEntitySubComponent (Maybe a)
 
 
-derive instance Generic ArtDecoPvsEntitySubComponent _
-derive instance Eq ArtDecoPvsEntitySubComponent
-instance Show ArtDecoPvsEntitySubComponent where
+derive instance Generic (ArtDecoPvsEntitySubComponent a) _
+derive instance Eq a => Eq (ArtDecoPvsEntitySubComponent a)
+instance Show a => Show (ArtDecoPvsEntitySubComponent a) where
   show = genericShow
 
-derive instance Generic ArtDecoCenterContent _
-derive instance Eq ArtDecoCenterContent
-instance Show ArtDecoCenterContent where
+derive instance Generic (ArtDecoCenterContent a) _
+derive instance Eq a => Eq(ArtDecoCenterContent a)
+instance Show a => Show(ArtDecoCenterContent a) where
   show = genericShow
 
-derive instance Generic ArtDecoCenterHeader _
-derive instance Eq ArtDecoCenterHeader
-instance Show ArtDecoCenterHeader where
+derive instance Generic (ArtDecoCenterHeader a) _
+derive instance Eq a => Eq(ArtDecoCenterHeader a)
+instance Show a => Show(ArtDecoCenterHeader a) where
   show = genericShow
 
-derive instance Generic ArtDecoCenter _
-derive instance Eq ArtDecoCenter
-instance Show ArtDecoCenter where
+derive instance Generic (ArtDecoCenter a) _
+derive instance Eq a => Eq(ArtDecoCenter a)
+instance Show a => Show(ArtDecoCenter a) where
   show = genericShow
 
-derive instance Generic ArtDecoPvsEntity _
-derive instance Eq ArtDecoPvsEntity
-instance Show ArtDecoPvsEntity where
+derive instance Generic (ArtDecoPvsEntity a) _
+derive instance Eq a => Eq(ArtDecoPvsEntity a)
+instance Show a => Show(ArtDecoPvsEntity a) where
   show = genericShow
 
 
-parseArtDecoPvsEntitySubComponent ∷ Parser ArtDecoPvsEntitySubComponent
+parseArtDecoPvsEntitySubComponent ∷ Parser (ArtDecoPvsEntitySubComponent DetachedNode)
 parseArtDecoPvsEntitySubComponent n = do
   content <- queryAndDetachOne "span[aria-hidden=true]" n
   pure $ Right $ ArtDecoPvsEntitySubComponent $ hush content
 
-parseArtDecoCenterContent ∷ Parser ArtDecoCenterContent
+parseArtDecoCenterContent ∷ Parser (ArtDecoCenterContent DetachedNode)
 parseArtDecoCenterContent n = do
   list <- queryManyAndParse ":scope > ul > li" parseArtDecoPvsEntitySubComponent n
   pure $ ado
     l <- list
   in ArtDecoCenterContent l
 
-parseArtDecoCenterHeader :: Parser ArtDecoCenterHeader
+parseArtDecoCenterHeader :: Parser (ArtDecoCenterHeader DetachedNode)
 parseArtDecoCenterHeader n = do
   bold <- queryAndDetachOne ":scope div.t-bold > span[aria-hidden=true]" n
   normal <- queryAndDetachOne ":scope span.t-normal:not(t-black--light) > span[aria-hidden=true]" n
@@ -86,7 +86,7 @@ parseArtDecoCenterHeader n = do
     b <- bold
   in ArtDecoCenterHeader {bold: b, normal: hush normal, light: hush light}
 
-parseArtDecoCenter :: Parser ArtDecoCenter
+parseArtDecoCenter :: Parser (ArtDecoCenter DetachedNode)
 parseArtDecoCenter n = do
   header <- queryOneAndParse ":scope > div" parseArtDecoCenterHeader n
   content <- queryOneAndParse ":scope > div.pvs-entity__sub-components" parseArtDecoCenterContent n
@@ -96,7 +96,7 @@ parseArtDecoCenter n = do
     c <- content
   in ArtDecoCenter {header: h, content: c}
 
-parseArtDecoPvsEntity :: Parser ArtDecoPvsEntity
+parseArtDecoPvsEntity :: Parser (ArtDecoPvsEntity DetachedNode)
 parseArtDecoPvsEntity n = do
   center <- queryOneAndParse ":scope > div.display-flex" parseArtDecoCenter n
 
@@ -104,23 +104,23 @@ parseArtDecoPvsEntity n = do
     c <- center
   in ArtDecoPvsEntity {side: unit, center: c}
 
-toHeaderBold ∷ ArtDecoPvsEntity → Either ParseError UIElement
+toHeaderBold ∷ ArtDecoPvsEntity DetachedNode → Either ParseError UIElement
 toHeaderBold (ArtDecoPvsEntity {
     center: ArtDecoCenter { header: ArtDecoCenterHeader { bold }
   }
 }) = toUIElement bold
 
-toHeaderNormal ∷ ArtDecoPvsEntity → Maybe (Either ParseError UIElement)
+toHeaderNormal ∷ ArtDecoPvsEntity DetachedNode → Maybe (Either ParseError UIElement)
 toHeaderNormal (ArtDecoPvsEntity {
   center: ArtDecoCenter { header: ArtDecoCenterHeader { normal }}
 }) = toUIElement <$> normal
 
-toHeaderLight ∷ ArtDecoPvsEntity → Maybe (NonEmptyList (Either ParseError UIElement))
+toHeaderLight ∷ ArtDecoPvsEntity DetachedNode → Maybe (NonEmptyList (Either ParseError UIElement))
 toHeaderLight (ArtDecoPvsEntity {
   center: ArtDecoCenter { header: ArtDecoCenterHeader { light } }
 }) = (map toUIElement) <$> light
 
-toCenterContent ∷ ArtDecoPvsEntity → List (Either ParseError UIElement)
+toCenterContent ∷ ArtDecoPvsEntity DetachedNode → List (Either ParseError UIElement)
 toCenterContent (ArtDecoPvsEntity {
   center: ArtDecoCenter { content: ArtDecoCenterContent subComponents }
 }) = map toUIElement subC

+ 12 - 11
src/LinkedIn/ArtDecoCard.purs

@@ -8,6 +8,7 @@ import Data.List (List)
 import Data.List.Types (NonEmptyList)
 import Data.Maybe (Maybe)
 import Data.Show.Generic (genericShow)
+import LinkedIn (DetachedNode)
 import LinkedIn.ArtDeco (ArtDecoPvsEntity, parseArtDecoPvsEntity)
 import LinkedIn.ArtDeco as AD
 import LinkedIn.Types (Parser)
@@ -16,16 +17,16 @@ import LinkedIn.Utils (queryOneAndParse)
 import Parsing (ParseError)
 
 
-data ArtDecoCardElement = ArtDecoCardElement {
-  pvs_entity :: ArtDecoPvsEntity
+data ArtDecoCardElement a = ArtDecoCardElement {
+  pvs_entity :: ArtDecoPvsEntity a
 }
 
-derive instance Generic ArtDecoCardElement _
-derive instance Eq ArtDecoCardElement
-instance Show ArtDecoCardElement where
+derive instance Generic (ArtDecoCardElement a) _
+derive instance Eq a => Eq (ArtDecoCardElement a)
+instance Show a => Show (ArtDecoCardElement a) where
   show = genericShow
 
-parseArtDecoCard :: Parser ArtDecoCardElement
+parseArtDecoCard :: Parser (ArtDecoCardElement DetachedNode)
 parseArtDecoCard n = do
   pvs <- queryOneAndParse ":scope div.pvs-entity--padded" parseArtDecoPvsEntity n
 
@@ -33,17 +34,17 @@ parseArtDecoCard n = do
     p <- pvs
   in ArtDecoCardElement {pvs_entity: p}
 
-toCenterContent ∷ ArtDecoCardElement → List (Either ParseError UIElement)
+toCenterContent ∷ ArtDecoCardElement DetachedNode → List (Either ParseError UIElement)
 toCenterContent = toPvsEntity >>> AD.toCenterContent
 
-toHeaderBold ∷ ArtDecoCardElement → Either ParseError UIElement
+toHeaderBold ∷ ArtDecoCardElement DetachedNode → Either ParseError UIElement
 toHeaderBold = toPvsEntity >>> AD.toHeaderBold
 
-toHeaderLight ∷ ArtDecoCardElement → Maybe (NonEmptyList (Either ParseError UIElement))
+toHeaderLight ∷ ArtDecoCardElement DetachedNode → Maybe (NonEmptyList (Either ParseError UIElement))
 toHeaderLight = toPvsEntity >>> AD.toHeaderLight
 
-toHeaderNormal ∷ ArtDecoCardElement → Maybe (Either ParseError UIElement)
+toHeaderNormal ∷ ArtDecoCardElement DetachedNode → Maybe (Either ParseError UIElement)
 toHeaderNormal = toPvsEntity >>> AD.toHeaderNormal
 
-toPvsEntity ∷ ArtDecoCardElement → ArtDecoPvsEntity
+toPvsEntity ∷ forall a. ArtDecoCardElement a → ArtDecoPvsEntity a
 toPvsEntity (ArtDecoCardElement { pvs_entity }) = pvs_entity

+ 15 - 14
src/LinkedIn/ArtDecoTab.purs

@@ -8,24 +8,25 @@ import Data.List (List)
 import Data.List.Types (NonEmptyList)
 import Data.Maybe (Maybe)
 import Data.Show.Generic (genericShow)
-import LinkedIn.Types (Parser)
-import LinkedIn.Utils (queryOneAndParse)
-import LinkedIn.UIElements.Types (UIElement)
+import LinkedIn (DetachedNode)
 import LinkedIn.ArtDeco (ArtDecoPvsEntity, parseArtDecoPvsEntity)
 import LinkedIn.ArtDeco as AD
+import LinkedIn.Types (Parser)
+import LinkedIn.UIElements.Types (UIElement)
+import LinkedIn.Utils (queryOneAndParse)
 import Parsing (ParseError)
 
 
-data ArtDecoTabElement = ArtDecoTabElement {
-  pvs_entity :: ArtDecoPvsEntity
+data ArtDecoTabElement a = ArtDecoTabElement {
+  pvs_entity :: ArtDecoPvsEntity a
 }
 
-derive instance Generic ArtDecoTabElement _
-derive instance Eq ArtDecoTabElement
-instance Show ArtDecoTabElement where
+derive instance Generic (ArtDecoTabElement a) _
+derive instance Eq a => Eq (ArtDecoTabElement a)
+instance Show a => Show (ArtDecoTabElement a) where
   show = genericShow
 
-parseArtDecoTab :: Parser ArtDecoTabElement
+parseArtDecoTab :: Parser (ArtDecoTabElement DetachedNode)
 parseArtDecoTab n = do
   pvs <- queryOneAndParse ":scope div.pvs-entity--padded" parseArtDecoPvsEntity n
 
@@ -33,17 +34,17 @@ parseArtDecoTab n = do
     p <- pvs
   in ArtDecoTabElement {pvs_entity: p}
 
-toCenterContent ∷ ArtDecoTabElement → List (Either ParseError UIElement)
+toCenterContent ∷ ArtDecoTabElement DetachedNode → List (Either ParseError UIElement)
 toCenterContent = toPvsEntity >>> AD.toCenterContent
 
-toHeaderBold ∷ ArtDecoTabElement → Either ParseError UIElement
+toHeaderBold ∷ ArtDecoTabElement DetachedNode → Either ParseError UIElement
 toHeaderBold = toPvsEntity >>> AD.toHeaderBold
 
-toHeaderLight ∷ ArtDecoTabElement → Maybe (NonEmptyList (Either ParseError UIElement))
+toHeaderLight ∷ ArtDecoTabElement DetachedNode → Maybe (NonEmptyList (Either ParseError UIElement))
 toHeaderLight = toPvsEntity >>> AD.toHeaderLight
 
-toHeaderNormal ∷ ArtDecoTabElement → Maybe (Either ParseError UIElement)
+toHeaderNormal ∷ ArtDecoTabElement DetachedNode → Maybe (Either ParseError UIElement)
 toHeaderNormal = toPvsEntity >>> AD.toHeaderNormal
 
-toPvsEntity ∷ ArtDecoTabElement → ArtDecoPvsEntity
+toPvsEntity ∷ forall a. ArtDecoTabElement a → ArtDecoPvsEntity a
 toPvsEntity (ArtDecoTabElement { pvs_entity }) = pvs_entity

+ 3 - 2
src/LinkedIn/Profile/Project.purs

@@ -7,8 +7,9 @@ import Data.Foldable (findMap)
 import Data.Generic.Rep (class Generic)
 import Data.Maybe (Maybe(..))
 import Data.Show.Generic (genericShow)
+import LinkedIn (DetachedNode)
+import LinkedIn.ArtDecoCard (ArtDecoCardElement, toCenterContent, toHeaderBold, toHeaderNormal)
 import LinkedIn.Profile.Utils (maybeExtractFromMaybe, maybeGetInList)
-import LinkedIn.ArtDecoCard (ArtDecoCardElement,  toCenterContent, toHeaderBold, toHeaderNormal)
 import LinkedIn.UIElements.Types (TimeSpan, UIElement(..))
 
 data Project = Project {
@@ -21,7 +22,7 @@ derive instance Generic Project _
 instance Show Project where
   show = genericShow
 
-fromUI ∷ ArtDecoCardElement → Either String Project
+fromUI ∷ ArtDecoCardElement DetachedNode → Either String Project
 fromUI card = ado
     name <- note "No position found" $ findMap extractName bold
   in

+ 2 - 1
src/LinkedIn/Profile/Skill.purs

@@ -7,6 +7,7 @@ import Data.Foldable (findMap)
 import Data.Generic.Rep (class Generic)
 import Data.Maybe (Maybe(..))
 import Data.Show.Generic (genericShow)
+import LinkedIn (DetachedNode)
 import LinkedIn.ArtDecoTab (ArtDecoTabElement, toHeaderBold)
 import LinkedIn.UIElements.Types (UIElement(..))
 
@@ -18,7 +19,7 @@ derive instance Generic Skill _
 instance Show Skill where
   show = genericShow
 
-fromUI ∷ ArtDecoTabElement → Either String Skill
+fromUI ∷ ArtDecoTabElement DetachedNode → Either String Skill
 fromUI (tab) = ado
     name <- note "No position found" $ findMap extractName bold
   in

+ 2 - 1
src/LinkedIn/Profile/WorkExperience.purs

@@ -7,6 +7,7 @@ import Data.Foldable (findMap)
 import Data.Generic.Rep (class Generic)
 import Data.Maybe (Maybe(..))
 import Data.Show.Generic (genericShow)
+import LinkedIn (DetachedNode)
 import LinkedIn.ArtDecoCard (ArtDecoCardElement, toCenterContent, toHeaderBold, toHeaderLight, toHeaderNormal)
 import LinkedIn.Profile.Utils (maybeExtractFromMaybe, maybeFindInMaybeNEL, maybeGetInList)
 import LinkedIn.UIElements.Types (Duration, TimeSpan, UIElement(..))
@@ -25,7 +26,7 @@ derive instance Eq WorkExperience
 instance Show WorkExperience where
   show = genericShow
 
-fromUI ∷ ArtDecoCardElement → Either String WorkExperience
+fromUI ∷ ArtDecoCardElement DetachedNode → Either String WorkExperience
 fromUI (card) = ado
     position <- note "No position found" $ findMap extractPosition bold
   in

+ 1 - 1
test/ArtDecoCard.purs

@@ -90,7 +90,7 @@ testArtDecoCards = do
           })
       }
 
-parseHeadCard ∷ Partial => Maybe (NonEmptyList LinkedInUIElement) → Effect (Either ParseError ArtDecoCardElement)
+parseHeadCard ∷ Partial => Maybe (NonEmptyList LinkedInUIElement) → Effect (Either ParseError (ArtDecoCardElement DetachedNode))
 parseHeadCard (Just l) = do
   parsed <- (\(LinkedInUIElement _ n) -> parseArtDecoCard n) $ NEL.head l
   pure $ parsed