Skip to content

Commit 82bbc97

Browse files
committed
;feat:ui: implement live updating for the transaction page
1 parent 9d0684d commit 82bbc97

File tree

2 files changed

+17
-12
lines changed

2 files changed

+17
-12
lines changed

hledger-ui/Hledger/UI/UIScreens.hs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ screenUpdate opts d j = \case
6363
BS sst -> BS $ bsUpdate opts d j sst
6464
IS sst -> IS $ isUpdate opts d j sst
6565
RS sst -> RS $ rsUpdate opts d j sst
66-
TS sst -> TS $ tsUpdate sst
66+
TS sst -> TS $ tsUpdate opts d j sst
6767
ES sst -> ES $ esUpdate sst
6868

6969
-- | Construct an error screen.
@@ -360,12 +360,17 @@ tsNew acct nts nt =
360360
,_tssTransaction = nt
361361
}
362362

363-
-- | Update a transaction screen.
364-
-- This currently does nothing because the initialisation in rsHandle is not so easy to extract.
365-
-- To see the updated transaction, one must exit and re-enter the transaction screen.
366-
-- See also tsHandle.
367-
tsUpdate :: TransactionScreenState -> TransactionScreenState
368-
tsUpdate tss =
363+
-- | Update a transaction screen by refreshing the current transaction from the journal.
364+
-- This preserves the current transaction selection while updating its data.
365+
-- XXX Caveat, this works by showing the transaction at the same index in the processed ledger,
366+
-- if transactions have been inserted or removed before the one shown this will just show
367+
-- whatever transaction landed at the same index in the new data set.
368+
tsUpdate :: UIOpts -> Day -> Journal -> TransactionScreenState -> TransactionScreenState
369+
tsUpdate _ _ j tss@TSS{_tssTransaction=(currentIdx,currentTxn)} =
369370
dbgui "tsUpdate" $
370-
tss `seq` tss -- Force evaluation to prevent accumulation
371-
371+
let
372+
-- Find the updated version of the current transaction in the journal
373+
updatedTxn = case find (\t -> tindex t == tindex currentTxn) (jtxns j) of
374+
Just t -> t
375+
Nothing -> currentTxn -- fallback to current if not found
376+
in tss { _tssTransaction = (currentIdx, updatedTxn) }

hledger-ui/Hledger/UI/UIState.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -366,8 +366,8 @@ resetScreens d ui@UIState{astartupopts=origopts, ajournal=j, aScreen=s,aPrevScre
366366
-- (using the ui state's current options), preserving the screen navigation history.
367367
-- Note, does not save the reporting date.
368368
--
369-
-- XXX Currently this does not properly regenerate the transaction screen or error screen,
370-
-- which depend on state from their parent(s); those screens' handlers must do additional work, which is fragile.
369+
-- XXX Currently this does not properly regenerate or error screen,
370+
-- which depends on state from their parent(s); that screens' handler must do additional work, which is fragile.
371371
regenerateScreens :: Journal -> Day -> UIState -> UIState
372372
regenerateScreens j d ui@UIState{aScreen=s} =
373373
let !ui' = ui{ajournal=j, aScreen=s'}
@@ -378,6 +378,6 @@ regenerateScreens j d ui@UIState{aScreen=s} =
378378
BS ass -> BS $! bsUpdate (aopts ui') d j ass
379379
IS ass -> IS $! isUpdate (aopts ui') d j ass
380380
RS rss -> RS $! rsUpdate (aopts ui') d j rss
381-
TS tss -> TS $! tsUpdate tss
381+
TS tss -> TS $! tsUpdate (aopts ui') d j tss
382382
ES _ -> s
383383
in ui'

0 commit comments

Comments
 (0)