mirror of
https://github.com/AmruthPillai/Reactive-Resume.git
synced 2026-07-25 17:34:52 +10:00
refactor(web): finding 7 - extract makeCustomSection, derive isStandard
Extract makeCustomSection factory to eliminate duplicate CustomSection object literal. Replace hand-maintained SectionType array in isStandardSectionId with membership check via `id in sections`. Claude-Session: https://claude.ai/code/session_012Bnvt1MghwHj4qQRxuQUGa
This commit is contained in:
@@ -31,27 +31,9 @@ type MoveTargetPage = {
|
|||||||
// Helper Functions
|
// Helper Functions
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
|
|
||||||
/**
|
// ponytail: derive standard section membership from data instead of a hand-maintained list
|
||||||
* Checks if a section ID belongs to a standard section.
|
function isStandardSectionId(sectionId: string, sections: Record<string, unknown>): sectionId is SectionType {
|
||||||
* Standard sections have predefined keys like "experience", "education", etc.
|
return sectionId in sections;
|
||||||
*/
|
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
@@ -111,7 +93,7 @@ export function getCompatibleMoveTargets(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check if it's a standard section with matching type
|
// Check if it's a standard section with matching type
|
||||||
if (isStandardSectionId(sectionId) && sectionId === sourceType) {
|
if (isStandardSectionId(sectionId, resumeData.sections) && sectionId === sourceType) {
|
||||||
compatibleSections.push({
|
compatibleSections.push({
|
||||||
sectionId,
|
sectionId,
|
||||||
sectionTitle: getDefaultSectionTitle(sectionId),
|
sectionTitle: getDefaultSectionTitle(sectionId),
|
||||||
@@ -189,7 +171,7 @@ export function addItemToSection(
|
|||||||
type: CustomSectionType,
|
type: CustomSectionType,
|
||||||
): void {
|
): void {
|
||||||
// Check if target is a standard section
|
// 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];
|
const section = draft.sections[type as SectionType];
|
||||||
if ("items" in section) {
|
if ("items" in section) {
|
||||||
section.items.push(item as never);
|
section.items.push(item as never);
|
||||||
@@ -214,6 +196,20 @@ export function addItemToSection(
|
|||||||
* @param targetPageIndex - The page index to add the section to
|
* @param targetPageIndex - The page index to add the section to
|
||||||
* @returns The ID of the newly created custom section
|
* @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(
|
export function createCustomSectionWithItem(
|
||||||
draft: WritableDraft<ResumeData>,
|
draft: WritableDraft<ResumeData>,
|
||||||
item: SectionItem,
|
item: SectionItem,
|
||||||
@@ -222,39 +218,14 @@ export function createCustomSectionWithItem(
|
|||||||
targetPageIndex: number,
|
targetPageIndex: number,
|
||||||
): string {
|
): string {
|
||||||
const newSectionId = generateId();
|
const newSectionId = generateId();
|
||||||
|
draft.customSections.push(makeCustomSection(newSectionId, type, sectionTitle, item) as WritableDraft<CustomSection>);
|
||||||
|
|
||||||
// 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<CustomSection>);
|
|
||||||
|
|
||||||
// Add the section to the target page's main column
|
|
||||||
const page = draft.metadata.layout.pages[targetPageIndex];
|
const page = draft.metadata.layout.pages[targetPageIndex];
|
||||||
if (page) {
|
if (page) page.main.push(newSectionId);
|
||||||
page.main.push(newSectionId);
|
|
||||||
}
|
|
||||||
|
|
||||||
return 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(
|
export function createPageWithSection(
|
||||||
draft: WritableDraft<ResumeData>,
|
draft: WritableDraft<ResumeData>,
|
||||||
item: SectionItem,
|
item: SectionItem,
|
||||||
@@ -262,26 +233,6 @@ export function createPageWithSection(
|
|||||||
sectionTitle: string,
|
sectionTitle: string,
|
||||||
): void {
|
): void {
|
||||||
const newSectionId = generateId();
|
const newSectionId = generateId();
|
||||||
|
draft.customSections.push(makeCustomSection(newSectionId, type, sectionTitle, item) as WritableDraft<CustomSection>);
|
||||||
// Create the new custom section
|
draft.metadata.layout.pages.push({ fullWidth: false, main: [newSectionId], sidebar: [] });
|
||||||
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<CustomSection>);
|
|
||||||
|
|
||||||
// Create the new page with the section in the main column
|
|
||||||
draft.metadata.layout.pages.push({
|
|
||||||
fullWidth: false,
|
|
||||||
main: [newSectionId],
|
|
||||||
sidebar: [],
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user