summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLLLL Colonq <llll@colonq>2024-12-12 05:48:49 -0500
committerLLLL Colonq <llll@colonq>2024-12-12 05:48:49 -0500
commit776265c301e9994613ccaa4606e63c0a48d797e6 (patch)
treefbe2cc88796f0efd1b57608318ad92d38a431a0c /src
parent638bdddeb10b18dd35af5a6de2950aaa3c8a5e44 (diff)
Greencircle site
Diffstat (limited to 'src')
-rw-r--r--src/Main/Greencircle.purs45
-rw-r--r--src/Utils.purs3
2 files changed, 48 insertions, 0 deletions
diff --git a/src/Main/Greencircle.purs b/src/Main/Greencircle.purs
index 17f3e0c..1fa434c 100644
--- a/src/Main/Greencircle.purs
+++ b/src/Main/Greencircle.purs
@@ -2,10 +2,55 @@ module Main.Greencircle where
import Prelude
+import Config as Config
+import Data.Array as Array
+import Data.HTTP.Method (Method(..))
+import Data.Maybe (Maybe(..))
+import Data.String as String
+import Data.String.Pattern as String
+import Data.Traversable (for, for_)
import Effect (Effect)
+import Effect.Aff (launchAff_)
import Effect.Class (liftEffect)
import Effect.Console (log)
+import Fetch (fetch)
+import UI as UI
+import Utils as Utils
+
+adjective :: Int -> String
+adjective x
+ | x == 0 = "sleepy"
+ | x == 1 = "singular"
+ | x == 2 = "double trouble"
+ | x == 3 = "triplicate"
+ | otherwise = "relentless"
+
+updateLive :: Effect Unit
+updateLive = launchAff_ do
+ { text: resp } <- fetch (Config.apiServer <> "/circle") {}
+ res <- resp
+ let names =
+ Array.filter (not <<< String.null)
+ $ String.split (String.Pattern " ")
+ $ String.replaceAll (String.Pattern "\"") (String.Replacement "")
+ $ String.replaceAll (String.Pattern "(") (String.Replacement "")
+ $ String.replaceAll (String.Pattern ")") (String.Replacement "") res
+ adj <- Utils.byId "lcolonq-gc-adjective"
+ Utils.setText adj $ adjective $ Array.length names
+ for_ names \n -> do
+ liftEffect $ log n
+ p <- Utils.byId $ "lcolonq-gc-panel-" <> n
+ Utils.addClass "lcolonq-gc-visible" p
main :: Effect Unit
main = do
liftEffect $ log "hello it is greencircle"
+ panels <- Utils.queryAll ".lcolonq-gc-panel"
+ for_ panels \p -> do
+ pid <- Utils.getId p
+ case String.stripPrefix (String.Pattern "lcolonq-gc-panel-") pid of
+ Nothing -> pure unit
+ Just user -> do
+ Utils.listen p "click" \_ev -> do
+ UI.redirect $ "https://twitch.tv/" <> user
+ updateLive
diff --git a/src/Utils.purs b/src/Utils.purs
index 4755436..8c530ef 100644
--- a/src/Utils.purs
+++ b/src/Utils.purs
@@ -54,6 +54,9 @@ query q = do
Nothing -> liftEffect $ throw $ "could not find element matching query: " <> q
Just x -> pure x
+getId :: forall m. MonadEffect m => DOM.Element -> m String
+getId e = liftEffect $ DOM.El.id e
+
listen :: forall m. MonadEffect m => DOM.Element -> String -> (Ev.Event -> Effect Unit) -> m Unit
listen e ev f = do
l <- liftEffect $ Ev.Tar.eventListener f