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,
)}
+2
View File
@@ -1,6 +1,7 @@
import { NextResponse } from "next/server";
import { isDatabaseConfigured } from "../../../../lib/server/env";
import { dbUnavailable } from "../../../../lib/server/responses";
import { clearGuestRuleClaimCookie } from "../../../../lib/server/guestRuleClaim";
import { destroySessionFromRequest } from "../../../../lib/server/session";
import { apiRoute } from "../../../../lib/server/apiRoute";
@@ -10,5 +11,6 @@ export const POST = apiRoute("auth.logout", async () => {
}
await destroySessionFromRequest();
await clearGuestRuleClaimCookie();
return NextResponse.json({ ok: true });
});
+2
View File
@@ -6,6 +6,7 @@ import {
internalError,
unauthorized,
} from "../../../../lib/server/responses";
import { clearGuestRuleClaimCookie } from "../../../../lib/server/guestRuleClaim";
import {
clearSessionCookie,
getSessionUser,
@@ -37,6 +38,7 @@ export const DELETE = apiRoute("user.me.delete", async () => {
}
await clearSessionCookie();
await clearGuestRuleClaimCookie();
return NextResponse.json({ ok: true });
});
+7 -2
View File
@@ -36,6 +36,7 @@ const RuleContainer = memo<RuleProps>(
className = "",
onClick,
href,
ariaLabel: ariaLabelProp,
expanded = false,
size: sizeProp,
categories,
@@ -67,7 +68,11 @@ const RuleContainer = memo<RuleProps>(
const size = sizeProp ?? "L";
const isInteractive = interactive ?? !hasBottomLinks;
const t = useTranslation("ruleCard");
const cardAriaLabel = t("ariaLabel")?.replace("{title}", title) || title;
const trimmedAriaLabel = ariaLabelProp?.trim() ?? "";
const cardAriaLabel =
trimmedAriaLabel.length > 0
? trimmedAriaLabel
: t("ariaLabel")?.replace("{title}", title) || title;
const recommendedLabel = t("recommendedLabel");
const handleClick = () => {
@@ -111,7 +116,7 @@ const RuleContainer = memo<RuleProps>(
icon={icon}
backgroundColor={backgroundColor}
className={className}
href={isInteractive && !hasBottomLinks ? href : undefined}
href={href}
onClick={isInteractive && !hasBottomLinks ? handleClick : undefined}
onKeyDown={
isInteractive && !hasBottomLinks && !href ? handleKeyDown : undefined
+8 -1
View File
@@ -56,9 +56,16 @@ export interface RuleProps {
onClick?: () => void;
/**
* When set, the card is a real link (focusable, Enter, open in a new tab)
* instead of a click-only `role="button"` surface.
* instead of a click-only `role="button"` surface. Combined with
* {@link hasBottomLinks}, the link is a stretched overlay so Invite /
* Duplicate / Delete stay separate controls.
*/
href?: string;
/**
* Accessible name for the card or its overlay link. Defaults to the
* `ruleCard` “Learn more about {title}…” string.
*/
ariaLabel?: string;
expanded?: boolean;
size?: RuleSizeValue;
categories?: Category[];
+25 -1
View File
@@ -298,6 +298,7 @@ export function RuleView({
<NavigationLink
key={link.id}
{...shared}
className={`${shared.className} pointer-events-auto relative z-10`}
href={link.href}
onClick={(e) => e.stopPropagation()}
/>
@@ -307,6 +308,7 @@ export function RuleView({
<NavigationLink
key={link.id}
{...shared}
className={`${shared.className} pointer-events-auto relative z-10`}
onClick={(e) => {
e.stopPropagation();
link.onClick?.();
@@ -319,7 +321,8 @@ export function RuleView({
const surfaceStyle = surfaceColor
? { backgroundColor: surfaceColor }
: undefined;
const isLinkCard = Boolean(href) && interactiveCard;
const isLinkCard = Boolean(href) && interactiveCard && !hasBottomLinks;
const overlayHref = hasBottomLinks && href ? href : undefined;
const hasCategories = Boolean(categories && categories.length > 0);
const expandedDescriptionFrameClass = [
@@ -610,6 +613,27 @@ export function RuleView({
);
}
if (overlayHref) {
return (
<div
className={`${cardClassName} cursor-pointer`}
style={surfaceStyle}
role="article"
>
<NextLink
href={overlayHref}
className="absolute inset-0 z-0 rounded-[inherit]"
aria-label={ariaLabel}
/>
<div
className={`relative z-[1] flex w-full flex-col items-start pointer-events-none ${cardGap}`}
>
{cardBody}
</div>
</div>
);
}
return (
<div
className={cardClassName}