Skip to content

Commit

Permalink
fix: rendering issue on delete #58
Browse files Browse the repository at this point in the history
  • Loading branch information
NilsJacobsen committed Mar 10, 2023
1 parent cdd6f28 commit 5cf4cc7
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 24 deletions.
6 changes: 3 additions & 3 deletions src/client/components/PageHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ export const PageHeader: FC<PageHeaderProps> = ({ disabled = false }) => {
isIsrMode ? isrUserState : currentUserState
);

useEffect(() => {
console.log(site);
}, [site]);
// useEffect(() => {
// console.log(site);
// }, [site]);

//set initial value
useEffect(() => {
Expand Down
15 changes: 9 additions & 6 deletions src/client/components/studio/StudioEditor.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import debounce from "lodash.debounce";
import dynamic from "next/dynamic";
import Head from "next/head";
import { FC, useEffect, useRef, useState } from "react";
import { FC, useCallback, useEffect, useRef, useState } from "react";
import { useDropzone } from "react-dropzone";
import { Layout, Layouts, Responsive, WidthProvider } from "react-grid-layout";
import { toast } from "react-hot-toast";
Expand Down Expand Up @@ -88,6 +89,7 @@ const StudioEditor = () => {
}
setTimeout(async () => {
if (!site?.layouts || site.layouts == null) return null;
console.log("onSiteChange");
await handleLayoutChange(itemsRef, site.layouts);

setInitialCalculated(true);
Expand All @@ -102,9 +104,9 @@ const StudioEditor = () => {
if (itemsRef.current) itemsRef.current.classList.remove("animated");
}, []);

useEffect(() => {
console.log(site?.layouts);
}, [site]);
// useEffect(() => {
// console.log(site?.layouts);
// }, [site]);

if (!site || !user || !initialCalculated) return null;

Expand Down Expand Up @@ -165,8 +167,9 @@ const StudioEditor = () => {
setBreakpoint(breakpoint);
}}
onLayoutChange={(layout: Layout[], layouts: Layouts) => {
console.log("layout changed");
console.log(layouts);
handleLayoutChange(itemsRef, layouts);

}}
onDrag={onDrag}
>
Expand Down Expand Up @@ -221,4 +224,4 @@ const StudioEditor = () => {
);
};

export default StudioEditor;
export default StudioEditor;
18 changes: 10 additions & 8 deletions src/client/components/studio/hooks/useDeleteExtension.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,23 @@ export const useDeleteExtension = () => {
const [, deleteExtension] = useDeleteExtensionMutation();

const deleteExtensionFromSite = async (extensionId: string) => {
console.log("ID: " + extensionId);

try {
// delete extension from database

if (!siteSlug) return null;
// delete extension from recoil site store
if (!site || !site.extensions) return null;

const newExtensions = [...site.extensions];
const currentExtensions = [...site.extensions];

const extensionIndex = newExtensions.findIndex(
const index = currentExtensions.findIndex(
(extension) => extension.id === extensionId
);
if (extensionIndex !== -1) {
newExtensions.splice(extensionIndex, 1);
setSite({ ...site });
setSite({ ...site, extensions: newExtensions });
console.log(index);
if (index !== -1) {
currentExtensions.splice(index, 1);
console.log(currentExtensions);
setSite({ ...site, extensions: currentExtensions });

await deleteExtension({
id: decodeGlobalID(extensionId).id,
Expand Down
14 changes: 7 additions & 7 deletions src/client/components/studio/hooks/useHandleLayoutChange.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { RefObject } from "react";
import { RefObject, useState } from "react";
import { Layouts } from "react-grid-layout";
import { useRecoilState, useRecoilValue } from "recoil";
import { useUpdateSiteLayoutsMutation } from "../../../graphql/updateSiteLayouts.generated";
Expand Down Expand Up @@ -31,11 +31,11 @@ export const useHandleLayoutChange = () => {
itemsRef: RefObject<HTMLDivElement>,
newlayouts?: Layouts
) => {
console.log("compare", site?.layouts, newlayouts);
//console.log("compare", site?.layouts, newlayouts);
let currentLayouts = newlayouts ? newlayouts : site?.layouts;
if (!currentLayouts || !site) return null;

console.log("before calculation", currentLayouts);
//console.log("before calculation", currentLayouts);

//calculate height
const calculateLayout = () => {
Expand All @@ -44,7 +44,7 @@ export const useHandleLayoutChange = () => {
let index = 0;
const newItems = [...currentLayouts[breakpoint]];

console.log("everything ready for calculation");
//console.log("everything ready for calculation");

if (itemsRef.current?.children[0].children) {
for (const element of itemsRef.current.children[0].children) {
Expand All @@ -66,19 +66,19 @@ export const useHandleLayoutChange = () => {
});
};
calculateLayout();
console.log("after calculation", currentLayouts);
//console.log("after calculation", currentLayouts);

await new Promise((resolve) =>
setTimeout(() => {
calculateLayout();
console.log("after second calculation", currentLayouts);
//console.log("after second calculation", currentLayouts);
resolve(true);
}, 100)
);

setTimeout(() => {
calculateLayout();
console.log("after third calculation", currentLayouts);
//console.log("after third calculation", currentLayouts);
}, 200);

//update layout
Expand Down

0 comments on commit 5cf4cc7

Please sign in to comment.