FIX: Do a transition to update 'solved' queryparam (#184)

A more involved transition / redirect was happening which sometimes
made Ember think it was an incomplete transition and threw an error.
This commit is contained in:
Dan Ungureanu 2022-01-08 13:58:41 +02:00 committed by GitHub
parent 5e87180ed7
commit ec9258d2ee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 2 additions and 15 deletions

View File

@ -1,5 +1,4 @@
import I18n from "I18n"; import I18n from "I18n";
import DiscourseUrl from "discourse/lib/url";
import { getOwner } from "discourse-common/lib/get-owner"; import { getOwner } from "discourse-common/lib/get-owner";
export default { export default {
@ -42,23 +41,11 @@ export default {
actions: { actions: {
changeStatus(newStatus) { changeStatus(newStatus) {
let location = window.location; const router = getOwner(this).lookup("router:main");
let queryStrings = location.search;
let params = queryStrings.startsWith("?")
? queryStrings.substr(1).split("&")
: [];
params = params.filter((param) => !param.startsWith("solved="));
if (newStatus && newStatus !== "all") { if (newStatus && newStatus !== "all") {
newStatus = newStatus === "solved" ? "yes" : "no"; newStatus = newStatus === "solved" ? "yes" : "no";
params.push(`solved=${newStatus}`);
} }
router.transitionTo({ queryParams: { solved: newStatus } });
queryStrings = params.length > 0 ? `?${params.join("&")}` : "";
DiscourseUrl.routeTo(
`${location.pathname}${queryStrings}${location.hash}`
);
}, },
}, },
}; };