Skip to content

Feat/back button nav#63

Merged
SudoMayo merged 2 commits intomainfrom
feat/back-button-nav
May 2, 2026
Merged

Feat/back button nav#63
SudoMayo merged 2 commits intomainfrom
feat/back-button-nav

Conversation

@Codex-Crusader
Copy link
Copy Markdown
Member

  • Navigation history stack — Added _push_nav_if_changed(), _restore_nav_state(), and _on_back_click() to dashboard.py. On every sidebar render, the current
    asset/category/custom-ticker state is compared against the previous run; if it changed, the old state (including whether news and live data were loaded) is pushed onto a
    session-state history stack capped at 20 entries. A _nav_restoring flag prevents the back action from being recorded as a new navigation event.
  • Back button — top-left fixed position — Removed the back button from the sidebar. An invisible is injected via st.markdown immediately before
    the st.button call at the top of the main panel. A CSS :has() sibling selector in styles.py targets the button's wrapper div and fixes it at top: 60px; left: calc(21rem + 1rem),
    placing it just below Streamlit's header bar and to the right of the sidebar. Button inherits all retro broadsheet theme variables (gold text, dark transparent background, serif
    font).
  • on_click callback pattern — The back button uses Streamlit's on_click callback rather than inline body handling. This avoids a StreamlitAPIException that occurs when writing to
    a widget-backed session state key (e.g. _custom_ticker_input) after that widget has already been instantiated in the current run. The callback fires between reruns, before any
    widgets are created.
  • Selectbox keys for state restoration — Added key="_selected_category" and key="_selected_asset" to both sidebar selectboxes so the restore can write to them via session state.
    A guard clears _selected_asset if the restored value is not valid for the current category, preventing a Streamlit value-not-in-options error.
  • Sidebar layout stability — Category and Asset selectboxes were previously hidden entirely when a custom ticker was active. They now always render, with disabled=True applied
    when a custom ticker is confirmed, keeping the sidebar layout stable and showing the user their last tracked selection.
  • Ticker placeholder correction — The sidebar ticker lookup label and placeholder used TSMC as an example, which is not a valid Yahoo Finance symbol and caused 404 errors.
    Corrected to TSM (Taiwan Semiconductor Manufacturing Company)

  Introduces _push_nav_if_changed(), _restore_nav_state(), and
  _on_back_click() to track asset/category navigation and restore
  full page state (including lazy-loaded news and live data).
  Removes back button from sidebar. Injects a CSS anchor span before
  the st.button call and uses a :has() sibling selector in styles.py
  to position the button fixed at top: 60px, left: calc(21rem + 1rem),
  styled with the retro broadsheet theme variables.
@Codex-Crusader Codex-Crusader requested a review from SudoMayo May 1, 2026 07:46
@SudoMayo SudoMayo merged commit 33235b7 into main May 2, 2026
3 checks passed
@Codex-Crusader Codex-Crusader deleted the feat/back-button-nav branch May 3, 2026 06:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants