Skip to content

Commit

Permalink
Avoid hiding view by using display
Browse files Browse the repository at this point in the history
  • Loading branch information
axman6 committed Jan 8, 2024
1 parent 1980535 commit e1fc3cf
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
18 changes: 9 additions & 9 deletions up-top/src/Event.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,37 +10,37 @@ import Control.Monad.IO.Class (liftIO)
import qualified Data.HashMap.Strict as H
import qualified Data.Vector as Vec
import Graphics.Vty
import Lens.Micro.Platform hiding (view)
import Lens.Micro.Platform
import Types
import Up.Model.Account
import Up.Model.Category

-- Handling events
handleEvent :: BrickEvent Name UEvent -> EventM Name State ()
handleEvent (VtyEvent e) = do
use (screen . focus . view) >>= \case
use (screen . focus . display) >>= \case
MainView lz ViewportMode ->
case e of
EvKey KEsc [] -> pure ()
EvKey (KChar 'k') [] -> modify (setView (MainView (focusLeft lz) NormalMode))
EvKey (KChar 'j') [] -> modify (setView (MainView (focusRight lz) NormalMode))
EvKey KUp [] -> modify (setView (MainView (focusLeft lz) NormalMode))
EvKey KDown [] -> modify (setView (MainView (focusRight lz) NormalMode))
_ -> modify (setView (MainView lz NormalMode))
EvKey (KChar 'k') [] -> modify (setDisplay (MainView (focusLeft lz) NormalMode))
EvKey (KChar 'j') [] -> modify (setDisplay (MainView (focusRight lz) NormalMode))
EvKey KUp [] -> modify (setDisplay (MainView (focusLeft lz) NormalMode))
EvKey KDown [] -> modify (setDisplay (MainView (focusRight lz) NormalMode))
_ -> modify (setDisplay (MainView lz NormalMode))
MainView lz NormalMode ->
case e of
EvKey KEsc [] -> halt
EvKey (KChar 'q') [] -> halt
EvKey (KChar '?') [] -> modify setHelpScreen
EvKey (KChar 'w') [MCtrl] -> modify (setView (MainView lz ViewportMode))
EvKey (KChar 'w') [MCtrl] -> modify (setDisplay (MainView lz ViewportMode))
EvKey KEnter [] -> case lz ^. focus of
FocusAccounts -> do
aid <- use (accounts . to L.listSelectedElement) >>= \case
Just (_, a) -> pure (accountId a)
Nothing -> error "" -- TODO: No more monad fail
ch <- use reqChan
liftIO $ writeBChan ch $ FetchTransaction aid
modify (setView (MainView (focusRight lz) NormalMode))
modify (setDisplay (MainView (focusRight lz) NormalMode))
_ -> pure ()
ev -> case lz ^. focus of
FocusTransactions -> do
Expand Down
8 changes: 4 additions & 4 deletions up-top/src/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import Brick.BChan
import qualified Brick.Widgets.List as L
import Data.HashMap.Strict
import qualified Data.Text as T
import Lens.Micro.Platform hiding (view)
import Lens.Micro.Platform
import Servant.Client (ClientEnv)
import Up.Model.Account
import Up.Model.Category
Expand Down Expand Up @@ -96,7 +96,7 @@ data Tag
-- A Screen is a tag and a view
data Screen = Screen
{ _tag :: Tag,
_view :: View
_display :: View
}

makeLenses ''Screen
Expand Down Expand Up @@ -128,5 +128,5 @@ setMainScreen = setScreen MainTag
setHelpScreen :: State -> State
setHelpScreen = setScreen HelpTag

setView :: View -> State -> State
setView v st = st & (screen . focus . view) .~ v
setDisplay :: View -> State -> State
setDisplay v st = st & (screen . focus . display) .~ v
4 changes: 2 additions & 2 deletions up-top/src/UI.hs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
module UI where

import Brick.Types
import Lens.Micro.Platform hiding (view)
import Lens.Micro.Platform

import Types
import UI.HelpView
import UI.MainView

drawUI :: State -> [Widget Name]
drawUI st =
case st ^. (screen . focus . view) of
case st ^. (screen . focus . display) of
MainView lz _m -> drawMain st lz
HelpView -> drawHelp st

0 comments on commit e1fc3cf

Please sign in to comment.