Resume the draft from Create rule instead of deleting it.
This commit is contained in:
1 parent
d31045b0e5
commit
a846169960
9 files changed
+119
-71
No files matched your search
@@ -68,6 +68,14 @@ export function useCreateFlowNavigation(
|
||||
|
||||
const validStep = parseCreateFlowScreenFromPathname(pathname ?? null);
|
||||
|
||||
useLayoutEffect(() => {
|
||||
if (!validStep || validStep === "completed" || validStep === "edit-rule") {
|
||||
return;
|
||||
}
|
||||
if (state.currentStep === validStep) return;
|
||||
updateState({ currentStep: validStep });
|
||||
}, [validStep, state.currentStep, updateState]);
|
||||
|
||||
useLayoutEffect(() => {
|
||||
if (!pathname?.includes("/create/review-template/")) return;
|
||||
if (
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
import { createFlowStateHasKeys } from "../../../../lib/create/draftHydrationUtils";
|
||||
import type { CreateFlowStep } from "../types";
|
||||
import { readAnonymousCreateFlowState } from "./anonymousDraftStorage";
|
||||
import { CREATE_ROUTES, createFlowStepPath } from "./createFlowPaths";
|
||||
import { readCoreValueDetailsFromLocalStorage } from "./coreValueDetailsLocalStorage";
|
||||
import { isValidStep } from "./flowSteps";
|
||||
|
||||
const NON_RESUME_STEPS = new Set<CreateFlowStep>(["completed", "edit-rule"]);
|
||||
|
||||
export function hasBrowserCreateFlowDraft(): boolean {
|
||||
if (createFlowStateHasKeys(readAnonymousCreateFlowState())) return true;
|
||||
return Object.keys(readCoreValueDetailsFromLocalStorage()).length > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Path for header / Home / Profile **Create rule**. Never clears the browser
|
||||
* draft or `DELETE`s `/api/drafts/me` — resume where the draft was left.
|
||||
*/
|
||||
export function createRuleEntryPath(): string {
|
||||
const local = readAnonymousCreateFlowState();
|
||||
const step = local.currentStep;
|
||||
if (isValidStep(step) && !NON_RESUME_STEPS.has(step)) {
|
||||
return createFlowStepPath(step);
|
||||
}
|
||||
return CREATE_ROUTES.createFirstStep;
|
||||
}
|
||||
@@ -40,7 +40,7 @@ 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 { createRuleEntryPath } from "../create/utils/createRuleEntry";
|
||||
import { createFlowStepPath } from "../create/utils/createFlowPaths";
|
||||
import { useMediaQuery } from "../../hooks/useMediaQuery";
|
||||
import {
|
||||
@@ -310,8 +310,7 @@ export default function ProfilePageClient() {
|
||||
}, [draft, router]);
|
||||
|
||||
const handleStartNewCustomRule = useCallback(() => {
|
||||
prepareFreshCreateFlowEntrySync({ signedIn: true });
|
||||
router.push("/create/informational");
|
||||
router.push(createRuleEntryPath());
|
||||
}, [router]);
|
||||
|
||||
const handleRequestDeleteDraft = useCallback(() => {
|
||||
|
||||
@@ -15,7 +15,7 @@ import AvatarContainer from "../../asset/AvatarContainer";
|
||||
import Avatar from "../../asset/Avatar";
|
||||
import { getAssetPath, ASSETS } from "../../../../lib/assetUtils";
|
||||
import { PRODUCTION_SITE_ORIGIN, websiteJsonLd } from "../../../../lib/siteMetadata";
|
||||
import { prepareFreshCreateFlowEntrySync } from "../../../(app)/create/utils/prepareFreshCreateFlowEntry";
|
||||
import { createRuleEntryPath } from "../../../(app)/create/utils/createRuleEntry";
|
||||
import { TopView } from "./Top.view";
|
||||
import type { TopProps } from "./Top.types";
|
||||
|
||||
@@ -59,16 +59,12 @@ const TopContainer = memo<TopProps>(
|
||||
|
||||
/**
|
||||
* `Top` is hidden on `/create` routes by ConditionalNavigationClient, so
|
||||
* this button is always clicked from outside the wizard. Clears anonymous
|
||||
* `localStorage` synchronously and, when backend sync is on, fires the
|
||||
* server `DELETE /api/drafts/me` in the background. `SignedInDraftHydration`
|
||||
* reads the `create:fresh-entry-pending` sentinel and waits before fetching
|
||||
* (see {@link prepareFreshCreateFlowEntrySync}).
|
||||
* this button is always clicked from outside the wizard. Resume the draft
|
||||
* in the browser instead of wiping it.
|
||||
*/
|
||||
const handleCreateRuleClick = useCallback(() => {
|
||||
prepareFreshCreateFlowEntrySync({ signedIn: loggedIn });
|
||||
router.push("/create/informational");
|
||||
}, [loggedIn, router]);
|
||||
router.push(createRuleEntryPath());
|
||||
}, [router]);
|
||||
|
||||
const schemaData = websiteJsonLd(siteOrigin);
|
||||
|
||||
|
||||
@@ -4,11 +4,10 @@
|
||||
* Figma: "Section / Hero Banner" (18477:15473)
|
||||
*/
|
||||
|
||||
import { memo, useCallback, useEffect, useMemo, useState } from "react";
|
||||
import { memo, useCallback, useMemo } from "react";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useMessages, useTranslation } from "../../../contexts/MessagesContext";
|
||||
import { fetchAuthSession } from "../../../../lib/create/api";
|
||||
import { prepareFreshCreateFlowEntrySync } from "../../../(app)/create/utils/prepareFreshCreateFlowEntry";
|
||||
import { createRuleEntryPath } from "../../../(app)/create/utils/createRuleEntry";
|
||||
import type { Category } from "../../cards/Rule";
|
||||
import type { ChipOption } from "../../controls/MultiSelect/MultiSelect.types";
|
||||
import HeroBannerView from "./HeroBanner.view";
|
||||
@@ -28,26 +27,10 @@ const HeroBannerContainer = memo<HeroBannerProps>(
|
||||
const messages = useMessages();
|
||||
const tHome = useTranslation("pages.home.heroBanner");
|
||||
const tHero = useTranslation("heroBanner");
|
||||
const [signedIn, setSignedIn] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
let cancelled = false;
|
||||
void fetchAuthSession()
|
||||
.then(({ user }) => {
|
||||
if (!cancelled) setSignedIn(Boolean(user));
|
||||
})
|
||||
.catch(() => {
|
||||
/* guest fallback */
|
||||
});
|
||||
return () => {
|
||||
cancelled = true;
|
||||
};
|
||||
}, []);
|
||||
|
||||
const handleCreateRule = useCallback(() => {
|
||||
prepareFreshCreateFlowEntrySync({ signedIn });
|
||||
router.push("/create/informational");
|
||||
}, [router, signedIn]);
|
||||
router.push(createRuleEntryPath());
|
||||
}, [router]);
|
||||
|
||||
const ruleCategories = useMemo<Category[]>(() => {
|
||||
const groups = messages.heroBanner.ruleCard.categories;
|
||||
|
||||
@@ -4,38 +4,21 @@
|
||||
* Figma: "Section / Your Turn" (24239:1397)
|
||||
*/
|
||||
|
||||
import { memo, useCallback, useEffect, useState } from "react";
|
||||
import { memo, useCallback, useState } from "react";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useMessages } from "../../../contexts/MessagesContext";
|
||||
import { fetchAuthSession } from "../../../../lib/create/api";
|
||||
import { prepareFreshCreateFlowEntrySync } from "../../../(app)/create/utils/prepareFreshCreateFlowEntry";
|
||||
import { createRuleEntryPath } from "../../../(app)/create/utils/createRuleEntry";
|
||||
import AskOrganizerInquiryModal from "../../modals/AskOrganizerInquiry";
|
||||
import YourTurnView from "./YourTurn.view";
|
||||
|
||||
const YourTurnContainer = memo(() => {
|
||||
const router = useRouter();
|
||||
const copy = useMessages().pages.about.yourTurn;
|
||||
const [signedIn, setSignedIn] = useState(false);
|
||||
const [inquiryOpen, setInquiryOpen] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
let cancelled = false;
|
||||
void fetchAuthSession()
|
||||
.then(({ user }) => {
|
||||
if (!cancelled) setSignedIn(Boolean(user));
|
||||
})
|
||||
.catch(() => {
|
||||
/* guest fallback */
|
||||
});
|
||||
return () => {
|
||||
cancelled = true;
|
||||
};
|
||||
}, []);
|
||||
|
||||
const onCreateRule = useCallback(() => {
|
||||
prepareFreshCreateFlowEntrySync({ signedIn });
|
||||
router.push("/create/informational");
|
||||
}, [router, signedIn]);
|
||||
router.push(createRuleEntryPath());
|
||||
}, [router]);
|
||||
|
||||
return (
|
||||
<>
|
||||
|
||||
Reference in new issue
Block a user