diff options
| author | Roman Smrž <roman.smrz@seznam.cz> | 2026-02-12 12:06:36 +0100 |
|---|---|---|
| committer | Roman Smrž <roman.smrz@seznam.cz> | 2026-02-12 12:35:54 +0100 |
| commit | 5eb2df6c41e9329eb2fb89e0e9bbf53911fd2e66 (patch) | |
| tree | 7c8d8132a189d5b8194693da67218df622184776 | |
| parent | 257ce67d3dd398055c0710ec712618104621c8a0 (diff) | |
Use cached IndexDB storage
| -rw-r--r-- | src/Main.hs | 47 |
1 files changed, 25 insertions, 22 deletions
diff --git a/src/Main.hs b/src/Main.hs index 66c8126..0d5549a 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -40,6 +40,8 @@ import Text.Blaze.Html5.Attributes qualified as A import Text.Blaze.Html.Renderer.String import JavaScript qualified as JS +import Storage.Cache +import Storage.IndexedDB import WebSocket (startClient, receiveMessage) main :: IO () @@ -60,11 +62,30 @@ data CurrentConversation initGlobalState :: IO GlobalState initGlobalState = do - globalStorage <- memoryStorage + --globalStorage <- memoryStorage + globalStorage <- cacheStorage =<< indexedDBStorage "erebos" (either (fail . showErebosError) return =<<) $ runExceptT $ flip runReaderT globalStorage $ do - identity <- createIdentity Nothing Nothing - globalHead <- storeHead globalStorage $ LocalState - { lsPrev = Nothing, lsIdentity = idExtData identity, lsShared = [], lsOther = [] } + globalHead <- loadHeads globalStorage >>= \case + (h : _) -> do + return h + [] -> do + let devName = T.pack "WebApp" + owner <- createIdentity Nothing Nothing + identity <- createIdentity (Just devName) (Just owner) + + shared <- mstore SharedState + { ssPrev = [] + , ssType = Just $ sharedTypeID @(Maybe ComposedIdentity) Proxy + , ssValue = [ storedRef $ idExtData owner ] + } + + storeHead globalStorage $ LocalState + { lsPrev = Nothing + , lsIdentity = idExtData identity + , lsShared = [ shared ] + , lsOther = [] + } + peerListVar <- liftIO $ newMVar [] currentConversationVar <- liftIO $ newMVar NoCurrentConversation conversationsVar <- liftIO $ newMVar [] @@ -124,24 +145,6 @@ setup = do watchIdentityUpdates gs watchConversations gs - let devName = T.pack "WebApp" - (either (fail . showErebosError) return =<<) $ runExceptT $ flip runReaderT globalHead $ do - owner <- createIdentity Nothing Nothing - identity <- createIdentity (Just devName) (Just owner) - - shared <- mstore SharedState - { ssPrev = [] - , ssType = Just $ sharedTypeID @(Maybe ComposedIdentity) Proxy - , ssValue = [ storedRef $ idExtData owner ] - } - updateLocalState_ $ \_ -> do - mstore $ LocalState - { lsPrev = Nothing - , lsIdentity = idExtData identity - , lsShared = [ shared ] - , lsOther = [] - } - setNameInput <- JS.getElementById "name_set_input" setNameForm <- JS.getElementById "name_set_form" JS.addEventListener setNameForm "submit" $ \_ -> do |