Keep a continued draft on screen, ask before Edit drops rewritten copy, and retry clearing the draft after publish.
This commit is contained in:
1 parent
54a4871ad1
commit
7c08766092
11 files changed
+361
-41
No files matched your search
@@ -18,6 +18,15 @@ import {
|
||||
} from "../utils/flowSteps";
|
||||
import { createFlowStepPath } from "../utils/createFlowPaths";
|
||||
|
||||
const DRAFT_DELETE_ATTEMPTS = 3;
|
||||
|
||||
/** The rule is saved. Keep trying until the source draft is actually gone. */
|
||||
async function deleteServerDraftAfterPublish(): Promise<void> {
|
||||
for (let attempt = 0; attempt < DRAFT_DELETE_ATTEMPTS; attempt += 1) {
|
||||
if (await deleteServerDraft()) return;
|
||||
}
|
||||
}
|
||||
|
||||
type AppRouterLike = { push: (_href: string) => void };
|
||||
|
||||
type OpenLogin = (args: {
|
||||
@@ -154,7 +163,7 @@ export function useCreateFlowFinalize({
|
||||
document: ruleDocument,
|
||||
});
|
||||
updateState({ editingPublishedRuleId: undefined });
|
||||
void deleteServerDraft();
|
||||
void deleteServerDraftAfterPublish();
|
||||
router.push(createFlowStepPath("completed"));
|
||||
return;
|
||||
}
|
||||
@@ -209,7 +218,7 @@ export function useCreateFlowFinalize({
|
||||
writePendingKeepRuleLogin();
|
||||
onGuestPublished?.({ skippedInvites: skippedGuestInvites });
|
||||
} else {
|
||||
void deleteServerDraft();
|
||||
void deleteServerDraftAfterPublish();
|
||||
}
|
||||
router.push(
|
||||
createFlowStepPath("completed", {
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
import type { CreateFlowState } from "../types";
|
||||
import { forgetFlushedCommunityAvatarUrl } from "../../../../lib/create/flushPendingCommunityAvatar";
|
||||
import { clearPendingCommunityAvatarFile } from "../../../../lib/create/pendingCommunityAvatarUpload";
|
||||
import {
|
||||
clearTransferPendingFlag,
|
||||
writeAnonymousCreateFlowState,
|
||||
} from "./anonymousDraftStorage";
|
||||
import { writeCoreValueDetailsToLocalStorage } from "./coreValueDetailsLocalStorage";
|
||||
|
||||
/**
|
||||
* Profile already has the server draft. Write that snapshot into the browser
|
||||
* before opening the wizard so the create flow can mount it immediately,
|
||||
* including when backend sync is off and hydration will not refetch.
|
||||
*/
|
||||
export function seedContinuedDraftLocalStorage(state: CreateFlowState): void {
|
||||
writeAnonymousCreateFlowState(state);
|
||||
writeCoreValueDetailsToLocalStorage(state.coreValueDetailsByChipId);
|
||||
clearTransferPendingFlag();
|
||||
forgetFlushedCommunityAvatarUrl();
|
||||
void clearPendingCommunityAvatarFile();
|
||||
}
|
||||
@@ -37,9 +37,9 @@ import {
|
||||
} from "../create/utils/flowSteps";
|
||||
import { clearAnonymousCreateFlowStorage } from "../create/utils/anonymousDraftStorage";
|
||||
import { clearBrowserRuleData } from "../create/utils/clearBrowserRuleData";
|
||||
import { clearCoreValueDetailsLocalStorage } from "../create/utils/coreValueDetailsLocalStorage";
|
||||
import { createRuleEntryPath } from "../create/utils/createRuleEntry";
|
||||
import { createFlowStepPath } from "../create/utils/createFlowPaths";
|
||||
import { seedContinuedDraftLocalStorage } from "../create/utils/seedContinuedDraftLocalStorage";
|
||||
import { useMediaQuery } from "../../hooks/useMediaQuery";
|
||||
import {
|
||||
ProfilePageSignedOutView,
|
||||
@@ -294,9 +294,8 @@ export default function ProfilePageClient() {
|
||||
const handleContinueDraft = useCallback(() => {
|
||||
if (draft == null || !draft.hasDraft) return;
|
||||
const step = resumeCreateFlowStep(draft.state);
|
||||
clearAnonymousCreateFlowStorage();
|
||||
clearCoreValueDetailsLocalStorage();
|
||||
router.push(`/create/${step}`);
|
||||
seedContinuedDraftLocalStorage(draft.state);
|
||||
router.push(createFlowStepPath(step));
|
||||
}, [draft, router]);
|
||||
|
||||
const handleStartNewCustomRule = useCallback(() => {
|
||||
|
||||
Reference in new issue
Block a user