mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-06-02 05:41:33 +02:00
Allow switching reviewing mode for anonymous editors (#26426)
* Revert "Remove reference to track changes ofForGuests" This reverts commit 675f3864e4bf0a07d24848223814768ab50bfd9b. * handle track changes for guests * only send on_for_guests * update test GitOrigin-RevId: 15308f0904b26d2ea6a2e57b3852cd2a9b3c886d
This commit is contained in:
committed by
Copybot
parent
af6b3a7df8
commit
27211c6644
+14
-4
@@ -30,7 +30,8 @@ const useCurrentMode = (): Mode => {
|
||||
const user = useUserContext()
|
||||
const trackChangesForCurrentUser =
|
||||
trackChanges?.onForEveryone ||
|
||||
(user && user.id && trackChanges?.onForMembers[user.id])
|
||||
(user?.id && trackChanges?.onForMembers[user.id]) ||
|
||||
(!user?.id && trackChanges?.onForGuests)
|
||||
const { permissionsLevel } = useEditorContext()
|
||||
|
||||
if (permissionsLevel === 'readOnly') {
|
||||
@@ -46,7 +47,8 @@ const useCurrentMode = (): Mode => {
|
||||
|
||||
function ReviewModeSwitcher() {
|
||||
const { t } = useTranslation()
|
||||
const { saveTrackChangesForCurrentUser } =
|
||||
const user = useUserContext()
|
||||
const { saveTrackChangesForCurrentUser, saveTrackChanges } =
|
||||
useTrackChangesStateActionsContext()
|
||||
const mode = useCurrentMode()
|
||||
const { permissionsLevel } = useEditorContext()
|
||||
@@ -74,7 +76,11 @@ function ReviewModeSwitcher() {
|
||||
previousMode: mode,
|
||||
newMode: 'edit',
|
||||
})
|
||||
saveTrackChangesForCurrentUser(false)
|
||||
if (user?.id) {
|
||||
saveTrackChangesForCurrentUser(false)
|
||||
} else {
|
||||
saveTrackChanges({ on_for_guests: false })
|
||||
}
|
||||
}}
|
||||
description={t('edit_content_directly')}
|
||||
leadingIcon="edit"
|
||||
@@ -96,7 +102,11 @@ function ReviewModeSwitcher() {
|
||||
previousMode: mode,
|
||||
newMode: 'review',
|
||||
})
|
||||
saveTrackChangesForCurrentUser(true)
|
||||
if (user?.id) {
|
||||
saveTrackChangesForCurrentUser(true)
|
||||
} else {
|
||||
saveTrackChanges({ on_for_guests: true })
|
||||
}
|
||||
}
|
||||
}}
|
||||
description={
|
||||
|
||||
+9
-5
@@ -20,6 +20,7 @@ import { usePermissionsContext } from '@/features/ide-react/context/permissions-
|
||||
|
||||
export type TrackChangesState = {
|
||||
onForEveryone: boolean
|
||||
onForGuests: boolean
|
||||
onForMembers: Record<UserId, boolean | undefined>
|
||||
}
|
||||
|
||||
@@ -30,6 +31,7 @@ export const TrackChangesStateContext = createContext<
|
||||
type SaveTrackChangesRequestBody = {
|
||||
on?: boolean
|
||||
on_for?: Record<UserId, boolean | undefined>
|
||||
on_for_guests?: boolean
|
||||
}
|
||||
|
||||
type TrackChangesStateActions = {
|
||||
@@ -60,20 +62,22 @@ export const TrackChangesStateProvider: FC<React.PropsWithChildren> = ({
|
||||
useEffect(() => {
|
||||
setWantTrackChanges(
|
||||
trackChangesValue === true ||
|
||||
(trackChangesValue !== false && !!user.id && trackChangesValue[user.id])
|
||||
(trackChangesValue !== false &&
|
||||
trackChangesValue[user.id ?? '__guests__'])
|
||||
)
|
||||
}, [setWantTrackChanges, trackChangesValue, user.id])
|
||||
|
||||
const trackChangesIsObject =
|
||||
trackChangesValue !== true && trackChangesValue !== false
|
||||
const onForEveryone = trackChangesValue === true
|
||||
const onForGuests =
|
||||
onForEveryone ||
|
||||
(trackChangesIsObject && trackChangesValue.__guests__ === true)
|
||||
|
||||
const onForMembers = useMemo(() => {
|
||||
const onForMembers: Record<UserId, boolean | undefined> = {}
|
||||
if (trackChangesIsObject) {
|
||||
for (const key of Object.keys(trackChangesValue)) {
|
||||
// TODO: Remove this check when we have converted
|
||||
// all projects to the current format.
|
||||
if (key !== '__guests__') {
|
||||
onForMembers[key as UserId] = trackChangesValue[key as UserId]
|
||||
}
|
||||
@@ -141,8 +145,8 @@ export const TrackChangesStateProvider: FC<React.PropsWithChildren> = ({
|
||||
)
|
||||
|
||||
const value = useMemo(
|
||||
() => ({ onForEveryone, onForMembers }),
|
||||
[onForEveryone, onForMembers]
|
||||
() => ({ onForEveryone, onForGuests, onForMembers }),
|
||||
[onForEveryone, onForGuests, onForMembers]
|
||||
)
|
||||
|
||||
return (
|
||||
|
||||
@@ -45,8 +45,6 @@ export type ProjectContextValue = {
|
||||
signUpDate: string
|
||||
}
|
||||
tags: Tag[]
|
||||
// TODO: Remove __guests__ and boolean options when we have converted
|
||||
// all projects to the current format.
|
||||
trackChangesState: boolean | Record<UserId | '__guests__', boolean>
|
||||
projectSnapshot: ProjectSnapshot
|
||||
joinedOnce: boolean
|
||||
|
||||
Reference in New Issue
Block a user