This repository has been archived on 2023-03-18. You can view files and clone it, but cannot push or open issues or pull requests.
osr-discourse-src/app/assets/javascripts/discourse/components/suggested-topics.js
Kane York ed95a6005b FEATURE: screenreader landmarks for main, suggested topics
In order to avoid a boatload of attributeBindings, I moved the root
element of the suggested-topics component into the template. Also,
autoformat their hbs files.

Testing info: https://www.scottohara.me/blog/2018/03/03/landmarks.html#using-screen-readers-to-navigate-landmarks

Additionally, flag modals with aria-modal=true to avoid the screenreader
accidentally escaping the modal. There's no need to ever toggle the
attribute to false, because we display:none the modal root when it's
closed.
2020-04-07 15:42:03 -07:00

73 lines
2.0 KiB
JavaScript

import discourseComputed from "discourse-common/utils/decorators";
import { computed, get } from "@ember/object";
import Component from "@ember/component";
import { categoryBadgeHTML } from "discourse/helpers/category-link";
import Site from "discourse/models/site";
export default Component.extend({
tagName: "",
suggestedTitleLabel: computed("topic", function() {
const href = this.currentUser && this.currentUser.pmPath(this.topic);
if (this.topic.get("isPrivateMessage") && href) {
return "suggested_topics.pm_title";
} else {
return "suggested_topics.title";
}
}),
@discourseComputed("topic", "topicTrackingState.messageCount")
browseMoreMessage(topic) {
// TODO decide what to show for pms
if (topic.get("isPrivateMessage")) {
return;
}
const opts = {
latestLink: `<a href="${Discourse.getURL("/latest")}">${I18n.t(
"topic.view_latest_topics"
)}</a>`
};
let category = topic.get("category");
if (
category &&
get(category, "id") === Site.currentProp("uncategorized_category_id")
) {
category = null;
}
if (category) {
opts.catLink = categoryBadgeHTML(category);
} else {
opts.catLink =
'<a href="' +
Discourse.getURL("/categories") +
'">' +
I18n.t("topic.browse_all_categories") +
"</a>";
}
const unreadTopics = this.topicTrackingState.countUnread();
const newTopics = this.currentUser ? this.topicTrackingState.countNew() : 0;
if (newTopics + unreadTopics > 0) {
const hasBoth = unreadTopics > 0 && newTopics > 0;
return I18n.messageFormat("topic.read_more_MF", {
BOTH: hasBoth,
UNREAD: unreadTopics,
NEW: newTopics,
CATEGORY: category ? true : false,
latestLink: opts.latestLink,
catLink: opts.catLink,
basePath: ""
});
} else if (category) {
return I18n.t("topic.read_more_in_category", opts);
} else {
return I18n.t("topic.read_more", opts);
}
}
});