FEATURE: Show topic visited state on search page (#15994)

The visited state used user's history instead of the data from the
server.
This commit is contained in:
Bianca Nenciu 2022-02-23 21:24:26 +02:00 committed by GitHub
parent 9c1ab97c01
commit 82a9109ae3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 21 additions and 5 deletions

View File

@ -10,7 +10,7 @@
{{track-selected selectedList=selected selectedId=post.topic class="bulk-select"}} {{track-selected selectedList=selected selectedId=post.topic class="bulk-select"}}
{{/if}} {{/if}}
<a href={{post.url}} {{action "logClick" post.topic_id}} class="search-link" role="heading" aria-level="2"> <a href={{post.url}} {{action "logClick" post.topic_id}} class="search-link{{if post.topic.visited " visited"}}" role="heading" aria-level="2">
{{raw "topic-status" topic=post.topic showPrivateMessageIcon=true}} {{raw "topic-status" topic=post.topic showPrivateMessageIcon=true}}
<span class="topic-title"> <span class="topic-title">
{{#if post.useTopicTitleHeadline}} {{#if post.useTopicTitleHeadline}}

View File

@ -558,4 +558,16 @@ acceptance("Search - Full Page", function (needs) {
await click(".topic-bulk-actions-modal .btn:nth-child(2)"); // close topics await click(".topic-bulk-actions-modal .btn:nth-child(2)"); // close topics
assert.equal(lastBody["topic_ids[]"], 7); assert.equal(lastBody["topic_ids[]"], 7);
}); });
test("adds visited class to visited topics", async function (assert) {
await visit("/search");
await fillIn(".search-query", "discourse");
await click(".search-cta");
assert.equal(queryAll(".visited").length, 0);
await fillIn(".search-query", "discourse visited");
await click(".search-cta");
assert.equal(queryAll(".visited").length, 1);
});
}); });

View File

@ -254,10 +254,14 @@ export function applyDefaultHandlers(pretender) {
pretender.get("/search", (request) => { pretender.get("/search", (request) => {
if (request.queryParams.q === "discourse") { if (request.queryParams.q === "discourse") {
return response(fixturesByUrl["/search.json"]); return response(fixturesByUrl["/search.json"]);
} else if (request.queryParams.q === "discourse visited") {
const obj = JSON.parse(JSON.stringify(fixturesByUrl["/search.json"]));
obj.topics.firstObject.visited = true;
return response(obj);
} else if (request.queryParams.q === "discourse in:personal") { } else if (request.queryParams.q === "discourse in:personal") {
const fixtures = fixturesByUrl["/search.json"]; const obj = JSON.parse(JSON.stringify(fixturesByUrl["/search.json"]));
fixtures.topics.firstObject.archetype = "private_message"; obj.topics.firstObject.archetype = "private_message";
return response(fixtures); return response(obj);
} else { } else {
return response({}); return response({});
} }

View File

@ -329,7 +329,7 @@
} }
} }
a.search-link:visited .topic-title { a.search-link.visited .topic-title {
color: var(--primary-medium); color: var(--primary-medium);
} }
.search-link { .search-link {