Skip to content

Commit a6f4bd4

Browse files
logic to wait for editing enabled
1 parent 5f6c18f commit a6f4bd4

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

client/packages/lowcoder/src/pages/editor/AppEditor.tsx

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import Flex from "antd/es/flex";
3434
import React from "react";
3535
import dayjs from "dayjs";
3636
import { currentApplication } from "@lowcoder-ee/redux/selectors/applicationSelector";
37+
import { notificationInstance } from "components/GlobalInstances";
3738

3839
const AppSnapshot = lazy(() => {
3940
return import("pages/editor/appSnapshot")
@@ -115,10 +116,8 @@ const AppEditor = React.memo(() => {
115116
if (currentUser && application) {
116117
const lastEditedAt = dayjs(application?.lastEditedAt);
117118
const lastEditedDiff = dayjs().diff(lastEditedAt, 'minutes');
118-
// const shouldBlockEditing = currentUser.id !== application?.createBy && lastEditedDiff < 5;
119-
const shouldBlockEditing = lastEditedDiff < 5;
119+
const shouldBlockEditing = currentUser.id !== application?.editingUserId && lastEditedDiff < 3;
120120
setBlockEditing(shouldBlockEditing);
121-
console.log('blockEditing', shouldBlockEditing, {user_id: currentUser.id, editingUserId: application.createBy, lastEditedDiff});
122121
}
123122
}, [application, currentUser]);
124123

@@ -189,15 +188,21 @@ const AppEditor = React.memo(() => {
189188
fetchApplication();
190189
}, [fetchApplication]);
191190

192-
// useEffect(() => {
193-
// if(!blockEditing) return clearInterval(fetchInterval.current);
194-
// if(blockEditing) {
195-
// fetchInterval.current = window.setInterval(() => {
196-
// fetchApplication();
197-
// }, 60000);
198-
// }
199-
// return () => clearInterval(fetchInterval.current);
200-
// }, [blockEditing, fetchApplication]);
191+
useEffect(() => {
192+
if(!blockEditing && fetchInterval.current) {
193+
notificationInstance.info({
194+
message: 'Editing Enabled',
195+
description: 'Editing is now enabled. You can proceed with your changes.'
196+
});
197+
return clearInterval(fetchInterval.current);
198+
}
199+
if(blockEditing) {
200+
fetchInterval.current = window.setInterval(() => {
201+
fetchApplication();
202+
}, 60000);
203+
}
204+
return () => clearInterval(fetchInterval.current);
205+
}, [blockEditing, fetchApplication]);
201206

202207
const fallbackUI = useMemo(() => (
203208
<Flex align="center" justify="center" vertical style={{

0 commit comments

Comments
 (0)