blob: 1fa434c1c59a94e5bd7b545b725b15f7ab27280e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
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
|