|
|
@@ -8,7 +8,7 @@ import Data.Either (Either(..), hush, note)
|
|
|
import Data.Generic.Rep (class Generic)
|
|
|
import Data.List (List)
|
|
|
import Data.List.Types (NonEmptyList)
|
|
|
-import Data.Maybe (Maybe)
|
|
|
+import Data.Maybe (Maybe(..))
|
|
|
import Data.Show.Generic (genericShow)
|
|
|
import Effect (Effect)
|
|
|
import Effect.Class.Console (log, logShow)
|
|
|
@@ -22,7 +22,8 @@ import Web.DOM.Node (nodeName)
|
|
|
|
|
|
|
|
|
data ArtDecoCenterHeaderAlt a = ArtDecoCenterHeaderAlt {
|
|
|
- bold :: a
|
|
|
+ bold :: a,
|
|
|
+ normal :: Maybe a
|
|
|
}
|
|
|
|
|
|
derive instance Generic (ArtDecoCenterHeaderAlt a) _
|
|
|
@@ -30,8 +31,8 @@ derive instance Eq a => Eq (ArtDecoCenterHeaderAlt a)
|
|
|
instance Show a => Show (ArtDecoCenterHeaderAlt a) where
|
|
|
show = genericShow
|
|
|
instance Functor ArtDecoCenterHeaderAlt where
|
|
|
- map f (ArtDecoCenterHeaderAlt {bold}) =
|
|
|
- ArtDecoCenterHeaderAlt ({bold: f bold})
|
|
|
+ map f (ArtDecoCenterHeaderAlt {bold, normal}) =
|
|
|
+ ArtDecoCenterHeaderAlt ({bold: f bold, normal: map f normal})
|
|
|
|
|
|
data ArtDecoCardAltElement a = ArtDecoCardAltElement {
|
|
|
pvs_entity :: ArtDecoCenterHeaderAlt a
|
|
|
@@ -41,8 +42,8 @@ derive instance Generic (ArtDecoCardAltElement a) _
|
|
|
derive instance Eq a => Eq (ArtDecoCardAltElement a)
|
|
|
instance Show (ArtDecoCardAltElement Node) where
|
|
|
show (ArtDecoCardAltElement {
|
|
|
- pvs_entity: ArtDecoCenterHeaderAlt {bold}
|
|
|
- }) = "ArtDecoCardAltElement(Node " <> "ArtDecoCenterHeaderAlt(Node " <> nodeName bold <> ")" <> ")"
|
|
|
+ pvs_entity: ArtDecoCenterHeaderAlt {bold, normal}
|
|
|
+ }) = "ArtDecoCardAltElement(Node " <> "ArtDecoCenterHeaderAlt(Node " <> nodeName bold <> "," <> show (map nodeName normal) <> ")" <> ")"
|
|
|
else instance Show a => Show (ArtDecoCardAltElement a) where
|
|
|
show = genericShow
|
|
|
instance Functor ArtDecoCardAltElement where
|
|
|
@@ -50,19 +51,28 @@ instance Functor ArtDecoCardAltElement where
|
|
|
ArtDecoCardAltElement ({pvs_entity: map f pvs_entity})
|
|
|
|
|
|
queryArtDecoCardAlt :: Node → Effect (Either QueryError (ArtDecoCardAltElement Node))
|
|
|
-queryArtDecoCardAlt n = do
|
|
|
- eitherResult <- runExceptT do
|
|
|
- pvs <- ExceptT $ runOne ":scope div.pvs-entity--padded" n
|
|
|
- bold <- ExceptT $ runOne ":scope div.t-bold > span[aria-hidden=true]" pvs
|
|
|
- pure $ ArtDecoCardAltElement { pvs_entity: ArtDecoCenterHeaderAlt {bold} }
|
|
|
- pure eitherResult
|
|
|
+queryArtDecoCardAlt n = runExceptT do
|
|
|
+ pvs <- runOne ":scope div.pvs-entity--padded" n
|
|
|
|
|
|
-runOne ∷ String → Node → Effect (Either QueryError Node)
|
|
|
-runOne selector node = do
|
|
|
+ bold <- runOne ":scope div.t-bold > span[aria-hidden=true]" pvs
|
|
|
+ normal <-
|
|
|
+ mapExceptT (map ignoreNotFound) $
|
|
|
+ runOne ":scope span.t-normal:not(t-black--light) > span[aria-hidden=true]" n
|
|
|
+
|
|
|
+ pure $ ArtDecoCardAltElement { pvs_entity: ArtDecoCenterHeaderAlt {bold, normal: normal} }
|
|
|
+
|
|
|
+ where
|
|
|
+ ignoreNotFound = case _ of
|
|
|
+ (Left (QNodeNotFoundError _ )) -> Right Nothing
|
|
|
+ (Left q) -> Left q
|
|
|
+ (Right n') -> Right (Just n')
|
|
|
+
|
|
|
+runOne ∷ String → Node → ExceptT QueryError Effect Node
|
|
|
+runOne selector node = ExceptT $ do
|
|
|
maybeNode <- queryOne selector node
|
|
|
pure $ note (QNodeNotFoundError selector) maybeNode
|
|
|
|
|
|
-runAll ∷ String → Node → Effect (Either QueryError (NonEmptyList Node))
|
|
|
-runAll selector node = do
|
|
|
+runAll ∷ String → Node → ExceptT QueryError Effect (NonEmptyList Node)
|
|
|
+runAll selector node = ExceptT $ do
|
|
|
maybeNodes <- queryAll selector node
|
|
|
pure $ note (QNodeListNotFoundError selector) maybeNodes
|