ArtDeco.purs 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. module LinkedIn.UI.Components.ArtDeco where
  2. import Prelude
  3. import Data.Foldable (class Foldable, foldMap, foldlDefault, foldrDefault)
  4. import Data.Generic.Rep (class Generic)
  5. import Data.Lens (Lens', Traversal', lens', traversed)
  6. import Data.Lens.Record (prop)
  7. import Data.List (List)
  8. import Data.List.NonEmpty (NonEmptyList)
  9. import Data.Maybe (Maybe)
  10. import Data.Show.Generic (genericShow)
  11. import Data.Traversable (class Traversable, sequence, traverseDefault)
  12. import Data.Tuple (Tuple(..))
  13. import LinkedIn.CanBeQueried (class CanBeQueried, subQueryNEL, subQueryOne)
  14. import LinkedIn.QueryRunner (ignoreNotFound, queryList, queryOne)
  15. import LinkedIn.Queryable (class Queryable)
  16. import Type.Proxy (Proxy(..))
  17. type ArtDecoPvsEntityObject a = { side :: Unit, center :: ArtDecoCenter a }
  18. newtype ArtDecoPvsEntity a = ArtDecoPvsEntity (ArtDecoPvsEntityObject a)
  19. type ArtDecoCenterObject a = { header :: ArtDecoCenterHeader a, content :: ArtDecoCenterContent a}
  20. newtype ArtDecoCenter a = ArtDecoCenter (ArtDecoCenterObject a)
  21. type ArtDecoCenterHeaderObject a = { bold :: a, normal :: Maybe a, light :: List a}
  22. newtype ArtDecoCenterHeader a = ArtDecoCenterHeader (ArtDecoCenterHeaderObject a)
  23. newtype ArtDecoCenterContent a = ArtDecoCenterContent (NonEmptyList (ArtDecoPvsEntitySubComponent a))
  24. newtype ArtDecoPvsEntitySubComponent a = ArtDecoPvsEntitySubComponent a
  25. derive instance Generic (ArtDecoPvsEntitySubComponent a) _
  26. derive instance Eq a => Eq (ArtDecoPvsEntitySubComponent a)
  27. instance Show a => Show (ArtDecoPvsEntitySubComponent a) where show = genericShow
  28. derive instance Functor ArtDecoPvsEntitySubComponent
  29. instance Foldable ArtDecoPvsEntitySubComponent where
  30. foldMap f (ArtDecoPvsEntitySubComponent sc) = f sc
  31. foldl = \x -> foldlDefault x
  32. foldr = \x -> foldrDefault x
  33. instance Traversable ArtDecoPvsEntitySubComponent where
  34. sequence (ArtDecoPvsEntitySubComponent subComponents) = ado
  35. sc <- subComponents
  36. in ArtDecoPvsEntitySubComponent sc
  37. traverse = \x -> traverseDefault x
  38. instance Queryable q => CanBeQueried q ArtDecoPvsEntitySubComponent where
  39. query n = do
  40. content <- queryOne "span[aria-hidden=true]" n
  41. pure $ ArtDecoPvsEntitySubComponent content
  42. derive instance Generic (ArtDecoCenterContent a) _
  43. derive instance Eq a => Eq(ArtDecoCenterContent a)
  44. instance Show a => Show(ArtDecoCenterContent a) where show = genericShow
  45. derive instance Functor ArtDecoCenterContent
  46. instance Foldable ArtDecoCenterContent where
  47. foldMap f (ArtDecoCenterContent c) = foldMap (foldMap f) c
  48. foldl = \x -> foldlDefault x
  49. foldr = \x -> foldrDefault x
  50. instance Traversable ArtDecoCenterContent where
  51. sequence (ArtDecoCenterContent center) = ado
  52. c <- sequence (map sequence center)
  53. in ArtDecoCenterContent c
  54. traverse = \x -> traverseDefault x
  55. instance Queryable q => CanBeQueried q ArtDecoCenterContent where
  56. query n = do
  57. sc <- subQueryNEL ":scope > ul > li" n
  58. pure $ ArtDecoCenterContent sc
  59. derive instance Generic (ArtDecoCenterHeader a) _
  60. derive instance Eq a => Eq(ArtDecoCenterHeader a)
  61. instance Show a => Show(ArtDecoCenterHeader a) where show = genericShow
  62. derive instance Functor ArtDecoCenterHeader
  63. instance Foldable ArtDecoCenterHeader where
  64. foldMap f (ArtDecoCenterHeader {bold, normal, light}) = f bold <> foldMap f normal <> foldMap f light
  65. foldl = \x -> foldlDefault x
  66. foldr = \x -> foldrDefault x
  67. instance Traversable ArtDecoCenterHeader where
  68. sequence (ArtDecoCenterHeader {bold, normal, light}) = ado
  69. b <- bold
  70. n <- sequence normal
  71. l <- sequence light
  72. in ArtDecoCenterHeader {bold: b, normal: n, light: l}
  73. traverse = \x -> traverseDefault x
  74. instance Queryable q => CanBeQueried q ArtDecoCenterHeader where
  75. query n = do
  76. bold <- queryOne ":scope div.t-bold > span[aria-hidden=true]" n
  77. normal <-
  78. ignoreNotFound $
  79. queryOne ":scope span.t-normal:not(t-black--light) > span[aria-hidden=true]" n
  80. light <-
  81. queryList ":scope span.t-black--light > span[aria-hidden=true]" n
  82. pure $ ArtDecoCenterHeader {bold, normal, light}
  83. derive instance Generic (ArtDecoCenter a) _
  84. derive instance Eq a => Eq(ArtDecoCenter a)
  85. instance Show a => Show(ArtDecoCenter a) where show = genericShow
  86. derive instance Functor ArtDecoCenter
  87. instance Foldable ArtDecoCenter where
  88. foldMap f (ArtDecoCenter {header, content}) = foldMap f header <> foldMap f content
  89. foldl = \x -> foldlDefault x
  90. foldr = \x -> foldrDefault x
  91. instance Traversable ArtDecoCenter where
  92. sequence (ArtDecoCenter {header, content}) = ado
  93. h <- sequence header
  94. c <- sequence content
  95. in ArtDecoCenter {header: h, content: c}
  96. traverse = \x -> traverseDefault x
  97. instance Queryable q => CanBeQueried q ArtDecoCenter where
  98. query n = do
  99. header <- subQueryOne ":scope > div" n
  100. content <- subQueryOne ":scope > div.pvs-entity__sub-components" n
  101. pure $ ArtDecoCenter {header, content}
  102. derive instance Generic (ArtDecoPvsEntity a) _
  103. derive instance Eq a => Eq(ArtDecoPvsEntity a)
  104. instance Show a => Show(ArtDecoPvsEntity a) where show = genericShow
  105. derive instance Functor ArtDecoPvsEntity
  106. instance Foldable ArtDecoPvsEntity where
  107. foldMap f (ArtDecoPvsEntity {side: _, center}) = foldMap f center
  108. foldl = \x -> foldlDefault x
  109. foldr = \x -> foldrDefault x
  110. instance Traversable ArtDecoPvsEntity where
  111. sequence (ArtDecoPvsEntity {side, center}) = ado
  112. s <- pure side
  113. c <- sequence center
  114. in ArtDecoPvsEntity {side: s, center: c}
  115. traverse = \x -> traverseDefault x
  116. instance Queryable q => CanBeQueried q ArtDecoPvsEntity where
  117. query n = do
  118. center <- subQueryOne ":scope > div.display-flex" n
  119. pure $ ArtDecoPvsEntity {side: unit, center}
  120. _pvs_entity :: forall a. Lens' (ArtDecoPvsEntity a) { center ∷ ArtDecoCenter a , side ∷ Unit }
  121. _pvs_entity = lens'
  122. \(ArtDecoPvsEntity pvs) -> Tuple pvs \pvs' -> ArtDecoPvsEntity pvs'
  123. _center :: forall a. Lens' (ArtDecoCenter a) { content ∷ ArtDecoCenterContent a , header ∷ ArtDecoCenterHeader a }
  124. _center = lens'
  125. \(ArtDecoCenter center) -> Tuple center \center' -> ArtDecoCenter center'
  126. _header :: forall a. Lens' (ArtDecoCenterHeader a) { bold ∷ a , light ∷ List a , normal ∷ Maybe a }
  127. _header = lens' \(ArtDecoCenterHeader h) -> Tuple h \h' -> ArtDecoCenterHeader h'
  128. _content :: forall a. Lens' (ArtDecoCenterContent a) (NonEmptyList (ArtDecoPvsEntitySubComponent a))
  129. _content = lens' \(ArtDecoCenterContent cs) -> Tuple cs \cs' -> ArtDecoCenterContent cs'
  130. _sub_component :: forall a. Lens' (ArtDecoPvsEntitySubComponent a) a
  131. _sub_component = lens' \(ArtDecoPvsEntitySubComponent s) -> Tuple s \s' -> ArtDecoPvsEntitySubComponent s'
  132. _pvs_to_header :: forall a. Lens' (ArtDecoPvsEntity a) { bold ∷ a , light ∷ List a , normal ∷ Maybe a }
  133. _pvs_to_header = _pvs_entity
  134. <<< prop (Proxy :: Proxy "center")
  135. <<< _center
  136. <<< prop (Proxy :: Proxy "header")
  137. <<< _header
  138. _pvs_to_subcomponents ∷ ∀ a. Traversal' (ArtDecoPvsEntity a) a
  139. _pvs_to_subcomponents = _pvs_entity
  140. <<< prop (Proxy :: Proxy "center")
  141. <<< _center
  142. <<< prop (Proxy :: Proxy "content")
  143. <<< _content
  144. <<< traversed
  145. <<< _sub_component
  146. _pvs_to_header_bold :: forall a. Lens' (ArtDecoPvsEntity a) a
  147. _pvs_to_header_bold = _pvs_to_header <<< prop (Proxy :: Proxy "bold")
  148. _pvs_to_header_normal :: forall a. Lens' (ArtDecoPvsEntity a) (Maybe a)
  149. _pvs_to_header_normal = _pvs_to_header <<< prop (Proxy :: Proxy "normal")
  150. _pvs_to_header_light :: forall a. Lens' (ArtDecoPvsEntity a) (List a)
  151. _pvs_to_header_light = _pvs_to_header <<< prop (Proxy :: Proxy "light")