Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Topic edit modal #5505

Closed
wants to merge 3 commits into from
Closed

Topic edit modal #5505

wants to merge 3 commits into from

Conversation

dootMaster
Copy link

@dootMaster dootMaster commented Sep 25, 2022

This draft PR is ready for review. What should a unit test for this feature entail?

@dootMaster
Copy link
Author

Screen.Recording.2022-09-24.at.6.50.03.PM.mov

@dootMaster
Copy link
Author

@chrisbobbe 👋

@dootMaster
Copy link
Author

I think we also want the Edit Topic button to only appear for admins for now. I can borrow this:

  if (roleIsAtLeast(ownUserRole, Role.Admin)) {
    buttons.push(deleteTopic);
  }

@dootMaster dootMaster force-pushed the topicEditModal branch 2 times, most recently from 3b81cb0 to ec60c8d Compare September 25, 2022 20:24
@dootMaster dootMaster marked this pull request as ready for review September 25, 2022 20:52
@dootMaster dootMaster marked this pull request as draft September 25, 2022 20:53
@chrisbobbe
Copy link
Contributor

chrisbobbe commented Sep 28, 2022

I think we also want the Edit Topic button to only appear for admins for now. I can borrow this:

  if (roleIsAtLeast(ownUserRole, Role.Admin)) {
    buttons.push(deleteTopic);
  }

That sounds right; please do borrow that! 🙂 Since it won't be obvious to everyone reading that code, please include a code comment saying why we're only showing it to admins-and-above, linking to discussion if any.

Copy link
Contributor

@chrisbobbe chrisbobbe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @dootMaster! See comments below.

For the branch structure, I think it makes sense to have one NFC commit that converts SearchMessagesCard to a function component, followed by one non-NFC commit whose "single idea" is something like "add a new edit-topic UI" and contains all the work that accomplishes that. The added code is pretty coherent and is all meant to work together, so I think it's easier to see how it all works together when it's added in the same commit. Also please remember that all commits should pass all tests, and feel free to ask in #git help if you have questions on fixing/tidying commits. 🙂

src/ZulipMobile.js Outdated Show resolved Hide resolved
});

const startEditTopic = useCallback(
async (streamId, topic, streamsById, _) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's just ask the caller for streamId and topic. Those are the interesting things that make this edit-topic session different from another one: "Which topic do we want to edit? This topic, in this stream."

streamsById and _ are useful bits of background data that we end up consulting, but they're not special knowledge about the requested UI interaction that the caller has to provide. We can get them by calling useSelector and useContext, respectively, above this in TopicModalProvider. That way, this component will rerender when we have something new for those, which is helpful for avoiding bugs like (with _) showing text with the UI language setting at the time the modal was opened, which might be different from the current language setting.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, let's have startEditTopic bail out (return) early if there's already an edit-topic interaction in progress, so we don't have two interactions stepping on each other and corrupting each other's state.

src/boot/TopicModalProvider.js Outdated Show resolved Hide resolved
src/topics/TopicEditModal.js Outdated Show resolved Hide resolved
src/topics/TopicEditModal.js Outdated Show resolved Hide resolved
Comment on lines +52 to +113
const styles = createStyleSheet({
wrapper: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
},
modalView: {
margin: 10,
alignItems: 'center',
backgroundColor,
padding: 20,
borderStyle: 'solid',
borderWidth: 1,
borderColor: 'gray',
borderRadius: 20,
width: '90%',
},
buttonContainer: {
display: 'flex',
flexDirection: 'row',
justifyContent: 'space-between',
width: '60%',
},
input: {
width: '90%',
borderWidth: 1,
borderRadius: 5,
marginBottom: 16,
...inputMarginPadding,
backgroundColor: 'white',
borderStyle: 'solid',
borderColor: 'black',
},
button: {
position: 'relative',
justifyContent: 'center',
alignItems: 'center',
borderRadius: 32,
padding: 8,
},
titleText: {
fontSize: 18,
lineHeight: 21,
fontWeight: 'bold',
color: BRAND_COLOR,
marginBottom: 12,
},
text: {
fontSize: 14,
lineHeight: 21,
fontWeight: 'bold',
},
submitButtonText: {
color: 'white',
},
cancelButtonText: {
color: BRAND_COLOR,
},
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a lot of style attributes! 🙂

I think we can probably improve the appearance of the modal, and also need fewer of these ad-hoc style attributes, by using our components ZulipTextButton and Input for the buttons and text input.

These are meant to be reusable and to give a consistent look-and-feel to the app, with an eye on Material Design. The Material Design page on dialogs looks like a good resource that might be helpful in deciding how we want this modal to look.

src/topics/TopicEditModal.js Outdated Show resolved Hide resolved
src/topics/TopicEditModal.js Outdated Show resolved Hide resolved
src/boot/TopicModalProvider.js Outdated Show resolved Hide resolved
src/topics/TopicEditModal.js Outdated Show resolved Hide resolved
@dootMaster
Copy link
Author

dootMaster commented Sep 28, 2022

@chrisbobbe Thanks for reviewing!

How is this check achieved?

Also, let's have startEditTopic bail out (return) early if there's already an edit-topic interaction in progress, so we don't have two interactions stepping on each other and corrupting each other's state.

I've modified it to check visible from the provider's state. Is there a better way to do this?

  const startEditTopic = useCallback(
    async (streamId: number, topic: string) => {
      const { visible } = topicModalProviderState;
      if (visible) {
        return;
      }
      setTopicModalProviderState({
        visible: true,
        streamId,
        topic,
      });
    }, [topicModalProviderState]);
    ```

chrisbobbe and others added 3 commits September 28, 2022 16:28
We'll use this for zulip#5306; see the plan in discussion:
  https://chat.zulip.org/#narrow/stream/243-mobile-team/topic/.23M5306.20Follow.20.2Fnear.2F.20links.20through.20topic.20moves.2Frenames/near/1407930

In particular, we want the stream and topic for a stream message
that might not be in our data structures. We'll use this endpoint to
fetch that information.

topic edit modal [nfc]: Add TopicModalProvider context component.

Contains visibility context and handler callback context.
Sets up context for modal handler to be called inside topic action sheets.

topic edit modal [nfc]: Provide topic modal Context hook to children.

The useTopicModalHandler is called normally in TopicItem and TitleStream.
In order to deliver the callbacks to the action sheets in MessageList, the context hook
is called in ChatScreen and a bit of prop-drilling is performed.

topic edit modal: Add translation for action sheet button.

topic edit modal: Add modal and functionality to perform topic name updates.

Fixes zulip#5365

topid edit modal [nfc]: Revise Flow types for relevant components.

topic edit modal: Modify webview unit tests to accommodate feature update.
@chrisbobbe
Copy link
Contributor

(For the record, the next revision of this PR went to #5510.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants