ArtDeco.purs 7.3 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.NonEmpty (NonEmptyList)
  8. import Data.Maybe (Maybe)
  9. import Data.Show.Generic (genericShow)
  10. import Data.Traversable (class Traversable, sequence, traverseDefault)
  11. import Data.Tuple (Tuple(..))
  12. import LinkedIn.CanBeQueried (class CanBeQueried, subQueryMany, subQueryOne)
  13. import LinkedIn.QueryRunner (ignoreNotFound, queryAll, queryOne)
  14. import LinkedIn.Queryable (class Queryable)
  15. import Type.Proxy (Proxy(..))
  16. data ArtDecoPvsEntity a = ArtDecoPvsEntity {
  17. side :: Unit,
  18. center :: ArtDecoCenter a
  19. }
  20. data ArtDecoCenter a = ArtDecoCenter {
  21. header :: ArtDecoCenterHeader a,
  22. content :: ArtDecoCenterContent a
  23. }
  24. data ArtDecoCenterHeader a = ArtDecoCenterHeader {
  25. bold :: a,
  26. normal :: Maybe a,
  27. light :: Maybe (NonEmptyList a)
  28. }
  29. data ArtDecoCenterContent a = ArtDecoCenterContent (NonEmptyList (ArtDecoPvsEntitySubComponent a))
  30. data ArtDecoPvsEntitySubComponent a = ArtDecoPvsEntitySubComponent a
  31. derive instance Generic (ArtDecoPvsEntitySubComponent a) _
  32. derive instance Eq a => Eq (ArtDecoPvsEntitySubComponent a)
  33. instance Show a => Show (ArtDecoPvsEntitySubComponent a) where
  34. show = genericShow
  35. derive instance Functor ArtDecoPvsEntitySubComponent
  36. instance Foldable ArtDecoPvsEntitySubComponent where
  37. foldMap f (ArtDecoPvsEntitySubComponent sc) = f sc
  38. foldl = \x -> foldlDefault x
  39. foldr = \x -> foldrDefault x
  40. instance Traversable ArtDecoPvsEntitySubComponent where
  41. sequence (ArtDecoPvsEntitySubComponent subComponents) = ado
  42. sc <- subComponents
  43. in ArtDecoPvsEntitySubComponent sc
  44. traverse = \x -> traverseDefault x
  45. instance Queryable q => CanBeQueried q ArtDecoPvsEntitySubComponent where
  46. query n = do
  47. content <- queryOne "span[aria-hidden=true]" n
  48. pure $ ArtDecoPvsEntitySubComponent content
  49. derive instance Generic (ArtDecoCenterContent a) _
  50. derive instance Eq a => Eq(ArtDecoCenterContent a)
  51. instance Show a => Show(ArtDecoCenterContent a) where
  52. show = genericShow
  53. derive instance Functor ArtDecoCenterContent
  54. instance Foldable ArtDecoCenterContent where
  55. foldMap f (ArtDecoCenterContent c) = foldMap (foldMap f) c
  56. foldl = \x -> foldlDefault x
  57. foldr = \x -> foldrDefault x
  58. instance Traversable ArtDecoCenterContent where
  59. sequence (ArtDecoCenterContent center) = ado
  60. c <- sequence (map sequence center)
  61. in ArtDecoCenterContent c
  62. traverse = \x -> traverseDefault x
  63. instance Queryable q => CanBeQueried q ArtDecoCenterContent where
  64. query n = do
  65. sc <- subQueryMany ":scope > ul > li" n
  66. pure $ ArtDecoCenterContent sc
  67. derive instance Generic (ArtDecoCenterHeader a) _
  68. derive instance Eq a => Eq(ArtDecoCenterHeader a)
  69. instance Show a => Show(ArtDecoCenterHeader a) where
  70. show = genericShow
  71. derive instance Functor ArtDecoCenterHeader
  72. instance Foldable ArtDecoCenterHeader where
  73. foldMap f (ArtDecoCenterHeader {bold, normal, light}) = f bold <> foldMap f normal <> foldMap (foldMap f) light
  74. foldl = \x -> foldlDefault x
  75. foldr = \x -> foldrDefault x
  76. instance Traversable ArtDecoCenterHeader where
  77. sequence (ArtDecoCenterHeader {bold, normal, light}) = ado
  78. b <- bold
  79. n <- sequence normal
  80. l <- sequence (map sequence light)
  81. in ArtDecoCenterHeader {bold: b, normal: n, light: l}
  82. traverse = \x -> traverseDefault x
  83. instance Queryable q => CanBeQueried q ArtDecoCenterHeader where
  84. query n = do
  85. bold <- queryOne ":scope div.t-bold > span[aria-hidden=true]" n
  86. normal <-
  87. ignoreNotFound $
  88. queryOne ":scope span.t-normal:not(t-black--light) > span[aria-hidden=true]" n
  89. light <-
  90. ignoreNotFound $
  91. queryAll ":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 ∷ Maybe (NonEmptyList 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 ∷ Maybe (NonEmptyList 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) (Maybe (NonEmptyList a))
  163. _pvs_to_header_light = _pvs_to_header <<< prop (Proxy :: Proxy "light")