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

Fixes duplicated title in header after edit #4760

Merged
merged 1 commit into from Mar 16, 2017

Conversation

nbianca
Copy link
Member

@nbianca nbianca commented Mar 16, 2017

Fixes the issue described here.

@mention-bot
Copy link

Thanks @nbianca for your pull request 👍. By analyzing the blame information on this pull request, I identified @eviltrout and @ZogStriP to be potential reviewers.

@discoursebot
Copy link

You've signed the CLA, nbianca. Thank you! This pull request is ready for review.

@SamSaffron
Copy link
Member

@nbianca really appreciate this, but I feel the fix is not in the right spot.

I think it should always be safe to trigger the header:show-topic event it should be responsible for ensuring that it is in the correct mode prior to rendering. This logic of deciding if we should render the topic header would be in 2 places, duplicated with this change.

@eviltrout what do you thing?

@nbianca
Copy link
Member Author

nbianca commented Mar 16, 2017

@SamSaffron By saying that it should be always safe to trigger header:show-topic what exactly do you suggest?

  1. that header:show-topic and header:hide-topic should be combined into something like header:update-topic that would show or hide the topic accordingly;
  2. or just that header:show-topic should check if the topic title should be really shown or else do nothing?

@SamSaffron
Copy link
Member

I see,

My recommendation would be maybe to add an extra event called "header:update" that can be used whenever anyone feels like updating the header, then the logic can be centralized

@eviltrout
Copy link
Contributor

header:update-topic is probably a better name for the event. I think it should handle the logic of choosing to display the header depending on the scrollTop.

@SamSaffron
Copy link
Member

@nbianca keep in mind the logic is a bit more subtle than your test was.

See: components/discourse-topic.js

What I would like is for all the logic to be centralized there, discourse-topic already knows how to make the call here so it should be the one handling this new event.

@@ -117,16 +135,11 @@ export default Ember.Component.extend(AddArchetypeClass, Scrolling, {

this.set('hasScrolled', offset > 0);

// Trigger a header (topic title) update, but only if it is requried.
const topic = this.get('topic');
const showTopic = this.showTopicInHeader(topic, offset);
if (showTopic !== this._lastShowTopic) {
Copy link
Member Author

@nbianca nbianca Mar 16, 2017

Choose a reason for hiding this comment

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

I did this to avoid unnecessary rendering and event triggers.

}

const offset = window.pageYOffset || $('html').scrollTop();
this._lastShowTopic = this.showTopicInHeader(topic, offset);
Copy link
Member Author

Choose a reason for hiding this comment

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

Basically this forces an update.

Copy link
Member Author

Choose a reason for hiding this comment

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

I also do not that think that offset should be a parameter and it would be better if it were moved inside showTopicInHeader.

Copy link
Member

Choose a reason for hiding this comment

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

agree we can further refine this, but I think this fix for now is good

this.appEvents.trigger('header:show-topic', topic);
} else {
this.appEvents.trigger('header:hide-topic');
}
Copy link
Member

Choose a reason for hiding this comment

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

I think some of the duplication here is fine, cause otherwise you have to call showTopicInHeader twice, for no great gain

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

@SamSaffron SamSaffron merged commit 2c952e1 into discourse:master Mar 16, 2017
@SamSaffron
Copy link
Member

Thanks for the fix @nbianca !

@nbianca nbianca deleted the fix_topic_title branch August 18, 2017 17:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
5 participants