Skip to content

A one-of-a-kind resume builder that keeps your privacy in mind. Completely secure, customizable, portable, open-source and free forever. Try it out today!

fix: retain empty editor sections after entry deletion

Amruth Pillaia45b969c7e5f
diff --git a/apps/mobile/scripts/outline-retention.test.mjs b/apps/mobile/scripts/outline-retention.test.mjs
new file mode 100644
index 000000000..0ab744c66
--- /dev/null
+++ b/apps/mobile/scripts/outline-retention.test.mjs
@@ -0,0 +1,142 @@
+import assert from "node:assert/strict";
+import { readFileSync } from "node:fs";
+import { createRequire } from "node:module";
+import { test } from "node:test";
+import { i18n } from "@lingui/core";
+
+const require = createRequire(new URL("../../server/package.json", import.meta.url));
+const { buildSync, transformSync } = createRequire(require.resolve("tsx"))("esbuild");
+i18n.loadAndActivate({ locale: "en-US", messages: {} });
+function domain(path) {
+ const code = buildSync({
+ entryPoints: [new URL(path, import.meta.url).pathname],
+ bundle: true,
+ platform: "node",
+ format: "cjs",
+ write: false,
+ }).outputFiles[0].text;
+ const module = { exports: {} };
+ new Function("require", "module", "exports", code)(require, module, module.exports);
+ return module.exports;
+}
+const model = domain("../src/features/write/model.ts");
+const { defaultResumeData } = domain("../../../packages/schema/src/resume/default.ts");
+
+for (const via of ["inline options", "entry screen"]) {
+ test(`native opened section keeps its Add action after final deletion via ${via}`, () => {
+ const data = structuredClone(defaultResumeData);
+ const entry = model.createEntry("experience");
+ entry.position = "Fictional engineer";
+ data.sections.experience.items = [entry];
+ const before = JSON.stringify(data);
+ let slots = [];
+ let cursor = 0;
+ const react = {
+ createElement: (type, props, ...children) => ({ type, props: { ...props, children } }),
+ useMemo: (make) => make(),
+ useState(initial) {
+ const index = cursor++;
+ if (!(index in slots)) slots[index] = typeof initial === "function" ? initial() : initial;
+ const owner = slots;
+ return [
+ owner[index],
+ (next) => {
+ owner[index] = typeof next === "function" ? next(owner[index]) : next;
+ },
+ ];
+ },
+ };
+ const tag = (parts, ...values) => parts.reduce((text, part, i) => text + part + (values[i] ?? ""), "");
+ const ui = Object.fromEntries(
+ ["Banner", "Button", "Chip", "Icon", "IconButton", "ListRow", "Sheet", "SortableList", "Text"].map((name) => [
+ name,
+ name,
+ ]),
+ );
+ ui.useTheme = () => ({ space: { s2: 8, s3: 12, s4: 16 } });
+ const boundary = {
+ react,
+ "react-native": { Pressable: "Pressable", View: "View" },
+ "@lingui/core": { i18n },
+ "@lingui/core/macro": {
+ plural: (count, forms) => (count === 1 ? forms.one : forms.other).replace("#", String(count)),
+ },
+ "@lingui/react/macro": { useLingui: () => ({ t: tag }) },
+ "expo-image": { Image: "Image" },
+ "expo-router": { useRouter: () => ({ push() {} }) },
+ "@reactive-resume/utils/string": { getInitials: () => "FE" },
+ "./entry-sheet": { EntrySheet: "EntrySheet" },
+ "./fields": { ADD_LABELS: {}, SECTION_ICONS: {}, SECTION_TITLES: {} },
+ "./hooks": {
+ useWriteData: (select) => select(data),
+ edit: (write) => write(data),
+ addEntry() {},
+ requestFocus() {},
+ },
+ "./model": model,
+ "./picture-screen": { resolvePictureUrl: (url) => url },
+ "./resume-language": { ResumeLanguage: "ResumeLanguage" },
+ "./section-sheet": { SectionSheet: "SectionSheet" },
+ "@/auth/session": { useSession: () => ({ server: "https://fictional.example.test" }) },
+ "@/draft": { useIsResumeLocked: () => false },
+ "@/features/write/unlock": { useUnlockResume: () => ({ unlock() {}, isPending: false }) },
+ "@/routes": { routes: { entry: () => "/fictional-entry" } },
+ "@/ui": ui,
+ };
+ const module = { exports: {} };
+ const code = transformSync(readFileSync(new URL("../src/features/write/outline.tsx", import.meta.url), "utf8"), {
+ loader: "tsx",
+ format: "cjs",
+ jsx: "transform",
+ }).code;
+ new Function("React", "require", "module", "exports", code)(
+ react,
+ (name) => {
+ assert.ok(name in boundary, `Missing boundary: ${name}`);
+ return boundary[name];
+ },
+ module,
+ module.exports,
+ );
+ const { Outline } = module.exports;
+ const nodes = (tree) =>
+ !tree || typeof tree !== "object"
+ ? []
+ : Array.isArray(tree)
+ ? tree.flatMap(nodes)
+ : [tree, ...nodes(tree.props.children)];
+ const render = () => {
+ cursor = 0;
+ return Outline({ resumeId: "fictional-resume" });
+ };
+ const list = () => nodes(render()).find((node) => node.type === "SortableList").props;
+ const row = (kind) => {
+ const current = list();
+ const item = current.data.find(
+ (item) => item.kind === kind && (kind === "section" ? item.row.id : item.sectionId) === "experience",
+ );
+ assert.ok(item, `Missing ${kind}`);
+ return current.renderItem({ item, drag() {}, isActive: false });
+ };
+ row("section").props.onToggle();
+ if (via === "entry screen") row("entry").props.onOpen();
+ else {
+ row("entry").props.onOptions();
+ const sheet = nodes(render()).find((node) => node.type === "EntrySheet");
+ assert.ok(sheet);
+ // EntrySheet calls this existing lifecycle callback before deleting or moving the entry.
+ sheet.props.onGone?.();
+ }
+ assert.equal(JSON.stringify(data), before, "opening and retaining a section never changes the resume");
+ // The unchanged deletion owner supplies an empty section; exercise the actual Outline/model consumer.
+ data.sections.experience.items = [];
+ assert.ok(list().data.some((item) => item.kind === "section" && item.row.id === "experience"));
+ assert.ok(list().data.some((item) => item.kind === "add" && item.sectionId === "experience"));
+ assert.equal(data.sections.experience.items.length, 0, "retention must not create a fake entry");
+ slots = [];
+ assert.ok(
+ !list().data.some((item) => item.kind === "section" && item.row.id === "experience"),
+ "a new visit resets ephemeral retention",
+ );
+ });
+}
diff --git a/apps/mobile/src/features/write/outline.tsx b/apps/mobile/src/features/write/outline.tsx
index 2e656c189..331105067 100644
--- a/apps/mobile/src/features/write/outline.tsx
+++ b/apps/mobile/src/features/write/outline.tsx
@@ -71,7 +71,9 @@ export function Outline({ resumeId, imported, initialSection }: OutlineProps) {
if (!next.delete(id)) next.add(id);
return next;
});
+ const retainSection = (id: string) => setAdded((current) => (current.has(id) ? current : new Set(current).add(id)));
const openEntry = (sectionId: string, entryId: string, focus = false) => {
+ retainSection(sectionId);
if (focus) requestFocus(entryId);
router.push(routes.entry(resumeId, sectionId, entryId));
};
@@ -220,6 +222,7 @@ export function Outline({ resumeId, imported, initialSection }: OutlineProps) {
entryId={sheet.entryId}
open
onClose={() => setSheet(null)}
+ onGone={() => retainSection(entrySection.id)}
/>
) : null}
<AddSectionSheet
diff --git a/apps/web/src/features/resume/editor/write/entry-card.tsx b/apps/web/src/features/resume/editor/write/entry-card.tsx
index d0ca68593..a9dd01130 100644
--- a/apps/web/src/features/resume/editor/write/entry-card.tsx
+++ b/apps/web/src/features/resume/editor/write/entry-card.tsx
@@ -259,6 +259,7 @@ function deleteEntry(section: WriteSection, entryId: string) {
const index = entries.findIndex((entry) => entry.id === entryId);
const deleted = entries[index];
if (!deleted) return;
+ if (entries.length === 1) useEditorStore.getState().markSectionAdded(section.id);
updateResumeData(
(draft) => {
const items = getEntries(draft, section);
diff --git a/docs/guides/editing-entries.mdx b/docs/guides/editing-entries.mdx
index a44c5ce34..c6afca6a7 100644
--- a/docs/guides/editing-entries.mdx
+++ b/docs/guides/editing-entries.mdx
@@ -91,6 +91,15 @@ When you move the last entry out of a custom section, that empty section is remo
Select **Delete** in the entry menu, or the trash icon that appears next to an open entry's title. The entry is removed right away, and the **Entry deleted** message has an **Undo** button if you change your mind.
+The section stays available after its last entry is deleted, so you can use **Add experience** (or the matching add action) to write another. In the browser, keyboard focus returns to a surviving entry, or to that add action when no entries remain.
+
+<Frame caption="An empty section stays ready for another entry">
+ <img
+ src="/images/guides/editing-entries/empty-experience.webp"
+ alt="Experience section after its last entry is deleted, with Add experience available"
+ />
+</Frame>
+
## Fields by section type
The **main field** is the one an entry needs before it prints.
diff --git a/docs/images/guides/editing-entries/empty-experience.webp b/docs/images/guides/editing-entries/empty-experience.webp
new file mode 100644
index 000000000..f0483a27a
Binary files /dev/null and b/docs/images/guides/editing-entries/empty-experience.webp differ
diff --git a/tests/e2e/specs/builder-entry-focus.spec.ts b/tests/e2e/specs/builder-entry-focus.spec.ts
new file mode 100644
index 000000000..e40e18135
--- /dev/null
+++ b/tests/e2e/specs/builder-entry-focus.spec.ts
@@ -0,0 +1,85 @@
+import type { Page } from "@playwright/test";
+import { expect, test } from "../fixtures/test";
+
+async function resume(page: Page) {
+ const created = await page.request.post("/api/openapi/resumes", {
+ data: { name: "Fictional focus example", tags: [], withSampleData: true },
+ });
+ expect(created.ok()).toBe(true);
+ const id = await created.json();
+ const response = await page.request.get(`/api/openapi/resumes/${id}`);
+ expect(response.ok()).toBe(true);
+ const original = await response.json();
+ const first = original.data.sections.experience.items[0];
+ const entries = [
+ { ...structuredClone(first), position: "Fictional first role" },
+ {
+ ...structuredClone(first),
+ id: first.id.slice(0, -1) + (first.id.endsWith("a") ? "b" : "a"),
+ position: "Fictional second role",
+ },
+ ];
+ const patched = await page.request.patch(`/api/openapi/resumes/${id}`, {
+ data: { operations: [{ op: "replace", path: "/sections/experience/items", value: entries }] },
+ });
+ expect(patched.ok()).toBe(true);
+ return { id, entries };
+}
+
+async function count(page: Page, id: string) {
+ const response = await page.request.get(`/api/openapi/resumes/${id}`);
+ expect(response.ok()).toBe(true);
+ return (await response.json()).data.sections.experience.items.length;
+}
+
+test("deletion focuses a surviving entry then the retained section Add action", async ({ authPage: page }, info) => {
+ await page.setViewportSize({ width: 1440, height: 900 });
+ const { id, entries } = await resume(page);
+ await page.goto(`/builder/${id}`);
+ await page.locator("#sidebar-experience").getByRole("button", { name: "Experience", exact: true }).click();
+ const first = page.locator(`[data-entry-id="${entries[0].id}"]`);
+ const second = page.locator(`[data-entry-id="${entries[1].id}"]`);
+ const title = first.locator("button[aria-expanded]").first();
+ await title.focus();
+ await title.press("Alt+ArrowDown");
+ await expect(title).toBeFocused();
+ await expect(
+ page
+ .locator('[aria-live="polite"]')
+ .filter({ hasText: /entry 2 of 2/ })
+ .first(),
+ ).toContainText(entries[0].position);
+ await title.click();
+ await first.getByRole("button", { name: "Delete entry", exact: true }).click();
+ await expect(second.locator("button[aria-expanded]").first()).toBeFocused();
+ await second.locator("button[aria-expanded]").first().click();
+ await second.getByRole("button", { name: "Delete entry", exact: true }).click();
+ const add = page.getByRole("button", { name: "Add experience", exact: true });
+ await expect(add).toBeFocused();
+ await expect.poll(() => count(page, id)).toBe(0);
+ await page
+ .locator("#sidebar-experience")
+ .screenshot({ path: info.outputPath("empty-experience.png"), animations: "disabled" });
+ await add.press("Enter");
+ await expect(page.locator("#sidebar-experience input:focus")).toHaveCount(1);
+ await expect.poll(() => count(page, id)).toBe(1);
+});
+
+test("phone final deletion returns to its section Add action", async ({ authPage: page }) => {
+ await page.setViewportSize({ width: 390, height: 844 });
+ const { id, entries } = await resume(page);
+ const patch = await page.request.patch(`/api/openapi/resumes/${id}`, {
+ data: { operations: [{ op: "replace", path: "/sections/experience/items", value: entries.slice(0, 1) }] },
+ });
+ expect(patch.ok()).toBe(true);
+ await page.goto(`/builder/${id}`);
+ await page.getByRole("button", { name: "Write", exact: true }).click();
+ await page.locator("#sidebar-experience").getByRole("button", { name: "Experience", exact: true }).click();
+ await page.locator(`[data-entry-id="${entries[0].id}"] button[aria-expanded]`).first().click();
+ const sheet = page.getByRole("dialog", { name: entries[0].position, exact: true });
+ await expect(sheet).toBeVisible();
+ await sheet.getByRole("button", { name: "Delete entry", exact: true }).click();
+ await expect(sheet).toBeHidden();
+ await expect(page.getByRole("button", { name: "Add experience", exact: true })).toBeFocused();
+ await expect.poll(() => count(page, id)).toBe(0);
+});