FEATURE: Shortcut 'g s' goes to first suggested topic

This commit is contained in:
Dan Ungureanu
2019-02-06 23:43:07 +02:00
committed by Sam
parent b88aa4a592
commit fc4c015bee
3 changed files with 300 additions and 216 deletions

View File

@@ -1,6 +1,7 @@
import DiscourseURL from "discourse/lib/url";
import Composer from "discourse/models/composer";
import { minimumOffset } from "discourse/lib/offset-calculator";
import { ajax } from "discourse/lib/ajax";
const bindings = {
"!": { postAction: "showFlags" },
@@ -32,6 +33,7 @@ const bindings = {
"g p": { path: "/my/activity" },
"g m": { path: "/my/messages" },
"g d": { path: "/my/activity/drafts" },
"g s": { handler: "goToFirstSuggestedTopic", anonymous: true },
home: { handler: "goToFirstPost", anonymous: true },
"command+up": { handler: "goToFirstPost", anonymous: true },
j: { handler: "selectDown", anonymous: true },
@@ -133,6 +135,26 @@ export default {
Ember.run.later(() => $(".d-editor .quote").click(), 500);
},
goToFirstSuggestedTopic() {
const $el = $(".suggested-topics a.raw-topic-link:first");
if ($el.length) {
$el.click();
} else {
const controller = this.container.lookup("controller:topic");
// Only the last page contains list of suggested topics.
const url = `/t/${controller.get("model.id")}/last.json`;
ajax(url).then(result => {
if (result.suggested_topics && result.suggested_topics.length > 0) {
const topic = controller.store.createRecord(
"topic",
result.suggested_topics[0]
);
DiscourseURL.routeTo(topic.get("url"));
}
});
}
},
goToFirstPost() {
this._jumpTo("jumpTop");
},