Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Canvas history #39

Merged
merged 14 commits into from
Dec 14, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
refactor: Move auto save logic out of canvas
surajshetty3416 committed Dec 14, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit 08caa9ef334a896aca6476ad135fbb08acf9231d
18 changes: 2 additions & 16 deletions frontend/src/components/BuilderCanvas.vue
Original file line number Diff line number Diff line change
@@ -70,14 +70,13 @@ import { addPxToNumber, getNumberFromPx } from "@/utils/helpers";
import {
UseRefHistoryReturn,
clamp,
useDebounceFn,
useDebouncedRefHistory,
useDropZone,
useElementBounding,
useEventListener,
} from "@vueuse/core";
import { FeatherIcon } from "frappe-ui";
import { Ref, computed, nextTick, onMounted, provide, reactive, ref, watch, watchEffect } from "vue";
import { Ref, computed, nextTick, onMounted, provide, reactive, ref, watchEffect } from "vue";
import useStore from "../store";
import setPanAndZoom from "../utils/panAndZoom";
import BlockSnapGuides from "./BlockSnapGuides.vue";
@@ -384,20 +383,6 @@ const setRootBlock = (newBlock: Block) => {
setupHistory();
};

const debouncedPageSave = useDebounceFn(store.savePage, 500);

watch(
() => block.value,
() => {
if (store.selectedPage && store.autoSave && !store.settingPage && !store.editingComponent) {
debouncedPageSave();
}
},
{
deep: true,
}
);

defineExpose({
setScaleAndTranslate,
resetZoom,
@@ -409,5 +394,6 @@ defineExpose({
getFirstBlock,
block,
setRootBlock,
canvasProps,
});
</script>
8 changes: 6 additions & 2 deletions frontend/src/store.ts
Original file line number Diff line number Diff line change
@@ -31,6 +31,7 @@ const useStore = defineStore("store", {
hoveredBreakpoint: <string | null>null,
routeVariables: <{ [key: string]: string }>{},
autoSave: true,
pageBlocks: <Block[]>[],
builderLayout: {
rightPanelWidth: 275,
leftPanelWidth: 280,
@@ -85,7 +86,7 @@ const useStore = defineStore("store", {
this.activeCanvas.setRootBlock(firstBlock);
} else {
for (let block of blocks) {
parent.children.push(this.getBlockInstance(block));
parent?.children.push(this.getBlockInstance(block));
}
}
},
@@ -122,6 +123,7 @@ const useStore = defineStore("store", {
this.pushBlocks([blocks]);
}
this.activeCanvas?.setRootBlock(this.getBlockInstance(blocks[0]));
this.pageBlocks = [this.getBlockInstance(blocks[0])];
this.pageName = page.page_name as string;
this.route = page.route || "/" + this.pageName.toLowerCase().replace(/ /g, "-");
this.selectedPage = page.name;
@@ -341,7 +343,9 @@ const useStore = defineStore("store", {
window.open(`/${route}`, "builder-preview");
},
savePage() {
const pageData = JSON.stringify(this.getPageData());
this.pageBlocks = this.getPageData() as Block[];
const pageData = JSON.stringify(this.pageBlocks);

const args = {
name: this.selectedPage,
draft_blocks: pageData,