mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FIX: sidebar list destination for tracked and tags (#18639)
Follow up for https://github.com/discourse/discourse/pull/18594 Same solution for tracked and tag links.
This commit is contained in:
parent
8791b6d5ee
commit
799fa8d6f9
@ -48,6 +48,7 @@ export default class SidebarUserTagsSection extends Component {
|
|||||||
new TagSectionLink({
|
new TagSectionLink({
|
||||||
tagName: tag.name,
|
tagName: tag.name,
|
||||||
topicTrackingState: this.topicTrackingState,
|
topicTrackingState: this.topicTrackingState,
|
||||||
|
currentUser: this.currentUser,
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ import I18n from "I18n";
|
|||||||
import { tracked } from "@glimmer/tracking";
|
import { tracked } from "@glimmer/tracking";
|
||||||
import BaseSectionLink from "discourse/lib/sidebar/base-community-section-link";
|
import BaseSectionLink from "discourse/lib/sidebar/base-community-section-link";
|
||||||
import { isTrackedTopic } from "discourse/lib/topic-list-tracked-filter";
|
import { isTrackedTopic } from "discourse/lib/topic-list-tracked-filter";
|
||||||
|
import { UNREAD_LIST_DESTINATION } from "discourse/controllers/preferences/sidebar";
|
||||||
|
|
||||||
export default class TrackedSectionLink extends BaseSectionLink {
|
export default class TrackedSectionLink extends BaseSectionLink {
|
||||||
@tracked totalUnread = 0;
|
@tracked totalUnread = 0;
|
||||||
@ -64,6 +65,14 @@ export default class TrackedSectionLink extends BaseSectionLink {
|
|||||||
}
|
}
|
||||||
|
|
||||||
get route() {
|
get route() {
|
||||||
|
if (this.currentUser?.sidebarListDestination === UNREAD_LIST_DESTINATION) {
|
||||||
|
if (this.totalUnread > 0) {
|
||||||
|
return "discovery.unread";
|
||||||
|
}
|
||||||
|
if (this.totalNew > 0) {
|
||||||
|
return "discovery.new";
|
||||||
|
}
|
||||||
|
}
|
||||||
return "discovery.latest";
|
return "discovery.latest";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,14 +4,16 @@ import { tracked } from "@glimmer/tracking";
|
|||||||
|
|
||||||
import { bind } from "discourse-common/utils/decorators";
|
import { bind } from "discourse-common/utils/decorators";
|
||||||
import BaseTagSectionLink from "discourse/lib/sidebar/user/tags-section/base-tag-section-link";
|
import BaseTagSectionLink from "discourse/lib/sidebar/user/tags-section/base-tag-section-link";
|
||||||
|
import { UNREAD_LIST_DESTINATION } from "discourse/controllers/preferences/sidebar";
|
||||||
|
|
||||||
export default class TagSectionLink extends BaseTagSectionLink {
|
export default class TagSectionLink extends BaseTagSectionLink {
|
||||||
@tracked totalUnread = 0;
|
@tracked totalUnread = 0;
|
||||||
@tracked totalNew = 0;
|
@tracked totalNew = 0;
|
||||||
|
|
||||||
constructor({ topicTrackingState }) {
|
constructor({ topicTrackingState, currentUser }) {
|
||||||
super(...arguments);
|
super(...arguments);
|
||||||
this.topicTrackingState = topicTrackingState;
|
this.topicTrackingState = topicTrackingState;
|
||||||
|
this.currentUser = currentUser;
|
||||||
this.refreshCounts();
|
this.refreshCounts();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -33,6 +35,14 @@ export default class TagSectionLink extends BaseTagSectionLink {
|
|||||||
}
|
}
|
||||||
|
|
||||||
get route() {
|
get route() {
|
||||||
|
if (this.currentUser?.sidebarListDestination === UNREAD_LIST_DESTINATION) {
|
||||||
|
if (this.totalUnread > 0) {
|
||||||
|
return "tag.showUnread";
|
||||||
|
}
|
||||||
|
if (this.totalNew > 0) {
|
||||||
|
return "tag.showNew";
|
||||||
|
}
|
||||||
|
}
|
||||||
return "tag.show";
|
return "tag.show";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -297,6 +297,123 @@ acceptance("Sidebar - Logged on user - Community Section", function (needs) {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("clicking on tracked link - sidebar_list_destination set to unread/new and no unread or new topics", async function (assert) {
|
||||||
|
updateCurrentUser({
|
||||||
|
user_option: {
|
||||||
|
sidebar_list_destination: "unread_new",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
await visit("/t/280");
|
||||||
|
await click(".sidebar-section-community .sidebar-section-link-tracked");
|
||||||
|
assert.strictEqual(
|
||||||
|
currentURL(),
|
||||||
|
"/latest?f=tracked",
|
||||||
|
"it should transition to the latest tracked url"
|
||||||
|
);
|
||||||
|
|
||||||
|
assert.ok(
|
||||||
|
exists(".sidebar-section-community .sidebar-section-link-tracked.active"),
|
||||||
|
"the tracked link is marked as active"
|
||||||
|
);
|
||||||
|
|
||||||
|
assert.strictEqual(
|
||||||
|
count(".sidebar-section-community .sidebar-section-link.active"),
|
||||||
|
1,
|
||||||
|
"only one link is marked as active"
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("clicking on tracked link - sidebar_list_destination set to unread/new with new topics", async function (assert) {
|
||||||
|
const categories = Site.current().categories;
|
||||||
|
const category = categories.find((c) => c.id === 1001);
|
||||||
|
category.set("notification_level", NotificationLevels.TRACKING);
|
||||||
|
|
||||||
|
const topicTrackingState = this.container.lookup(
|
||||||
|
"service:topic-tracking-state"
|
||||||
|
);
|
||||||
|
topicTrackingState.states.set("t112", {
|
||||||
|
last_read_post_number: null,
|
||||||
|
id: 112,
|
||||||
|
notification_level: NotificationLevels.TRACKING,
|
||||||
|
category_id: 1001,
|
||||||
|
created_in_new_period: true,
|
||||||
|
});
|
||||||
|
updateCurrentUser({
|
||||||
|
user_option: {
|
||||||
|
sidebar_list_destination: "unread_new",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
await visit("/t/280");
|
||||||
|
await click(".sidebar-section-community .sidebar-section-link-tracked");
|
||||||
|
|
||||||
|
assert.strictEqual(
|
||||||
|
currentURL(),
|
||||||
|
"/new?f=tracked",
|
||||||
|
"it should transition to the tracked new page"
|
||||||
|
);
|
||||||
|
|
||||||
|
assert.ok(
|
||||||
|
exists(".sidebar-section-community .sidebar-section-link-tracked.active"),
|
||||||
|
"the tracked link is marked as active"
|
||||||
|
);
|
||||||
|
|
||||||
|
assert.strictEqual(
|
||||||
|
count(".sidebar-section-community .sidebar-section-link.active"),
|
||||||
|
1,
|
||||||
|
"only one link is marked as active"
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("clicking on tracked link - sidebar_list_destination set to unread/new with new and unread topics", async function (assert) {
|
||||||
|
const categories = Site.current().categories;
|
||||||
|
const category = categories.find((c) => c.id === 1001);
|
||||||
|
category.set("notification_level", NotificationLevels.TRACKING);
|
||||||
|
|
||||||
|
const topicTrackingState = this.container.lookup(
|
||||||
|
"service:topic-tracking-state"
|
||||||
|
);
|
||||||
|
topicTrackingState.states.set("t112", {
|
||||||
|
last_read_post_number: null,
|
||||||
|
id: 112,
|
||||||
|
notification_level: NotificationLevels.TRACKING,
|
||||||
|
category_id: 1001,
|
||||||
|
created_in_new_period: true,
|
||||||
|
});
|
||||||
|
topicTrackingState.states.set("t113", {
|
||||||
|
last_read_post_number: 1,
|
||||||
|
highest_post_number: 2,
|
||||||
|
id: 113,
|
||||||
|
notification_level: NotificationLevels.TRACKING,
|
||||||
|
category_id: 1001,
|
||||||
|
created_in_new_period: true,
|
||||||
|
});
|
||||||
|
updateCurrentUser({
|
||||||
|
user_option: {
|
||||||
|
sidebar_list_destination: "unread_new",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
await visit("/t/280");
|
||||||
|
await click(".sidebar-section-community .sidebar-section-link-tracked");
|
||||||
|
|
||||||
|
assert.strictEqual(
|
||||||
|
currentURL(),
|
||||||
|
"/unread?f=tracked",
|
||||||
|
"it should transition to the tracked unread page"
|
||||||
|
);
|
||||||
|
|
||||||
|
assert.ok(
|
||||||
|
exists(".sidebar-section-community .sidebar-section-link-tracked.active"),
|
||||||
|
"the tracked link is marked as active"
|
||||||
|
);
|
||||||
|
|
||||||
|
assert.strictEqual(
|
||||||
|
count(".sidebar-section-community .sidebar-section-link.active"),
|
||||||
|
1,
|
||||||
|
"only one link is marked as active"
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
test("clicking on users link", async function (assert) {
|
test("clicking on users link", async function (assert) {
|
||||||
await visit("/t/280");
|
await visit("/t/280");
|
||||||
|
|
||||||
|
@ -12,6 +12,7 @@ import {
|
|||||||
} from "discourse/tests/helpers/qunit-helpers";
|
} from "discourse/tests/helpers/qunit-helpers";
|
||||||
import discoveryFixture from "discourse/tests/fixtures/discovery-fixtures";
|
import discoveryFixture from "discourse/tests/fixtures/discovery-fixtures";
|
||||||
import { cloneJSON } from "discourse-common/lib/object";
|
import { cloneJSON } from "discourse-common/lib/object";
|
||||||
|
import { NotificationLevels } from "discourse/lib/notification-levels";
|
||||||
|
|
||||||
acceptance(
|
acceptance(
|
||||||
"Sidebar - Logged on user - Tags section - tagging disabled",
|
"Sidebar - Logged on user - Tags section - tagging disabled",
|
||||||
@ -235,6 +236,118 @@ acceptance("Sidebar - Logged on user - Tags section", function (needs) {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("clicking tag section links - sidebar_list_destination set to unread/new and no unread or new topics", async function (assert) {
|
||||||
|
updateCurrentUser({
|
||||||
|
user_option: {
|
||||||
|
sidebar_list_destination: "unread_new",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
await visit("/");
|
||||||
|
await click(".sidebar-section-link-tag1");
|
||||||
|
|
||||||
|
assert.strictEqual(
|
||||||
|
currentURL(),
|
||||||
|
"/tag/tag1",
|
||||||
|
"it should transition to tag1's topics discovery page"
|
||||||
|
);
|
||||||
|
|
||||||
|
assert.strictEqual(
|
||||||
|
count(".sidebar-section-tags .sidebar-section-link.active"),
|
||||||
|
1,
|
||||||
|
"only one link is marked as active"
|
||||||
|
);
|
||||||
|
|
||||||
|
assert.ok(
|
||||||
|
exists(`.sidebar-section-link-tag1.active`),
|
||||||
|
"the tag1 section link is marked as active"
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("clicking tag section links - sidebar_list_destination set to unread/new with new topics", async function (assert) {
|
||||||
|
updateCurrentUser({
|
||||||
|
user_option: {
|
||||||
|
sidebar_list_destination: "unread_new",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
this.container.lookup("service:topic-tracking-state").loadStates([
|
||||||
|
{
|
||||||
|
topic_id: 1,
|
||||||
|
highest_post_number: 1,
|
||||||
|
last_read_post_number: null,
|
||||||
|
created_at: "2022-05-11T03:09:31.959Z",
|
||||||
|
category_id: 1,
|
||||||
|
notification_level: null,
|
||||||
|
created_in_new_period: true,
|
||||||
|
treat_as_new_topic_start_date: "2022-05-09T03:17:34.286Z",
|
||||||
|
tags: ["tag1"],
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
|
||||||
|
await visit("/");
|
||||||
|
await click(".sidebar-section-link-tag1");
|
||||||
|
|
||||||
|
assert.strictEqual(
|
||||||
|
currentURL(),
|
||||||
|
"/tag/tag1/l/new",
|
||||||
|
"it should transition to tag1's topics new page"
|
||||||
|
);
|
||||||
|
|
||||||
|
assert.strictEqual(
|
||||||
|
count(".sidebar-section-tags .sidebar-section-link.active"),
|
||||||
|
1,
|
||||||
|
"only one link is marked as active"
|
||||||
|
);
|
||||||
|
|
||||||
|
assert.ok(
|
||||||
|
exists(`.sidebar-section-link-tag1.active`),
|
||||||
|
"the tag1 section link is marked as active"
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("clicking tag section links - sidebar_list_destination set to unread/new with unread topics", async function (assert) {
|
||||||
|
updateCurrentUser({
|
||||||
|
user_option: {
|
||||||
|
sidebar_list_destination: "unread_new",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
this.container.lookup("service:topic-tracking-state").loadStates([
|
||||||
|
{
|
||||||
|
topic_id: 1,
|
||||||
|
highest_post_number: 2,
|
||||||
|
last_read_post_number: 1,
|
||||||
|
created_at: "2022-05-11T03:09:31.959Z",
|
||||||
|
category_id: 1,
|
||||||
|
notification_level: NotificationLevels.TRACKING,
|
||||||
|
created_in_new_period: true,
|
||||||
|
treat_as_new_topic_start_date: "2022-05-09T03:17:34.286Z",
|
||||||
|
tags: ["tag1"],
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
|
||||||
|
await visit("/");
|
||||||
|
await click(".sidebar-section-link-tag1");
|
||||||
|
|
||||||
|
assert.strictEqual(
|
||||||
|
currentURL(),
|
||||||
|
"/tag/tag1/l/unread",
|
||||||
|
"it should transition to tag1's topics unread page"
|
||||||
|
);
|
||||||
|
|
||||||
|
assert.strictEqual(
|
||||||
|
count(".sidebar-section-tags .sidebar-section-link.active"),
|
||||||
|
1,
|
||||||
|
"only one link is marked as active"
|
||||||
|
);
|
||||||
|
|
||||||
|
assert.ok(
|
||||||
|
exists(`.sidebar-section-link-tag1.active`),
|
||||||
|
"the tag1 section link is marked as active"
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
test("private message tag section links for user", async function (assert) {
|
test("private message tag section links for user", async function (assert) {
|
||||||
await visit("/");
|
await visit("/");
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user