diff options
| author | LLLL Colonq <llll@colonq> | 2024-01-12 14:54:22 -0500 |
|---|---|---|
| committer | LLLL Colonq <llll@colonq> | 2024-01-12 14:54:32 -0500 |
| commit | 094d3e0e1370f2f8b3619ba6cea8b33ac83dceed (patch) | |
| tree | 01ae4f2706d32ef1433c60d60dcabb1e479be463 /fig-frontend/src/Fig/Frontend | |
| parent | 45980c6910a7fe16ec41b1663b79cebc6e33350d (diff) | |
Update frontend
Diffstat (limited to 'fig-frontend/src/Fig/Frontend')
| -rw-r--r-- | fig-frontend/src/Fig/Frontend/State.hs | 41 | ||||
| -rw-r--r-- | fig-frontend/src/Fig/Frontend/Utils.hs | 2 |
2 files changed, 43 insertions, 0 deletions
diff --git a/fig-frontend/src/Fig/Frontend/State.hs b/fig-frontend/src/Fig/Frontend/State.hs new file mode 100644 index 0000000..6053105 --- /dev/null +++ b/fig-frontend/src/Fig/Frontend/State.hs @@ -0,0 +1,41 @@ +{-# Language TemplateHaskell #-} + +module Fig.Frontend.State where + +import Control.Lens.TH (makeLensesFor) +import Control.Lens ((<>=)) +import Control.Monad.State (runStateT) + +import Fig.Prelude + +import qualified Data.IORef as IORef + +newtype State = State + { buffer :: Text + } +makeLensesFor [("buffer", "buffer")] ''State + +defaultState :: State +defaultState = State + { buffer = "" + } + +type StateRef = IORef.IORef State + +stateRef :: IO StateRef +stateRef = IORef.newIORef defaultState + +withState :: + MonadIO m' => + StateRef -> + (forall m. (MonadIO m, MonadState State m) => m a) -> + m' a +withState ref f = do + s <- liftIO $ IORef.readIORef ref + (res, s') <- liftIO $ runStateT f s + liftIO $ IORef.writeIORef ref s' + pure res + +sayHi :: StateRef -> IO () +sayHi ref = withState ref do + buffer <>= "hi" diff --git a/fig-frontend/src/Fig/Frontend/Utils.hs b/fig-frontend/src/Fig/Frontend/Utils.hs index 1ba1d5f..20234e7 100644 --- a/fig-frontend/src/Fig/Frontend/Utils.hs +++ b/fig-frontend/src/Fig/Frontend/Utils.hs @@ -22,6 +22,7 @@ data Config = Config { port :: Int , assetPath :: FilePath , clientId :: Text + , authToken :: Text } deriving (Show, Eq, Ord) configCodec :: Toml.TomlCodec Config @@ -29,6 +30,7 @@ configCodec = do port <- Toml.int "port" Toml..= (\a -> a.port) assetPath <- Toml.string "asset_path" Toml..= (\a -> a.assetPath) clientId <- Toml.text "client_id" Toml..= (\a -> a.clientId) + authToken <- Toml.text "auth_token" Toml..= (\a -> a.authToken) pure $ Config{..} loadConfig :: FilePath -> IO Config |
