mirror of
https://github.com/AmruthPillai/Reactive-Resume.git
synced 2026-07-26 18:04:45 +10:00
replace JSON.parse(JSON.stringify({})) with structuredClone({})
This commit is contained in:
@@ -91,7 +91,7 @@ export const CustomFieldsSection = ({ className }: Props) => {
|
|||||||
|
|
||||||
const onChangeCustomField = (field: ICustomField) => {
|
const onChangeCustomField = (field: ICustomField) => {
|
||||||
const index = customFields.findIndex((item) => item.id === field.id);
|
const index = customFields.findIndex((item) => item.id === field.id);
|
||||||
const newCustomFields = JSON.parse(JSON.stringify(customFields)) as ICustomField[];
|
const newCustomFields = structuredClone(customFields);
|
||||||
newCustomFields[index] = field;
|
newCustomFields[index] = field;
|
||||||
|
|
||||||
setValue("basics.customFields", newCustomFields);
|
setValue("basics.customFields", newCustomFields);
|
||||||
|
|||||||
@@ -163,7 +163,7 @@ export const LayoutSection = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const onAddPage = () => {
|
const onAddPage = () => {
|
||||||
const layoutCopy = JSON.parse(JSON.stringify(layout)) as string[][][];
|
const layoutCopy = structuredClone(layout);
|
||||||
|
|
||||||
layoutCopy.push([[], []]);
|
layoutCopy.push([[], []]);
|
||||||
|
|
||||||
@@ -171,7 +171,7 @@ export const LayoutSection = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const onRemovePage = (page: number) => {
|
const onRemovePage = (page: number) => {
|
||||||
const layoutCopy = JSON.parse(JSON.stringify(layout)) as string[][][];
|
const layoutCopy = structuredClone(layout);
|
||||||
|
|
||||||
layoutCopy[0][0].push(...layoutCopy[page][0]); // Main
|
layoutCopy[0][0].push(...layoutCopy[page][0]); // Main
|
||||||
layoutCopy[0][1].push(...layoutCopy[page][1]); // Sidebar
|
layoutCopy[0][1].push(...layoutCopy[page][1]); // Sidebar
|
||||||
@@ -182,7 +182,7 @@ export const LayoutSection = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const onResetLayout = () => {
|
const onResetLayout = () => {
|
||||||
const layoutCopy = JSON.parse(JSON.stringify(defaultMetadata.layout)) as string[][][];
|
const layoutCopy = structuredClone(defaultMetadata.layout);
|
||||||
|
|
||||||
// Loop through all pages and columns, and get any sections that start with "custom."
|
// Loop through all pages and columns, and get any sections that start with "custom."
|
||||||
// These should be appended to the first page of the new layout.
|
// These should be appended to the first page of the new layout.
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ export const useResumeStore = create<ResumeStore>()(
|
|||||||
state.resume.data = _set(state.resume.data, path, value);
|
state.resume.data = _set(state.resume.data, path, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
void debouncedUpdateResume(JSON.parse(JSON.stringify(state.resume)));
|
void debouncedUpdateResume(structuredClone(state.resume));
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
addSection: () => {
|
addSection: () => {
|
||||||
@@ -51,7 +51,7 @@ export const useResumeStore = create<ResumeStore>()(
|
|||||||
state.resume.data.metadata.layout[lastPageIndex][0].push(`custom.${section.id}`);
|
state.resume.data.metadata.layout[lastPageIndex][0].push(`custom.${section.id}`);
|
||||||
state.resume.data = _set(state.resume.data, `sections.custom.${section.id}`, section);
|
state.resume.data = _set(state.resume.data, `sections.custom.${section.id}`, section);
|
||||||
|
|
||||||
void debouncedUpdateResume(JSON.parse(JSON.stringify(state.resume)));
|
void debouncedUpdateResume(structuredClone(state.resume));
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
removeSection: (sectionId: SectionKey) => {
|
removeSection: (sectionId: SectionKey) => {
|
||||||
@@ -63,7 +63,7 @@ export const useResumeStore = create<ResumeStore>()(
|
|||||||
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
|
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
|
||||||
delete state.resume.data.sections.custom[id];
|
delete state.resume.data.sections.custom[id];
|
||||||
|
|
||||||
void debouncedUpdateResume(JSON.parse(JSON.stringify(state.resume)));
|
void debouncedUpdateResume(structuredClone(state.resume));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ import {
|
|||||||
defaultResumeData,
|
defaultResumeData,
|
||||||
defaultSkill,
|
defaultSkill,
|
||||||
defaultVolunteer,
|
defaultVolunteer,
|
||||||
ResumeData,
|
|
||||||
} from "@reactive-resume/schema";
|
} from "@reactive-resume/schema";
|
||||||
import { Json } from "@reactive-resume/utils";
|
import { Json } from "@reactive-resume/utils";
|
||||||
import { Schema } from "zod";
|
import { Schema } from "zod";
|
||||||
@@ -58,7 +57,7 @@ export class JsonResumeParser implements Parser<Json, JsonResume> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
convert(data: JsonResume) {
|
convert(data: JsonResume) {
|
||||||
const result = JSON.parse(JSON.stringify(defaultResumeData)) as ResumeData;
|
const result = structuredClone(defaultResumeData);
|
||||||
|
|
||||||
// Basics
|
// Basics
|
||||||
result.basics.name = data.basics?.name ?? "";
|
result.basics.name = data.basics?.name ?? "";
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ import {
|
|||||||
defaultProject,
|
defaultProject,
|
||||||
defaultResumeData,
|
defaultResumeData,
|
||||||
defaultSkill,
|
defaultSkill,
|
||||||
ResumeData,
|
|
||||||
resumeDataSchema,
|
resumeDataSchema,
|
||||||
} from "@reactive-resume/schema";
|
} from "@reactive-resume/schema";
|
||||||
import { extractUrl, Json, parseArrayLikeCSVEntry, parseCSV } from "@reactive-resume/utils";
|
import { extractUrl, Json, parseArrayLikeCSVEntry, parseCSV } from "@reactive-resume/utils";
|
||||||
@@ -58,7 +57,7 @@ export class LinkedInParser implements Parser<JSZip, LinkedIn> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
convert(data: LinkedIn) {
|
convert(data: LinkedIn) {
|
||||||
const result = JSON.parse(JSON.stringify(defaultResumeData)) as ResumeData;
|
const result = structuredClone(defaultResumeData);
|
||||||
|
|
||||||
// Profile
|
// Profile
|
||||||
if (data.Profile && data.Profile.length > 0) {
|
if (data.Profile && data.Profile.length > 0) {
|
||||||
|
|||||||
@@ -14,7 +14,6 @@ import {
|
|||||||
defaultResumeData,
|
defaultResumeData,
|
||||||
defaultSkill,
|
defaultSkill,
|
||||||
defaultVolunteer,
|
defaultVolunteer,
|
||||||
ResumeData,
|
|
||||||
} from "@reactive-resume/schema";
|
} from "@reactive-resume/schema";
|
||||||
import { isUrl, Json } from "@reactive-resume/utils";
|
import { isUrl, Json } from "@reactive-resume/utils";
|
||||||
import { Schema } from "zod";
|
import { Schema } from "zod";
|
||||||
@@ -60,7 +59,7 @@ export class ReactiveResumeV3Parser implements Parser<Json, ReactiveResumeV3> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
convert(data: ReactiveResumeV3) {
|
convert(data: ReactiveResumeV3) {
|
||||||
const result = JSON.parse(JSON.stringify(defaultResumeData)) as ResumeData;
|
const result = structuredClone(defaultResumeData);
|
||||||
|
|
||||||
// Basics
|
// Basics
|
||||||
result.basics.name = data.basics.name ?? "";
|
result.basics.name = data.basics.name ?? "";
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ export const moveItemInLayout = (
|
|||||||
): string[][][] => {
|
): string[][][] => {
|
||||||
try {
|
try {
|
||||||
// Create a deep copy of the layout to avoid mutating the original array
|
// Create a deep copy of the layout to avoid mutating the original array
|
||||||
const newLayout = JSON.parse(JSON.stringify(layout)) as string[][][];
|
const newLayout = structuredClone(layout);
|
||||||
|
|
||||||
// Get the item from the current location
|
// Get the item from the current location
|
||||||
const item = newLayout[current.page][current.column][current.section];
|
const item = newLayout[current.page][current.column][current.section];
|
||||||
|
|||||||
@@ -84,7 +84,7 @@ describe("moveItemInLayout", () => {
|
|||||||
[["item1"], ["item2"]],
|
[["item1"], ["item2"]],
|
||||||
[["item3"], ["item4"]],
|
[["item3"], ["item4"]],
|
||||||
];
|
];
|
||||||
const layoutCopy = JSON.parse(JSON.stringify(layout));
|
const layoutCopy = structuredClone(layout);
|
||||||
const current = { page: 0, column: 1, section: 0 };
|
const current = { page: 0, column: 1, section: 0 };
|
||||||
const target = { page: 1, column: 0, section: 1 };
|
const target = { page: 1, column: 0, section: 1 };
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user