fix(settings): clarify last-saved status state

This commit is contained in:
Bu5hm4nn
2026-03-26 13:54:56 +01:00
parent f7c134a709
commit cfa3cfcc08
3 changed files with 21 additions and 7 deletions

View File

@@ -42,6 +42,7 @@ def settings_page(workspace_id: str) -> None:
return RedirectResponse(url="/", status_code=307)
config = workspace_repo.load_portfolio_config(workspace_id)
last_saved_config = config
alert_service = AlertService()
syncing_entry_basis = False
@@ -69,6 +70,9 @@ def settings_page(workspace_id: str) -> None:
return str(int(parsed))
return str(parsed)
def last_saved_status_text(config: PortfolioConfig) -> str:
return save_status_text(config).replace("Saved:", "Last saved:", 1)
def build_preview_config() -> PortfolioConfig:
parsed_loan_amount = as_non_negative_float(loan_amount.value)
if parsed_loan_amount is None:
@@ -251,10 +255,9 @@ def settings_page(workspace_id: str) -> None:
"w-full rounded-2xl border border-slate-200 bg-white shadow-sm dark:border-slate-800 dark:bg-slate-900"
):
ui.label("Save Workspace Settings").classes("text-lg font-semibold text-slate-900 dark:text-slate-100")
status = ui.label(
f"Current: start=${config.gold_value:,.0f}, entry=${config.entry_price:,.2f}/oz, "
f"weight={config.gold_ounces:,.2f} oz, current LTV={config.current_ltv:.1%}"
).classes("text-sm text-slate-500 dark:text-slate-400")
status = ui.label(last_saved_status_text(last_saved_config)).classes(
"text-sm text-slate-500 dark:text-slate-400"
)
ui.button("Save settings", on_click=lambda: save_settings()).props("color=primary")
def apply_entry_basis_mode() -> None:
@@ -292,6 +295,10 @@ def settings_page(workspace_id: str) -> None:
f"Email alerts {'enabled' if alert_status.email_alerts_enabled else 'disabled'} · Warning {alert_status.warning_threshold:.0%} · Critical {alert_status.critical_threshold:.0%}"
)
alert_message.set_text(alert_status.message)
if preview_config.to_dict() == last_saved_config.to_dict():
status.set_text(last_saved_status_text(last_saved_config))
else:
status.set_text(f"Unsaved changes — {last_saved_status_text(last_saved_config)}")
alert_history_column.clear()
if alert_status.history:
for event in alert_status.history[:5]:
@@ -316,6 +323,7 @@ def settings_page(workspace_id: str) -> None:
ui.label("INVALID").classes(_alert_badge_classes("critical"))
email_state_label.set_text("Fix validation errors to preview alert state")
alert_message.set_text(str(exc))
status.set_text(f"Unsaved invalid changes — {last_saved_status_text(last_saved_config)}")
alert_history_column.clear()
def update_entry_basis(*_args: object) -> None:
@@ -389,14 +397,17 @@ def settings_page(workspace_id: str) -> None:
update_entry_basis()
def save_settings() -> None:
nonlocal last_saved_config
try:
new_config = build_preview_config()
workspace_repo.save_portfolio_config(workspace_id, new_config)
last_saved_config = new_config
render_alert_state()
status.set_text(save_status_text(new_config))
status.set_text(last_saved_status_text(last_saved_config))
ui.notify("Settings saved successfully", color="positive")
except ValueError as e:
status.set_text(f"Unsaved invalid changes — {last_saved_status_text(last_saved_config)}")
ui.notify(f"Validation error: {e}", color="negative")
except Exception as e:
status.set_text(f"Save failed — {last_saved_status_text(last_saved_config)}")
ui.notify(f"Failed to save: {e}", color="negative")