ArtDecoCard.purs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. module LinkedIn.UI.Components.ArtDecoCard 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', lens', toListOf, view)
  6. import Data.Lens.Record (prop)
  7. import Data.List (List)
  8. import Data.List as L
  9. import Data.List.Types (NonEmptyList)
  10. import Data.Maybe (Maybe)
  11. import Data.Show.Generic (genericShow)
  12. import Data.Traversable (class Traversable, sequence, traverseDefault)
  13. import Data.Tuple (Tuple(..))
  14. import LinkedIn.QueryRunner (QueryRunner', subQueryOne)
  15. import LinkedIn.Queryable (class Queryable)
  16. import LinkedIn.UI.Components.ArtDeco (ArtDecoPvsEntity, _pvs_to_header_bold, _pvs_to_header_light, _pvs_to_header_normal, _pvs_to_subcomponents, queryArtDecoPvsEntity)
  17. import Type.Proxy (Proxy(..))
  18. import Web.DOM (Node)
  19. data ArtDecoCardElement a = ArtDecoCardElement {
  20. pvs_entity :: ArtDecoPvsEntity a
  21. }
  22. derive instance Generic (ArtDecoCardElement a) _
  23. derive instance Eq a => Eq (ArtDecoCardElement a)
  24. instance Show a => Show (ArtDecoCardElement a) where
  25. show = genericShow
  26. derive instance Functor ArtDecoCardElement
  27. instance Foldable ArtDecoCardElement where
  28. foldMap f (ArtDecoCardElement {pvs_entity}) = foldMap f pvs_entity
  29. foldl = \x -> foldlDefault x
  30. foldr = \x -> foldrDefault x
  31. instance Traversable ArtDecoCardElement where
  32. sequence (ArtDecoCardElement {pvs_entity}) = ado
  33. p <- sequence pvs_entity
  34. in ArtDecoCardElement {pvs_entity: p}
  35. traverse = \x -> traverseDefault x
  36. queryArtDecoCard :: forall q. Queryable q => QueryRunner' q (ArtDecoCardElement Node)
  37. queryArtDecoCard n = do
  38. pvs_entity <- subQueryOne queryArtDecoPvsEntity ":scope div.pvs-entity--padded" n
  39. pure $ ArtDecoCardElement {pvs_entity}
  40. toHeaderBold ∷ ∀ a. ArtDecoCardElement a → a
  41. toHeaderBold = view $ _card_to_pvs_entity <<< _pvs_to_header_bold
  42. toHeaderNormal ∷ ∀ a. ArtDecoCardElement a → Maybe a
  43. toHeaderNormal = view $ _card_to_pvs_entity <<< _pvs_to_header_normal
  44. toHeaderLight ∷ ∀ a. ArtDecoCardElement a → Maybe (NonEmptyList a)
  45. toHeaderLight = view $ _card_to_pvs_entity <<< _pvs_to_header_light
  46. toCenterContent ∷ ∀ a. ArtDecoCardElement a → List a
  47. toCenterContent c = L.catMaybes $ toContent c
  48. where
  49. toContent = toListOf $ _card_to_pvs_entity <<< _pvs_to_subcomponents
  50. _card :: forall a. Lens' (ArtDecoCardElement a) { pvs_entity ∷ ArtDecoPvsEntity a }
  51. _card = lens' \(ArtDecoCardElement c) -> Tuple c \c' -> ArtDecoCardElement c'
  52. _card_to_pvs_entity :: forall a. Lens' (ArtDecoCardElement a) (ArtDecoPvsEntity a)
  53. _card_to_pvs_entity = _card <<< prop (Proxy :: Proxy "pvs_entity")