forked from liamoc/holbert
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.hs
30 lines (28 loc) · 924 Bytes
/
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
{-# LANGUAGE RecordWildCards, OverloadedStrings #-}
module Main where
import Miso
import Editor (runAction, EditorAction (..), Editor (..), initialEditor)
import qualified ImportExport
import View.Editor (viewEditor)
main :: IO ()
main = startApp App {..}
where
initialAction = Import
model = initialEditor
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 Download = \m -> act m #> m
where act m = ImportExport.export "file.holbert" (document m) >> pure Noop
updateModel act = noEff . runAction act