-
Notifications
You must be signed in to change notification settings - Fork 171
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature(editor) Snatching of control support.
- Modified `UpdateProjectServerState` to take a `Partial<ProjectServerState>`. - Renamed `releaseControl` to `clearAllControlFromThisEditor`. - Created `CollaborationStateUpdater` component to manage the visibility changes of the editor. - Added `SnatchProjectControl` and `ReleaseProjectControl` to `CollaborationRequest`. - Renamed `ClaimProjectControlResult` to `RequestProjectControlResult`. - Renamed `ClearAllOfCollaboratorsControlResult` to `ReleaseControlResult`. - Added `snatchControlOverProject` and releaseControlOverProject`. - Renamed `releaseControl` to `clearAllControlFromThisEditor`. - Modified `editorDispatchClosingOut` to use `result.projectServerState` instead of `storedState.projectServerState`. - Modified `editorDispatchInner` to take account of `projectServerState` when determining if anything has changed. - Changed `getProjectServerState` to return a more useful value for test environments and to check if the user owns a project before attempting to claim ownership. - Added `owner_id` column to `project_collaboration`. - Updated some database logic to take account of `owner_id` in `project_collaboration`. - Added `forceClaimCollaborationControl` and `releaseCollaborationControl` to the database handling. - Added `SnatchCollaborationControl` and `ReleaseCollaborationControl` to `ServiceTypes`. - Modified `ClearCollaboratorOwnership` to take the user ID.
- Loading branch information
1 parent
1b1c4d4
commit 9d4be8d
Showing
19 changed files
with
278 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
editor/src/components/editor/store/collaboration-state.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import React from 'react' | ||
import type { EditorDispatch } from '../action-types' | ||
import { releaseControlOverProject, snatchControlOverProject } from './collaborative-editing' | ||
import { Substores, useEditorState } from './store-hook' | ||
import { updateProjectServerState } from '../actions/action-creators' | ||
|
||
interface CollaborationStateUpdaterProps { | ||
projectId: string | null | ||
dispatch: EditorDispatch | ||
} | ||
|
||
export const CollaborationStateUpdater = React.memo( | ||
(props: React.PropsWithChildren<CollaborationStateUpdaterProps>) => { | ||
const { projectId, dispatch, children } = props | ||
const isMyProject = useEditorState( | ||
Substores.projectServerState, | ||
(store) => store.projectServerState.isMyProject, | ||
'CollaborationStateUpdater isMyProject', | ||
) | ||
React.useEffect(() => { | ||
function handleVisibilityChange(): void { | ||
if (projectId != null) { | ||
// If the document is hidden, that means the editor is in the background | ||
// or minimised, so release control. Otherwise if it has become unhidden | ||
// then snatch control of the project. | ||
if (document.hidden) { | ||
void releaseControlOverProject(projectId).then(() => { | ||
dispatch([updateProjectServerState({ currentlyHolderOfTheBaton: false })]) | ||
}) | ||
} else { | ||
// Only attempt to do any kind of snatching of control if the project is "mine". | ||
if (isMyProject === 'yes') { | ||
void snatchControlOverProject(projectId).then((controlResult) => { | ||
dispatch([ | ||
updateProjectServerState({ currentlyHolderOfTheBaton: controlResult ?? false }), | ||
]) | ||
}) | ||
} | ||
} | ||
} | ||
} | ||
document.addEventListener('visibilitychange', handleVisibilityChange) | ||
return () => { | ||
document.removeEventListener('visibilitychange', handleVisibilityChange) | ||
} | ||
}, [dispatch, projectId, isMyProject]) | ||
return <>{children}</> | ||
}, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
ALTER TABLE ONLY "public"."project_collaboration" | ||
ADD COLUMN "owner_id" character varying; |
Oops, something went wrong.