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

FEATURE: user status emoji #17025

Merged
merged 18 commits into from Jun 22, 2022
Merged

FEATURE: user status emoji #17025

merged 18 commits into from Jun 22, 2022

Conversation

AndrewPrigorshnev
Copy link
Contributor

This PR adds emoji to User Status:

Screenshot 2022-06-07 at 20 42 48

Screenshot 2022-06-07 at 14 17 45


@computed("emoji")
get emojiHtml() {
const emoji = escapeExpression(`:${this.emoji}:`);
Copy link
Contributor

Choose a reason for hiding this comment

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

what if emoji becomes null?

Copy link
Contributor

Choose a reason for hiding this comment

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

I understand there's the default, but this is a function call, what if something else makes it null without calling the default function?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not strongly against handling possible null value here, but I'm not sure that we should be that protective.

We do not support user statuses without emojis, an attempt to send a status without emoji to the server will lead to a server error and now emojiHtml() gets called only when emoji is already set:

{{#if @emoji}}
   {{html-safe this.emojiHtml}}
{{else}}

Yes, something else can set emoji to null, but the answer to the question What will happen then? is Tests will fail. And after seeing that failure, we'll need to prevent that thing from setting emoji to null.

We can add some protection and start returning an empty string from emojiHtml(). The modal will look like this then:

Screenshot 2022-06-09 at 21 55 51

But in that case, tests will still fail and show us that we have a problem, so probably it doesn't worth adding additional code.

What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm, with this actually even tests won't fail:

{{#if @emoji}}
   {{html-safe this.emojiHtml}}
{{else}}

this.set("emojiPickerIsActive", false);

scheduleOnce("afterRender", () => {
document.querySelector(".btn-emoji").focus();
Copy link
Contributor

Choose a reason for hiding this comment

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

It's usually safer to do document.querySelector(".btn-emoji")?.focus();

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've made it safer as you suggested, but now have some doubts. Like with the previous comment, not sure if we have to be so protective.

The component is designed in a way that it always have an emoji button. Let's say we set focus without ?:

document.querySelector(".btn-emoji").focus()

If somebody removes btn-emoji from the component, tests will fail, they will see that and remove the code for setting focus.

But if we set focus with ? and somebody removes btn-emoji, tests will be green. Chances are that the code for setting focus will remain in the code base doing nothing.

In a way, by handling a possible null value in the code we're saying "the null value can appear here, if it happens that's fine". But that isn't the case here. If .btn-emoji was removed, this code should be removed as well. An explicit exception may be better than silent swallowing of the problem.

But again, not strongly against adding ? (I've already added it). Curious, what do you think?


// Button with cleared default styles
// --------------------------------------------------
.btn-unstyled {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm kinda mixed on this. What's your opinion @jordanvidrine ?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think using btn-flat would probably get the styling you want, without needing to make a new style that strips away things as it currently is.

If that doesnt work, this current class and styling is probably fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you, Jordan! btn-flat does the job, also with this style the button looks better in focused state. In Chrome, btn-unstyled:

Screenshot 2022-06-16 at 18 00 14

btn-flat:

Screenshot 2022-06-16 at 17 59 38

Copy link
Contributor

@pmusaraj pmusaraj left a comment

Choose a reason for hiding this comment

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

Looking generally good. One thing I noticed as I pulled this locally is that we need some more events that clear the emoji modal. For example, from this screen:

image

I should be able to dismiss the emoji picker window if I

  • click in the "What are you doing?" input
  • click somewhere else in the modal content
  • press Esc (currently this dismisses the whole modal; this is a little tricky, can be a todo for a future PR)


class DisallowNullEmojiOnUserStatus < ActiveRecord::Migration[7.0]
def up
execute "UPDATE user_statuses SET emoji = 'mega'"
Copy link
Contributor

Choose a reason for hiding this comment

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

📣 the megaphone feels like a very loud choice for a default emoji. Maybe 💬 (speech_balloon) is a better default? Or 🗨️ (left_speech_bubble).

{{#if @emoji}}
{{html-safe this.emojiHtml}}
{{else}}
{{d-icon "discourse-emojis"}}
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should use the default icon right away here, instead of discourse-emojis, especially if using an emoji is not optional.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I deliberately build in this behavior, put some time and efforts into it. May we merge it in and try it for a while first? We can always get rid of it in case we don't like it.

@AndrewPrigorshnev
Copy link
Contributor Author

AndrewPrigorshnev commented Jun 21, 2022

I should be able to dismiss the emoji picker window if I

  • click in the "What are you doing?" input
  • click somewhere else in the modal content
  • press Esc (currently this dismisses the whole modal; this is a little tricky, can be a todo for a future PR)

I've added handling of clicks outside of emoji picker. Also, after adding it, dismissing of the emoji picker by Esc key started working too. After dismissing by Esc focus behave a little weird, but I'd better prefer to fix it in separate PR since it can be nontrivial.

@pmusaraj
Copy link
Contributor

After dismissing by Esc focus behave a little weird, but I'd better prefer to fix it in separate PR since it can be nontrivial.

Sure that's fine.

Any thoughts on the default emoji icon? Since it's in the migration, it would be good to establish a good default before merging.

@AndrewPrigorshnev
Copy link
Contributor Author

Any thoughts on the default emoji icon? Since it's in the migration, it would be good to establish a good default before merging.

I agree that 📣 is too loud, we also double-checked internally that we want to use 💬 instead. So I pushed the change. May I have an approval? At this moment this PR starts blocking my next work.

@AndrewPrigorshnev AndrewPrigorshnev merged commit 033f72c into main Jun 22, 2022
@AndrewPrigorshnev AndrewPrigorshnev deleted the feature/user-status-emoji branch June 22, 2022 14:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
4 participants