diff --git a/frontend/src/routes/+page.svelte b/frontend/src/routes/+page.svelte index 7fb66eb..cc179e3 100644 --- a/frontend/src/routes/+page.svelte +++ b/frontend/src/routes/+page.svelte @@ -124,8 +124,11 @@ seenIds = new Set(); dismissed = new Set(); history = []; + serverHistory = []; persistSession(); P.saveJSON(BRIEF_VIEW_KEY, null); + // Signed in? Also clear the account (cross-device) history on the server. + if (auth.user) delJSON('/api/history').catch(() => {}); showHistory = false; select(selected, true); } diff --git a/goodnews/api.py b/goodnews/api.py index 2f40b91..bcd3dfd 100644 --- a/goodnews/api.py +++ b/goodnews/api.py @@ -563,6 +563,14 @@ def create_app() -> FastAPI: conn.commit() return {"ok": True} + @app.delete("/api/history") + def clear_history(request: Request) -> dict: + with get_conn() as conn: + user = _require_user(conn, request) + conn.execute("DELETE FROM user_history WHERE user_id = ?", (user["id"],)) + conn.commit() + return {"ok": True} + @app.delete("/api/history/{article_id}") def remove_history(article_id: int, request: Request) -> dict: with get_conn() as conn: diff --git a/tests/test_saved_api.py b/tests/test_saved_api.py index 730ee7a..d86bc07 100644 --- a/tests/test_saved_api.py +++ b/tests/test_saved_api.py @@ -70,3 +70,6 @@ def test_history_and_import(client): # granular removal from history tc.delete("/api/history/2") assert {a["id"] for a in tc.get("/api/history").json()["items"]} == {1, 3} + # clear ALL history + assert tc.delete("/api/history").json() == {"ok": True} + assert tc.get("/api/history").json()["items"] == []