forked from zulip/zulip-mobile
-
Notifications
You must be signed in to change notification settings - Fork 0
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 a new edit-topic UI
Fixes: zulip#5365
- Loading branch information
Leslie Ngo
authored and
Leslie Ngo
committed
Sep 28, 2022
1 parent
943d68e
commit 2b49955
Showing
12 changed files
with
159 additions
and
192 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,70 @@ | ||
/* @flow strict-local */ | ||
import React, { createContext, useState, useCallback, useContext } from 'react'; | ||
import type { Context, Node } from 'react'; | ||
import { useSelector } from '../react-redux'; | ||
import TopicEditModal from '../topics/TopicEditModal'; | ||
import { getAuth, getZulipFeatureLevel, getStreamsById } from '../selectors'; | ||
import { TranslationContext } from './TranslationProvider'; | ||
|
||
type Props = $ReadOnly<{| | ||
children: Node, | ||
|}>; | ||
|
||
type StartEditTopicContext = ( | ||
streamId: number, | ||
topic: string, | ||
) => Promise<void>; | ||
|
||
// $FlowIssue[incompatible-type] | ||
const TopicModal: Context<StartEditTopicContext> = createContext(undefined); | ||
|
||
export const useStartEditTopic = ():StartEditTopicContext => useContext(TopicModal); | ||
|
||
export default function TopicEditModalProvider(props: Props): Node { | ||
const { children } = props; | ||
const auth = useSelector(getAuth); | ||
const zulipFeatureLevel = useSelector(getZulipFeatureLevel); | ||
const streamsById = useSelector(getStreamsById); | ||
const _ = useContext(TranslationContext); | ||
|
||
const [topicModalProviderState, setTopicModalProviderState] = useState({ | ||
visible: false, | ||
streamId: -1, | ||
topic: '', | ||
}); | ||
|
||
const startEditTopic = useCallback( | ||
async (streamId: number, topic: string) => { | ||
const { visible } = topicModalProviderState; | ||
if (visible) { | ||
return; | ||
} | ||
setTopicModalProviderState({ | ||
visible: true, | ||
streamId, | ||
topic, | ||
}); | ||
}, [topicModalProviderState]); | ||
|
||
const closeEditTopicModal = useCallback(() => { | ||
setTopicModalProviderState({ | ||
visible: false, | ||
streamId: -1, | ||
topic: '', | ||
}); | ||
}, []); | ||
|
||
return ( | ||
<TopicModal.Provider value={startEditTopic}> | ||
<TopicEditModal | ||
topicModalProviderState={topicModalProviderState} | ||
closeEditTopicModal={closeEditTopicModal} | ||
auth={auth} | ||
zulipFeatureLevel={zulipFeatureLevel} | ||
streamsById={streamsById} | ||
_={_} | ||
/> | ||
{children} | ||
</TopicModal.Provider> | ||
); | ||
} |
This file was deleted.
Oops, something went wrong.
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.