-
-
Notifications
You must be signed in to change notification settings - Fork 655
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
topic edit modal: Add new edit-topic UI.
Fixes: #5365
- Loading branch information
Leslie Ngo
authored and
Leslie Ngo
committed
Nov 4, 2022
1 parent
cf5e387
commit d47943e
Showing
13 changed files
with
301 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* @flow strict-local */ | ||
import React, { createContext, useState, useCallback, useContext } from 'react'; | ||
import type { Context, Node } from 'react'; | ||
|
||
import TopicEditModal from '../topics/TopicEditModal'; | ||
|
||
type Props = $ReadOnly<{| | ||
children: Node, | ||
|}>; | ||
|
||
type TopicEditModalProviderState = { | ||
streamId: number, | ||
oldTopic: string, | ||
} | null; | ||
|
||
type StartEditTopicContext = (streamId: number, oldTopic: string) => void; | ||
|
||
const TopicEditModalContext: Context<StartEditTopicContext> = createContext(() => { | ||
throw new Error( | ||
'Tried to open the edit-topic UI from a component without TopicEditModalProvider above it in the tree.', | ||
); | ||
}); | ||
|
||
export const useStartEditTopic = (): StartEditTopicContext => useContext(TopicEditModalContext); | ||
|
||
export default function TopicEditModalProvider(props: Props): Node { | ||
const { children } = props; | ||
|
||
const [topicModalProviderState, setTopicModalProviderState] = | ||
useState<TopicEditModalProviderState>(null); | ||
|
||
const startEditTopic = useCallback( | ||
(streamIdArg, oldTopicArg) => { | ||
if (!topicModalProviderState) { | ||
setTopicModalProviderState({ | ||
streamId: streamIdArg, | ||
oldTopic: oldTopicArg, | ||
}); | ||
} | ||
}, | ||
[topicModalProviderState], | ||
); | ||
|
||
const closeEditTopicModal = () => { | ||
setTopicModalProviderState(null); | ||
}; | ||
|
||
return ( | ||
<TopicEditModalContext.Provider value={startEditTopic}> | ||
<TopicEditModal | ||
topicModalProviderState={topicModalProviderState} | ||
closeEditTopicModal={closeEditTopicModal} | ||
/> | ||
{children} | ||
</TopicEditModalContext.Provider> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.