Open a finished Rule from its Profile card, and drop it from the browser on Log out.

This commit is contained in:
adilallo committed 2026-11-22 17:47:46 -07:00
1 parent db1599123b
commit 942c7cc9de
17 files changed
+280 -14

No files matched your search

@@ -0,0 +1,24 @@
import { clearPendingKeepRuleLogin } from "../../../../lib/create/pendingKeepRuleLogin";
import { clearLastPublishedRule } from "../../../../lib/create/lastPublishedRule";
import { clearCreateFlowPersistedDrafts } from "./clearCreateFlowPersistedDrafts";
const LEGACY_LIVE_KEY = "create-flow-state";
const LEGACY_DRAFT_KEY = "create-flow-draft";
/**
* Drop every Rule the browser is holding: the anonymous draft, last finished
* Rule, keep-this-rule prompt, and leftover pre-anonymous keys. Does not
* `DELETE /api/drafts/me`. Call after Log out and Delete account.
*/
export function clearBrowserRuleData(): void {
clearCreateFlowPersistedDrafts();
clearLastPublishedRule();
clearPendingKeepRuleLogin();
if (typeof window === "undefined") return;
try {
window.localStorage.removeItem(LEGACY_LIVE_KEY);
window.localStorage.removeItem(LEGACY_DRAFT_KEY);
} catch {
// ignore
}
}
+7
View File
@@ -23,7 +23,9 @@ import {
downloadStoredRuleAsPdf,
} from "../../../lib/create/ruleExport";
import {
clearLastPublishedRule,
finishedAtIso,
readLastPublishedRule,
writeLastPublishedRule,
type StoredLastPublishedRule,
} from "../../../lib/create/lastPublishedRule";
@@ -36,6 +38,7 @@ import {
} from "../create/utils/flowSteps";
import type { CreateFlowStep } from "../create/types";
import { clearAnonymousCreateFlowStorage } from "../create/utils/anonymousDraftStorage";
import { clearBrowserRuleData } from "../create/utils/clearBrowserRuleData";
import { clearCoreValueDetailsLocalStorage } from "../create/utils/coreValueDetailsLocalStorage";
import { prepareFreshCreateFlowEntrySync } from "../create/utils/prepareFreshCreateFlowEntry";
import { createFlowStepPath } from "../create/utils/createFlowPaths";
@@ -203,6 +206,7 @@ export default function ProfilePageClient() {
const handleSignOut = useCallback(async () => {
setActionError(null);
await logout();
clearBrowserRuleData();
setUser(null);
setRules([]);
setDraft(null);
@@ -228,6 +232,8 @@ export default function ProfilePageClient() {
const res = await deletePublishedRule(id);
setRuleDeleteBusy(false);
if (res.ok === true) {
const stored = readLastPublishedRule();
if (stored?.id === id) clearLastPublishedRule();
setRuleDeleteTargetId(null);
void load();
return;
@@ -392,6 +398,7 @@ export default function ProfilePageClient() {
const res = await deleteAccount();
setAccountDeleteBusy(false);
if (res.ok) {
clearBrowserRuleData();
setAccountDeleteOpen(false);
setUser(null);
setRules([]);
@@ -14,6 +14,7 @@ import Alert from "../../../components/modals/Alert";
import HeaderLockup from "../../../components/type/HeaderLockup";
import { useTranslation } from "../../../contexts/MessagesContext";
import type { CreateFlowState } from "../../create/types";
import { createCompletedPath } from "../../create/utils/createFlowPaths";
import type {
MyPublishedRule,
ServerDraftForProfile,
@@ -399,6 +400,8 @@ export function ProfilePageView({
description={rule.summary ?? undefined}
expanded
size={ruleCardSize}
href={createCompletedPath({ ruleId: rule.id })}
ariaLabel={rule.title}
hasBottomLinks
bottomStatusLabel={t("finishedBadge")}
bottomLinks={[
@@ -422,7 +425,7 @@ export function ProfilePageView({
rule.title,
)}
backgroundColor="bg-[var(--color-surface-invert-brand-teal)]"
className={ownedRuleCardShellClass}
className={ruleCardShellClass}
/>
))}
</div>
@@ -449,7 +452,8 @@ export function ProfilePageView({
description={rule.summary ?? undefined}
expanded
size={ruleCardSize}
href={`/invite/${encodeURIComponent(rule.id)}`}
href={`/rules/${encodeURIComponent(rule.id)}`}
ariaLabel={rule.title}
communityInitials={communityInitialsFromTitle(
rule.title,
)}