diff --git a/services/web/frontend/js/shared/context/editor-context.tsx b/services/web/frontend/js/shared/context/editor-context.tsx index 0508eaffe1..d514db29d3 100644 --- a/services/web/frontend/js/shared/context/editor-context.tsx +++ b/services/web/frontend/js/shared/context/editor-context.tsx @@ -19,6 +19,7 @@ import { useUserContext } from './user-context' import { saveProjectSettings } from '@/features/editor-left-menu/utils/api' import { PermissionsLevel } from '@/features/ide-react/types/permissions' import { useModalsContext } from '@/features/ide-react/context/modals-context' +import { WritefullAPI } from './types/writefull-instance' export const EditorContext = createContext< | { @@ -54,6 +55,8 @@ export const EditorContext = createContext< setHasPremiumSuggestion: (value: boolean) => void setPremiumSuggestionResetDate: (date: Date) => void premiumSuggestionResetDate: Date + writefullInstance: WritefullAPI | null + setWritefullInstance: (instance: WritefullAPI) => void } | undefined >(undefined) @@ -182,6 +185,9 @@ export const EditorProvider: FC = ({ children }) => { ) }, []) + const [writefullInstance, setWritefullInstance] = + useState(null) + const value = useMemo( () => ({ cobranding, @@ -206,6 +212,8 @@ export const EditorProvider: FC = ({ children }) => { setPremiumSuggestionResetDate, assistantUpgraded, setAssistantUpgraded, + writefullInstance, + setWritefullInstance, }), [ cobranding, @@ -231,6 +239,8 @@ export const EditorProvider: FC = ({ children }) => { setPremiumSuggestionResetDate, assistantUpgraded, setAssistantUpgraded, + writefullInstance, + setWritefullInstance, ] ) diff --git a/services/web/frontend/js/shared/context/types/writefull-instance.ts b/services/web/frontend/js/shared/context/types/writefull-instance.ts new file mode 100644 index 0000000000..7dab3e0913 --- /dev/null +++ b/services/web/frontend/js/shared/context/types/writefull-instance.ts @@ -0,0 +1,21 @@ +export interface WritefullEvents { + 'writefull-login-complete': { + method: 'email-password' | 'login-with-overleaf' + } + 'writefull-received-suggestions': { numberOfSuggestions: number } + 'writefull-register-as-auto-account': { email: string } +} + +export interface WritefullAPI { + init({ + hasAgreedToTOS, + overleafUserId, + }: { + hasAgreedToTOS: boolean + overleafUserId: string + }): Promise + addEventListener( + name: eventName, + callback: (detail: WritefullEvents[eventName]) => void + ): void +}