Skip to content

Commit

Permalink
Merge pull request #555 from Lemoncode/Bug/#554-heading-size-old-vers…
Browse files Browse the repository at this point in the history
…ion-not-showing

Bug/#554 heading size old version not showing
  • Loading branch information
brauliodiez authored Nov 18, 2024
2 parents bb6cbb0 + caa8732 commit 6642cd5
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 2 deletions.
74 changes: 73 additions & 1 deletion src/core/local-disk/shapes-to-document.mapper.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { FONT_SIZE_VALUES } from '@/common/components/mock-components/front-components/shape.const';
import { ShapeModel } from '../model';
import { DocumentModel } from '../providers/canvas/canvas.model';
import { QuickMockFileContract } from './local-disk.model';
Expand All @@ -21,18 +22,89 @@ export const mapFromQuickMockFileDocumentToApplicationDocument = (
};
};

const mapTextElementFromV0_1ToV0_2 = (shape: ShapeModel): ShapeModel => {
switch (shape.type) {
case 'heading1':
return {
...shape,
otherProps: {
...shape,
fontSize: FONT_SIZE_VALUES.HEADING1,
},
};
case 'heading2':
return {
...shape,
otherProps: {
...shape,
fontSize: FONT_SIZE_VALUES.HEADING2,
},
};
case 'heading3':
return {
...shape,
otherProps: {
...shape,
fontSize: FONT_SIZE_VALUES.HEADING3,
},
};
case 'link':
return {
...shape,
otherProps: {
...shape,
fontSize: FONT_SIZE_VALUES.LINK,
},
};
case 'normaltext':
return {
...shape,
otherProps: {
...shape,
fontSize: FONT_SIZE_VALUES.NORMALTEXT,
},
};
case 'smalltext':
return {
...shape,
otherProps: {
...shape,
fontSize: FONT_SIZE_VALUES.SMALLTEXT,
},
};
case 'paragraph':
return {
...shape,
otherProps: {
...shape,
fontSize: FONT_SIZE_VALUES.PARAGRAPH,
},
};
default:
return shape;
}
};

const setTextElementsDefaultFontSizeV0_1 = (
shapes: ShapeModel[]
): ShapeModel[] => {
return shapes.map(mapTextElementFromV0_1ToV0_2);
};

// Example function to handle version 0.1 parsing
export const mapFromQuickMockFileDocumentToApplicationDocumentV0_1 = (
fileDocument: QuickMockFileContract
): DocumentModel => {
// Combine all shapes into a single page
const combinedShapes: ShapeModel[] = fileDocument.pages.reduce<ShapeModel[]>(
let combinedShapes: ShapeModel[] = fileDocument.pages.reduce<ShapeModel[]>(
(acc: ShapeModel[], page) => {
return acc.concat(page.shapes);
},
[]
);

combinedShapes = setTextElementsDefaultFontSizeV0_1(combinedShapes);

return {
activePageIndex: 0,
pages: [
Expand Down
1 change: 0 additions & 1 deletion src/core/local-disk/use-local-disk.hook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ export const useLocalDisk = () => {
reader.onload = () => {
const content = reader.result as string;
const parseData: QuickMockFileContract = JSON.parse(content);

if (parseData.version === '0.1') {
// Handle version 0.1 parsing
const appDocument =
Expand Down

0 comments on commit 6642cd5

Please sign in to comment.