ff7de70a61
Build and Deploy Verso / deploy (push) Successful in 21m44s
Two bugs: 1. Converting when output already exists threw DuplicateNameError (400). Now overwrites existing doc via setDocument instead of failing. 2. Right-clicking an unselected file left contextMenuEntityId null, so the first click on Convert silently did nothing. Added contextMenuEntityId to FileTreeMainContext, set it on right-click and on the … button click; FileTreeItemMenuItems now uses it for the convert hooks rather than relying on selectedEntityIds. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
64 lines
1.6 KiB
TypeScript
64 lines
1.6 KiB
TypeScript
import { createContext, FC, useContext, useState } from 'react'
|
|
|
|
type ContextMenuCoords = { top: number; left: number }
|
|
|
|
const FileTreeMainContext = createContext<
|
|
| {
|
|
refProviders: object
|
|
setRefProviderEnabled: (provider: string, value: boolean) => void
|
|
setStartedFreeTrial: (value: boolean) => void
|
|
contextMenuCoords: ContextMenuCoords | null
|
|
setContextMenuCoords: (value: ContextMenuCoords | null) => void
|
|
contextMenuEntityId: string | null
|
|
setContextMenuEntityId: (value: string | null) => void
|
|
}
|
|
| undefined
|
|
>(undefined)
|
|
|
|
export function useFileTreeMainContext() {
|
|
const context = useContext(FileTreeMainContext)
|
|
|
|
if (!context) {
|
|
throw new Error(
|
|
'useFileTreeMainContext is only available inside FileTreeMainProvider'
|
|
)
|
|
}
|
|
|
|
return context
|
|
}
|
|
|
|
export const FileTreeMainProvider: FC<
|
|
React.PropsWithChildren<{
|
|
refProviders: object
|
|
setRefProviderEnabled: (provider: string, value: boolean) => void
|
|
setStartedFreeTrial: (value: boolean) => void
|
|
}>
|
|
> = ({
|
|
refProviders,
|
|
setRefProviderEnabled,
|
|
setStartedFreeTrial,
|
|
children,
|
|
}) => {
|
|
const [contextMenuCoords, setContextMenuCoords] =
|
|
useState<ContextMenuCoords | null>(null)
|
|
const [contextMenuEntityId, setContextMenuEntityId] = useState<string | null>(
|
|
null
|
|
)
|
|
|
|
return (
|
|
<FileTreeMainContext.Provider
|
|
value={{
|
|
refProviders,
|
|
setRefProviderEnabled,
|
|
setStartedFreeTrial,
|
|
contextMenuCoords,
|
|
setContextMenuCoords,
|
|
contextMenuEntityId,
|
|
setContextMenuEntityId,
|
|
}}
|
|
>
|
|
{children}
|
|
</FileTreeMainContext.Provider>
|
|
)
|
|
}
|