Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3375276
D7794.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
3 KB
Referenced Files
None
Subscribers
None
D7794.diff
View Options
diff --git a/web/app.react.js b/web/app.react.js
--- a/web/app.react.js
+++ b/web/app.react.js
@@ -31,6 +31,7 @@
import Calendar from './calendar/calendar.react.js';
import Chat from './chat/chat.react.js';
+import { EditModalProvider } from './chat/edit-message-provider.js';
import { TooltipProvider } from './chat/tooltip-provider.js';
import NavigationArrows from './components/navigation-arrows.react.js';
import { initOpaque } from './crypto/opaque-utils.js';
@@ -158,21 +159,23 @@
}
return (
<DndProvider backend={HTML5Backend}>
- <TooltipProvider>
- <MenuProvider>
- <WagmiConfig client={wagmiClient}>
- <WagmiENSCacheProvider>
- <FocusHandler />
- <VisibilityHandler />
- <DeviceIDUpdater />
- <PolicyAcknowledgmentHandler />
- <PushNotificationsHandler />
- {content}
- {this.props.modals}
- </WagmiENSCacheProvider>
- </WagmiConfig>
- </MenuProvider>
- </TooltipProvider>
+ <EditModalProvider>
+ <TooltipProvider>
+ <MenuProvider>
+ <WagmiConfig client={wagmiClient}>
+ <WagmiENSCacheProvider>
+ <FocusHandler />
+ <VisibilityHandler />
+ <DeviceIDUpdater />
+ <PolicyAcknowledgmentHandler />
+ <PushNotificationsHandler />
+ {content}
+ {this.props.modals}
+ </WagmiENSCacheProvider>
+ </WagmiConfig>
+ </MenuProvider>
+ </TooltipProvider>
+ </EditModalProvider>
</DndProvider>
);
}
diff --git a/web/chat/edit-message-provider.js b/web/chat/edit-message-provider.js
new file mode 100644
--- /dev/null
+++ b/web/chat/edit-message-provider.js
@@ -0,0 +1,81 @@
+// @flow
+
+import invariant from 'invariant';
+import * as React from 'react';
+
+import ModalOverlay from 'lib/components/modal-overlay.react.js';
+import type { ChatMessageInfoItem } from 'lib/selectors/chat-selectors.js';
+import type { ThreadInfo } from 'lib/types/thread-types';
+
+export type EditState = {
+ +messageInfo: ChatMessageInfoItem,
+ +threadInfo: ThreadInfo,
+ +editedMessageDraft: ?string,
+ +isError: boolean,
+};
+
+type EditModalContextType = {
+ +renderEditModal: (params: EditState) => void,
+ +clearEditModal: () => void,
+ +editState: ?EditState,
+};
+
+const EditModalContext: React.Context<EditModalContextType> =
+ React.createContext<EditModalContextType>({
+ renderEditModal: () => {},
+ clearEditModal: () => {},
+ editState: null,
+ });
+
+type Props = {
+ +children: React.Node,
+};
+function EditModalProvider(props: Props): React.Node {
+ const { children } = props;
+
+ const [editState, setEditState] = React.useState<?EditState>(null);
+
+ const clearEditModal = React.useCallback(() => {
+ setEditState(null);
+ }, []);
+
+ const renderEditModal = React.useCallback((newEditState: EditState): void => {
+ setEditState(newEditState);
+ }, []);
+
+ const modal = React.useMemo(() => {
+ // TODO: Add modal
+ return null;
+ }, []);
+
+ const value = React.useMemo(
+ () => ({
+ renderEditModal,
+ clearEditModal: clearEditModal,
+ editState,
+ }),
+ [renderEditModal, clearEditModal, editState],
+ );
+
+ const modalOverlay = React.useMemo(() => {
+ if (!modal) {
+ return null;
+ }
+ return <ModalOverlay onClose={clearEditModal}>{modal}</ModalOverlay>;
+ }, [clearEditModal, modal]);
+
+ return (
+ <EditModalContext.Provider value={value}>
+ {children}
+ {modalOverlay}
+ </EditModalContext.Provider>
+ );
+}
+
+function useEditModalContext(): EditModalContextType {
+ const context = React.useContext(EditModalContext);
+ invariant(context, 'EditModalContext not found');
+ return context;
+}
+
+export { EditModalProvider, useEditModalContext };
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Wed, Nov 27, 7:26 PM (20 h, 34 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2591443
Default Alt Text
D7794.diff (3 KB)
Attached To
Mode
D7794: [web] Add new edit message provider
Attached
Detach File
Event Timeline
Log In to Comment