diff options
Diffstat (limited to 'src/Main/Greencircle.purs')
| -rw-r--r-- | src/Main/Greencircle.purs | 45 |
1 files changed, 45 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 |
