diff --git a/apps/web/src/libs/resume/move-item.ts b/apps/web/src/libs/resume/move-item.ts index bb9c3f720..50b30200b 100644 --- a/apps/web/src/libs/resume/move-item.ts +++ b/apps/web/src/libs/resume/move-item.ts @@ -31,27 +31,9 @@ type MoveTargetPage = { // Helper Functions // ============================================================================ -/** - * Checks if a section ID belongs to a standard section. - * Standard sections have predefined keys like "experience", "education", etc. - */ -function isStandardSectionId(sectionId: string): sectionId is SectionType { - const standardSections: SectionType[] = [ - "profiles", - "experience", - "education", - "projects", - "skills", - "languages", - "interests", - "awards", - "certifications", - "publications", - "volunteer", - "references", - ]; - - return standardSections.includes(sectionId as SectionType); +// ponytail: derive standard section membership from data instead of a hand-maintained list +function isStandardSectionId(sectionId: string, sections: Record): sectionId is SectionType { + return sectionId in sections; } // ============================================================================ @@ -111,7 +93,7 @@ export function getCompatibleMoveTargets( } // Check if it's a standard section with matching type - if (isStandardSectionId(sectionId) && sectionId === sourceType) { + if (isStandardSectionId(sectionId, resumeData.sections) && sectionId === sourceType) { compatibleSections.push({ sectionId, sectionTitle: getDefaultSectionTitle(sectionId), @@ -189,7 +171,7 @@ export function addItemToSection( type: CustomSectionType, ): void { // Check if target is a standard section - if (isStandardSectionId(targetSectionId) && targetSectionId === type) { + if (isStandardSectionId(targetSectionId, draft.sections) && targetSectionId === type) { const section = draft.sections[type as SectionType]; if ("items" in section) { section.items.push(item as never); @@ -214,6 +196,20 @@ export function addItemToSection( * @param targetPageIndex - The page index to add the section to * @returns The ID of the newly created custom section */ +function makeCustomSection(id: string, type: CustomSectionType, title: string, item: SectionItem): CustomSection { + return { + id, + type, + title, + icon: "", + columns: 1, + hidden: false, + keepTogether: false, + startOnNewPage: false, + items: [item as never], + }; +} + export function createCustomSectionWithItem( draft: WritableDraft, item: SectionItem, @@ -222,39 +218,14 @@ export function createCustomSectionWithItem( targetPageIndex: number, ): string { const newSectionId = generateId(); + draft.customSections.push(makeCustomSection(newSectionId, type, sectionTitle, item) as WritableDraft); - // Create the new custom section - const newSection: CustomSection = { - id: newSectionId, - type, - title: sectionTitle, - icon: "", - columns: 1, - hidden: false, - keepTogether: false, - startOnNewPage: false, - items: [item as never], - }; - - draft.customSections.push(newSection as WritableDraft); - - // Add the section to the target page's main column const page = draft.metadata.layout.pages[targetPageIndex]; - if (page) { - page.main.push(newSectionId); - } + if (page) page.main.push(newSectionId); return newSectionId; } -/** - * Creates a new page with a custom section containing the given item. - * - * @param draft - The immer draft of resume data - * @param item - The item to add to the new section - * @param type - The section type for the new custom section - * @param sectionTitle - The title for the new custom section - */ export function createPageWithSection( draft: WritableDraft, item: SectionItem, @@ -262,26 +233,6 @@ export function createPageWithSection( sectionTitle: string, ): void { const newSectionId = generateId(); - - // Create the new custom section - const newSection: CustomSection = { - id: newSectionId, - type, - title: sectionTitle, - icon: "", - columns: 1, - hidden: false, - keepTogether: false, - startOnNewPage: false, - items: [item as never], - }; - - draft.customSections.push(newSection as WritableDraft); - - // Create the new page with the section in the main column - draft.metadata.layout.pages.push({ - fullWidth: false, - main: [newSectionId], - sidebar: [], - }); + draft.customSections.push(makeCustomSection(newSectionId, type, sectionTitle, item) as WritableDraft); + draft.metadata.layout.pages.push({ fullWidth: false, main: [newSectionId], sidebar: [] }); }