Skip to content

Concurrency user display #1175

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

Merged
merged 10 commits into from
Sep 20, 2024
Prev Previous commit
Next Next commit
logic to wait for editing enabled
  • Loading branch information
raheeliftikhar5 committed Sep 19, 2024
commit a6f4bd43a922852a8410dd2738ae048d6ca72661
29 changes: 17 additions & 12 deletions client/packages/lowcoder/src/pages/editor/AppEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import Flex from "antd/es/flex";
import React from "react";
import dayjs from "dayjs";
import { currentApplication } from "@lowcoder-ee/redux/selectors/applicationSelector";
import { notificationInstance } from "components/GlobalInstances";

const AppSnapshot = lazy(() => {
return import("pages/editor/appSnapshot")
Expand Down Expand Up @@ -115,10 +116,8 @@ const AppEditor = React.memo(() => {
if (currentUser && application) {
const lastEditedAt = dayjs(application?.lastEditedAt);
const lastEditedDiff = dayjs().diff(lastEditedAt, 'minutes');
// const shouldBlockEditing = currentUser.id !== application?.createBy && lastEditedDiff < 5;
const shouldBlockEditing = lastEditedDiff < 5;
const shouldBlockEditing = currentUser.id !== application?.editingUserId && lastEditedDiff < 3;
setBlockEditing(shouldBlockEditing);
console.log('blockEditing', shouldBlockEditing, {user_id: currentUser.id, editingUserId: application.createBy, lastEditedDiff});
}
}, [application, currentUser]);

Expand Down Expand Up @@ -189,15 +188,21 @@ const AppEditor = React.memo(() => {
fetchApplication();
}, [fetchApplication]);

// useEffect(() => {
// if(!blockEditing) return clearInterval(fetchInterval.current);
// if(blockEditing) {
// fetchInterval.current = window.setInterval(() => {
// fetchApplication();
// }, 60000);
// }
// return () => clearInterval(fetchInterval.current);
// }, [blockEditing, fetchApplication]);
useEffect(() => {
if(!blockEditing && fetchInterval.current) {
notificationInstance.info({
message: 'Editing Enabled',
description: 'Editing is now enabled. You can proceed with your changes.'
});
return clearInterval(fetchInterval.current);
}
if(blockEditing) {
fetchInterval.current = window.setInterval(() => {
fetchApplication();
}, 60000);
}
return () => clearInterval(fetchInterval.current);
}, [blockEditing, fetchApplication]);

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