From 36b15c888d654f0ce009f5d743023a0200fc1a23 Mon Sep 17 00:00:00 2001 From: Jimmy Domagala-Tang Date: Mon, 24 Mar 2025 12:39:10 -0400 Subject: [PATCH] Merge pull request #24253 from overleaf/jdt-move-wf-instance-to-context MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit moving WF to editor context in anticipation for calling functionality… GitOrigin-RevId: 368554e9308fe8e9e7ef42a4abd78690ec834520 --- .../js/shared/context/editor-context.tsx | 10 +++++++++ .../context/types/writefull-instance.ts | 21 +++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 services/web/frontend/js/shared/context/types/writefull-instance.ts 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 +}