mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-14 14:13:43 +01:00
* feat: changing chat to use cm6 editor instead to allow for mentions display and autocomplete * feat: changing review panel comment, edit, and reply to also use cm6 editor to enable mentions * feat: updating tests, and moving from jsdom to cypress tests as jsdom cant handle cm6 * feat: centralizing mentions component and applying to both chat and review-panel * feat: centralizing mentions input, and using changesUsers in chat mentions * fixing dark mode styles of chat * feat: updating mentions dropdown style and adding custom icon generation for mentions cm6 autocomplete tooltip * feat: making mentions look like links, and fixing border radius on tooltip * fix: naming and using correct color util * feat: fixing hover on highlight * update scroll bar dance in review panel when a system had persistent scroll bars, we would run into issues calculating the height of the review panel Co-authored-by: Kristina <7614497+khjrtbrg@users.noreply.github.com> --------- Co-authored-by: Kristina <7614497+khjrtbrg@users.noreply.github.com> GitOrigin-RevId: 96441ad55f9614427506edfecf3d87bae82d1607
74 lines
1.9 KiB
TypeScript
74 lines
1.9 KiB
TypeScript
import {
|
|
createContext,
|
|
FC,
|
|
useContext,
|
|
useEffect,
|
|
useMemo,
|
|
useState,
|
|
} from 'react'
|
|
import { getJSON } from '@/infrastructure/fetch-json'
|
|
import { useProjectContext } from '@/shared/context/project-context'
|
|
import { UserId } from '@ol-types/user'
|
|
import { useEditorContext } from '@/shared/context/editor-context'
|
|
import { debugConsole } from '@/utils/debugging'
|
|
import { captureException } from '@/infrastructure/error-reporter'
|
|
|
|
export type ChangesUser = {
|
|
id: UserId
|
|
email: string
|
|
first_name?: string
|
|
last_name?: string
|
|
}
|
|
|
|
export type ChangesUsers = Map<UserId, ChangesUser>
|
|
|
|
export const ChangesUsersContext = createContext<ChangesUsers | undefined>(
|
|
undefined
|
|
)
|
|
|
|
export const ChangesUsersProvider: FC<React.PropsWithChildren> = ({
|
|
children,
|
|
}) => {
|
|
const { projectId, project } = useProjectContext()
|
|
const { members, owner } = project || {}
|
|
const { isRestrictedTokenMember } = useEditorContext()
|
|
|
|
const [changesUsers, setChangesUsers] = useState<ChangesUsers>()
|
|
|
|
useEffect(() => {
|
|
if (isRestrictedTokenMember) {
|
|
return
|
|
}
|
|
|
|
getJSON<ChangesUser[]>(`/project/${projectId}/changes/users`)
|
|
.then(data => setChangesUsers(new Map(data.map(item => [item.id, item]))))
|
|
.catch(error => {
|
|
debugConsole.error(error)
|
|
captureException(error)
|
|
})
|
|
}, [projectId, isRestrictedTokenMember])
|
|
|
|
// add the project owner and members to the changes users data
|
|
const value = useMemo(() => {
|
|
if (!owner || !members) {
|
|
return
|
|
}
|
|
const value: ChangesUsers = new Map(changesUsers)
|
|
value.set(owner._id, { ...owner, id: owner._id })
|
|
for (const member of members) {
|
|
value.set(member._id, { ...member, id: member._id })
|
|
}
|
|
return value
|
|
}, [members, owner, changesUsers])
|
|
|
|
return (
|
|
<ChangesUsersContext.Provider value={value}>
|
|
{children}
|
|
</ChangesUsersContext.Provider>
|
|
)
|
|
}
|
|
|
|
export const useChangesUsersContext = () => {
|
|
return useContext(ChangesUsersContext)
|
|
}
|