Merge branch 'feat/rbf-wording' into 'main'
[ProtonMail-WebClient.git] / packages / drive-store / store / _uploads / UploadProvider / UploadProvider.tsx
blob12f7212b20a8092541029f61949a8861245f6775
1 import type { ReactNode } from 'react';
2 import { createContext, useContext } from 'react';
4 import type { UploadProviderState } from './UploadProviderState';
5 import { usePublicUpload, useUpload } from './useUpload';
7 const UploadContext = createContext<UploadProviderState | null>(null);
9 export const UploadProvider = ({ children }: { children: ReactNode }) => {
10     const [providerState, { conflictModal, fileThresholdModal }] = useUpload();
12     return (
13         <UploadContext.Provider value={{ ...providerState }}>
14             {children}
15             {conflictModal}
16             {fileThresholdModal}
17         </UploadContext.Provider>
18     );
21 export const PublicUploadProvider = ({ children }: { children: ReactNode }) => {
22     const [providerState, { conflictModal, fileThresholdModal }] = usePublicUpload();
24     return (
25         <UploadContext.Provider value={{ ...providerState }}>
26             {children}
27             {conflictModal}
28             {fileThresholdModal}
29         </UploadContext.Provider>
30     );
33 export const useUploadProvider = (): UploadProviderState => {
34     const state = useContext(UploadContext);
35     if (!state) {
36         throw new Error('Trying to use uninitialized UploadProvider');
37     }
38     return state;