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!

refactor(web): finding 7 - extract makeCustomSection, derive isStandard

Amruth Pillai27efeab7965d
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<string, unknown>): 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,20 +196,11 @@ export function addItemToSection(
* @param targetPageIndex - The page index to add the section to
* @returns The ID of the newly created custom section
*/
-export function createCustomSectionWithItem(
- draft: WritableDraft<ResumeData>,
- item: SectionItem,
- type: CustomSectionType,
- sectionTitle: string,
- targetPageIndex: number,
-): string {
- const newSectionId = generateId();
-
- // Create the new custom section
- const newSection: CustomSection = {
- id: newSectionId,
+function makeCustomSection(id: string, type: CustomSectionType, title: string, item: SectionItem): CustomSection {
+ return {
+ id,
type,
- title: sectionTitle,
+ title,
icon: "",
columns: 1,
hidden: false,
@@ -235,26 +208,24 @@ export function createCustomSectionWithItem(
startOnNewPage: false,
items: [item as never],
};
+}
- draft.customSections.push(newSection as WritableDraft<CustomSection>);
+export function createCustomSectionWithItem(
+ draft: WritableDraft<ResumeData>,
+ item: SectionItem,
+ type: CustomSectionType,
+ sectionTitle: string,
+ targetPageIndex: number,
+): string {
+ const newSectionId = generateId();
+ draft.customSections.push(makeCustomSection(newSectionId, type, sectionTitle, item) as WritableDraft<CustomSection>);
- // 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<ResumeData>,
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<CustomSection>);
-
- // 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<CustomSection>);
+ draft.metadata.layout.pages.push({ fullWidth: false, main: [newSectionId], sidebar: [] });
}