-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathMain.hs
43 lines (39 loc) · 1.29 KB
/
Main.hs
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
{-# LANGUAGE RecordWildCards, OverloadedStrings #-}
module Main where
import Miso
import Miso.String(MisoString)
import Editor (runAction, EditorAction (..), Editor (..), initialEditor)
import qualified ImportExport
import View.Editor (viewEditor)
foreign import javascript unsafe "$r = document.location.search.slice(1);"
urlparameter :: IO MisoString
main :: IO ()
main = do
url <- (\x -> if x == "" then "index.holbert" else x) <$> urlparameter
startApp App {model = initialEditor url, ..}
where
initialAction = Import
update = updateModel
view = viewEditor
events = defaultEvents
subs = []
mountPoint = Nothing
logLevel = Off
updateModel :: EditorAction -> Editor -> Effect EditorAction Editor
updateModel Import = \m -> act m #> m
where
act m = do
x <- ImportExport.import_ (inputText m)
pure $ case x of
Left e -> DisplayError e
Right x -> LoadDocument x
updateModel Upload = \m -> act m #> m
where
act m = do
x <- ImportExport.openFile
pure $ case x of
Left e -> DisplayError e
Right x -> LoadDocument x
updateModel Download = \m -> act m #> m
where act m = ImportExport.export "file.holbert" (document m) >> pure Noop
updateModel act = noEff . runAction act