FIX: applies correct styles to icon and attempts to dry code (#8739)

This commit is contained in:
Joffrey JAFFEUX 2020-01-17 18:20:23 +01:00 committed by GitHub
parent 56fa77c032
commit 6abc2f5072
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 75 additions and 41 deletions

View File

@ -0,0 +1,7 @@
import Component from "@ember/component";
export default Component.extend({
tagName: null,
link: null,
label: null
});

View File

@ -1,6 +1,5 @@
import discourseComputed from "discourse-common/utils/decorators"; import discourseComputed from "discourse-common/utils/decorators";
import Component from "@ember/component"; import Component from "@ember/component";
import { iconHTML } from "discourse-common/lib/icon-library";
export default Component.extend({ export default Component.extend({
elementId: "related-messages", elementId: "related-messages",
@ -31,14 +30,7 @@ export default Component.extend({
}, },
@discourseComputed("topic") @discourseComputed("topic")
relatedTitle(topic) { relatedTitleLink(topic) {
const href = this.currentUser && this.currentUser.pmPath(topic); return this.currentUser && this.currentUser.pmPath(topic);
return href
? `<a href="${href}" aria-label="${I18n.t(
"user.messages.inbox"
)}">${iconHTML("envelope", {
class: "private-message-glyph"
})}</a><span>${I18n.t("related_messages.title")}</span>`
: I18n.t("related_messages.title");
} }
}); });

View File

@ -2,24 +2,24 @@ import discourseComputed from "discourse-common/utils/decorators";
import { get } from "@ember/object"; import { get } from "@ember/object";
import Component from "@ember/component"; import Component from "@ember/component";
import { categoryBadgeHTML } from "discourse/helpers/category-link"; import { categoryBadgeHTML } from "discourse/helpers/category-link";
import { iconHTML } from "discourse-common/lib/icon-library";
import Site from "discourse/models/site"; import Site from "discourse/models/site";
import { computed } from "@ember/object";
export default Component.extend({ export default Component.extend({
elementId: "suggested-topics", elementId: "suggested-topics",
classNames: ["suggested-topics"], classNames: ["suggested-topics"],
@discourseComputed("topic") suggestedTitleLabel: computed("topic", function() {
suggestedTitle(topic) { if (this.currentUser && this.currentUser.pmPath(this.topic)) {
const href = this.currentUser && this.currentUser.pmPath(topic); return "suggested_topics.pm_title";
return topic.get("isPrivateMessage") && href } else {
? `<a href="${href}" aria-label="${I18n.t( return "suggested_topics.title";
"user.messages.inbox" }
)}>${iconHTML("envelope", { }),
class: "private-message-glyph"
})}</a><span>${I18n.t("suggested_topics.pm_title")}</span>` suggestedTitleLink: computed("topic", function() {
: I18n.t("suggested_topics.title"); return this.currentUser && this.currentUser.pmPath(this.topic);
}, }),
@discourseComputed("topic", "topicTrackingState.messageCount") @discourseComputed("topic", "topicTrackingState.messageCount")
browseMoreMessage(topic) { browseMoreMessage(topic) {

View File

@ -0,0 +1,16 @@
{{#if link}}
<a href={{link}} aria-label={{i18n "user.messages.inbox"}} class="private-message-glyph-wrapper">
{{d-icon "envelope" class="private-message-glyph"}}
</a>
{{#if label}}
<span>{{i18n label}}</span>
{{/if}}
{{else}}
{{#if label}}
<span>{{i18n label}}</span>
{{else}}
<span class="private-message-glyph-wrapper">
{{d-icon "envelope" class="private-message-glyph"}}
</span>
{{/if}}
{{/if}}

View File

@ -1,9 +1,15 @@
<h3 class="suggested-topics-title">{{{relatedTitle}}}</h3> <h3 class="suggested-topics-title">
{{private-message-glyph
link=relatedTitleLink
label="related_messages.title"
}}
</h3>
<div class="topics"> <div class="topics">
{{basic-topic-list {{basic-topic-list
hideCategory="true" hideCategory="true"
showPosters="true" showPosters="true"
topics=topic.relatedMessages}} topics=topic.relatedMessages}}
</div> </div>
{{#if targetUser}} {{#if targetUser}}

View File

@ -1,4 +1,10 @@
<h3 class="suggested-topics-title">{{{suggestedTitle}}}</h3> <h3 class="suggested-topics-title">
{{private-message-glyph
link=suggestedTitleLink
label=suggestedTitleLabel
}}
</h3>
<div class="topics"> <div class="topics">
{{#if topic.isPrivateMessage}} {{#if topic.isPrivateMessage}}
{{basic-topic-list {{basic-topic-list

View File

@ -17,9 +17,7 @@
{{#topic-title cancelled=(action "cancelEditingTopic") save=(action "finishedEditingTopic") model=model}} {{#topic-title cancelled=(action "cancelEditingTopic") save=(action "finishedEditingTopic") model=model}}
{{#if editingTopic}} {{#if editingTopic}}
<div class="edit-topic-title"> <div class="edit-topic-title">
{{#if model.isPrivateMessage}} {{private-message-glyph isVisible=model.isPrivateMessage}}
<span class="private-message-glyph">{{d-icon "envelope"}}</span>
{{/if}}
{{text-field id="edit-title" value=buffered.title maxlength=siteSettings.max_topic_title_length autofocus="true"}} {{text-field id="edit-title" value=buffered.title maxlength=siteSettings.max_topic_title_length autofocus="true"}}
{{#if showCategoryChooser}} {{#if showCategoryChooser}}

View File

@ -69,8 +69,10 @@ export default createWidget("header-topic-info", {
heading.push( heading.push(
h( h(
"a.private-message-glyph-wrapper", "a.private-message-glyph-wrapper",
{ attributes: { href } }, {
h("span.private-message-glyph", iconNode("envelope")) attributes: { href, "aria-label": I18n.t("user.messages.inbox") }
},
iconNode("envelope", { class: "private-message-glyph" })
) )
); );
} }

View File

@ -128,18 +128,27 @@ a.badge-category {
} }
} }
.private-message-glyph {
color: dark-light-choose($primary-low-mid, $secondary-high);
}
.private-message-glyph-wrapper {
float: left;
.private-message-glyph {
margin: 0 5px 0 0;
display: inline-block;
}
}
.private_message { .private_message {
#topic-title { #topic-title {
.private-message-glyph {
display: inline-block;
color: dark-light-choose($primary-low-mid, $secondary-high);
}
.edit-topic-title { .edit-topic-title {
position: relative; position: relative;
.private-message-glyph { .private-message-glyph {
position: absolute; position: absolute;
left: 0.75em; left: 0.75em;
top: 5px; top: 6px;
} }
#edit-title { #edit-title {
width: calc(100% - 50px); width: calc(100% - 50px);

View File

@ -33,9 +33,7 @@
color: $primary; color: $primary;
} }
} }
.private-message-glyph {
display: none;
}
.remove-featured-link { .remove-featured-link {
float: right; float: right;
text-transform: lowercase; text-transform: lowercase;