-
Notifications
You must be signed in to change notification settings - Fork 374
Expand file tree
/
Copy pathcreatePollContentContext.tsx
More file actions
54 lines (44 loc) · 1.72 KB
/
createPollContentContext.tsx
File metadata and controls
54 lines (44 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import React, { PropsWithChildren, useContext } from 'react';
import { StateStore } from 'stream-chat';
import { MessageInputContextValue } from '../messageInputContext/MessageInputContext';
import { DEFAULT_BASE_CONTEXT_VALUE } from '../utils/defaultBaseContextValue';
import { isTestEnvironment } from '../utils/isTestEnvironment';
export type CreatePollModalState = {
isClosing: boolean;
};
export type CreatePollContentContextValue = {
createAndSendPoll: () => Promise<void>;
sendMessage: MessageInputContextValue['sendMessage'];
closePollCreationDialog?: () => void;
modalStateStore?: StateStore<CreatePollModalState>;
/**
* Vertical gap between poll options in the poll creation screen.
*
* **Default: ** 8
*/
createPollOptionGap?: number;
};
export const CreatePollContentContext = React.createContext(
DEFAULT_BASE_CONTEXT_VALUE as CreatePollContentContextValue,
);
export const CreatePollContentProvider = ({
children,
value,
}: PropsWithChildren<{
value: CreatePollContentContextValue;
}>) => (
<CreatePollContentContext.Provider value={value as unknown as CreatePollContentContextValue}>
{children}
</CreatePollContentContext.Provider>
);
export const useCreatePollContentContext = () => {
const contextValue = useContext(
CreatePollContentContext,
) as unknown as CreatePollContentContextValue;
if (contextValue === DEFAULT_BASE_CONTEXT_VALUE && !isTestEnvironment()) {
throw new Error(
'The useCreatePollContentContext hook was called outside of the CreatePollContentContext provider. Make sure you have configured the CreatePollContent component correctly - https://getstream.io/chat/docs/sdk/reactnative/basics/hello_stream_chat/#channel',
);
}
return contextValue;
};