Keep the browser draft on screen after Save your progress, including when the save link is dead.
This commit is contained in:
1 parent
d576ed81d9
commit
d31045b0e5
6 files changed
+141
-12
No files matched your search
@@ -18,7 +18,6 @@ import type {
|
||||
import {
|
||||
clearAnonymousCreateFlowStorage,
|
||||
clearLegacyCreateFlowKeysOnce,
|
||||
hasTransferPendingFlag,
|
||||
readAnonymousCreateFlowState,
|
||||
writeAnonymousCreateFlowState,
|
||||
} from "../utils/anonymousDraftStorage";
|
||||
@@ -65,6 +64,7 @@ export function CreateFlowProvider({
|
||||
const [currentStep] = useState<CreateFlowStep | null>(initialStep);
|
||||
const prevPersistRef = useRef(enableLocalDraftMirroring);
|
||||
const persistWriteSkipRef = useRef(true);
|
||||
const coreValueWriteSkipRef = useRef(true);
|
||||
const initialHydrateDoneRef = useRef(false);
|
||||
|
||||
useEffect(() => {
|
||||
@@ -115,13 +115,6 @@ export function CreateFlowProvider({
|
||||
const wasOff = !prevPersistRef.current;
|
||||
prevPersistRef.current = true;
|
||||
if (!wasOff) return;
|
||||
if (hasTransferPendingFlag()) return;
|
||||
if (
|
||||
typeof window !== "undefined" &&
|
||||
new URLSearchParams(window.location.search).get("syncDraft") === "1"
|
||||
) {
|
||||
return;
|
||||
}
|
||||
const from = readAnonymousCreateFlowState();
|
||||
if (Object.keys(from).length === 0) return;
|
||||
// eslint-disable-next-line react-hooks/set-state-in-effect -- hydrate local draft when mirroring turns on
|
||||
@@ -160,8 +153,16 @@ export function CreateFlowProvider({
|
||||
|
||||
/** Meaning/signals for core values: survives refresh for signed-in users; merged with anonymous draft when both exist. */
|
||||
useEffect(() => {
|
||||
if (!enableLocalDraftMirroring) {
|
||||
coreValueWriteSkipRef.current = true;
|
||||
return;
|
||||
}
|
||||
if (coreValueWriteSkipRef.current) {
|
||||
coreValueWriteSkipRef.current = false;
|
||||
return;
|
||||
}
|
||||
writeCoreValueDetailsToLocalStorage(state.coreValueDetailsByChipId);
|
||||
}, [state.coreValueDetailsByChipId]);
|
||||
}, [state.coreValueDetailsByChipId, enableLocalDraftMirroring]);
|
||||
|
||||
const markCreateFlowInteraction = useCallback(() => {
|
||||
setInteractionTouched(true);
|
||||
|
||||
@@ -84,6 +84,16 @@ export function hasTransferPendingFlag(): boolean {
|
||||
}
|
||||
}
|
||||
|
||||
/** Drop the transfer flag without touching the stored draft. */
|
||||
export function clearTransferPendingFlag(): void {
|
||||
if (typeof window === "undefined") return;
|
||||
try {
|
||||
window.localStorage.removeItem(CREATE_FLOW_TRANSFER_PENDING_KEY);
|
||||
} catch {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
|
||||
/** One-time cleanup of pre–anonymous-draft keys. */
|
||||
export function clearLegacyCreateFlowKeysOnce(): void {
|
||||
if (typeof window === "undefined") return;
|
||||
|
||||
@@ -14,6 +14,7 @@ import { buildCreateFlowDraftPayload } from "../../../../lib/create/buildCreateF
|
||||
import { MAGIC_LINK_TTL_MINUTES } from "../../../../lib/privacyRetention";
|
||||
import { safeInternalPath } from "../../../../lib/safeInternalPath";
|
||||
import {
|
||||
clearTransferPendingFlag,
|
||||
readAnonymousCreateFlowState,
|
||||
setTransferPendingFlag,
|
||||
} from "../../../(app)/create/utils/anonymousDraftStorage";
|
||||
@@ -212,6 +213,7 @@ export default function LoginForm({
|
||||
useEffect(() => {
|
||||
if (isExpiredLinkError(errorParam)) {
|
||||
setLinkExpired(true);
|
||||
clearTransferPendingFlag();
|
||||
}
|
||||
}, [errorParam]);
|
||||
|
||||
|
||||
Reference in new issue
Block a user