ArtDeco.purs 7.2 KB

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