blob: e728e667d83f653bb6cbdd961e5589720dd23184 (
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
|
module Main.Gizmo where
import Prelude
import Config as Config
import Data.Foldable (for_)
import Data.String (Pattern(..), split)
import Data.String as String
import Effect (Effect)
import Effect.Aff (launchAff_)
import Effect.Class (class MonadEffect, liftEffect)
import Effect.Console (log)
import Fetch (fetch)
import UI (addOption, onInput, startBufferRefresh)
import Utils (byId, getSelectValue, setIFrameSrc)
loadBuffer :: forall m. MonadEffect m => String -> m Unit
loadBuffer nm = do
contents <- byId "lcolonq-gizmo-contents"
setIFrameSrc (Config.apiServer <> "/gizmo?buf=" <> nm) contents
main :: Effect Unit
main = launchAff_ do
liftEffect $ log "hello from gizmo"
select <- byId "lcolonq-gizmo-select"
onInput select \d -> loadBuffer d
{ text: text } <- fetch (Config.apiServer <> "/gizmo/list") {}
glist <- text
for_ (split (Pattern "\n") glist) \buf -> do
when (not $ String.null buf) $ addOption buf select
initial <- getSelectValue =<< byId "lcolonq-gizmo-select"
loadBuffer initial
contents <- byId "lcolonq-gizmo-contents"
startBufferRefresh contents
|