tabs: add clearURL method, loading tabs clears previous qps
Navigatable has clearURL, which for Search clears "search" qp, and invites clears "invite" qp. Tab interfaces optionally include "contentObject: AsTab", and show/hide funcs are passed the contentObject of the previously loaded tab if one is available, so that they can call it's clearURL method. This means searches you typed for the accounts tab won't pop up when switching to activity.
This commit is contained in:
@@ -2516,6 +2516,10 @@ export class accountsList extends PaginatedList implements Navigatable, AsTab {
|
||||
if (details) this.details(details);
|
||||
});
|
||||
};
|
||||
|
||||
clearURL() {
|
||||
this._search.clearURL();
|
||||
}
|
||||
}
|
||||
|
||||
// An alternate view showing accounts in sub-lists grouped by group/label.
|
||||
|
||||
@@ -708,4 +708,8 @@ export class activityList extends PaginatedList implements Navigatable, AsTab {
|
||||
}
|
||||
this._search.navigate(urlParams.toString());
|
||||
};
|
||||
|
||||
clearURL() {
|
||||
this._search.clearURL();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -818,6 +818,14 @@ export class DOMInviteList implements InviteList {
|
||||
this.focusInvite(inviteCode, window.lang.notif("errorInviteNotFound"));
|
||||
};
|
||||
|
||||
clearURL() {
|
||||
const url = new URL(window.location.href);
|
||||
if (!url.searchParams.has("invite")) return;
|
||||
url.searchParams.delete("invite");
|
||||
console.log("pushing", url.toString());
|
||||
window.history.pushState(null, "", url.toString());
|
||||
}
|
||||
|
||||
constructor() {
|
||||
this._list = document.getElementById("invites") as HTMLDivElement;
|
||||
this.empty = true;
|
||||
|
||||
@@ -731,6 +731,10 @@ export class Search implements Navigatable {
|
||||
this.setQueryParam("");
|
||||
};
|
||||
|
||||
clearURL() {
|
||||
this.clearQueryParam();
|
||||
}
|
||||
|
||||
// setQueryParam sets the ?search query param to the current searchbox content,
|
||||
// or value if given. If everything is set up correctly, this should trigger a search when it is
|
||||
// set to a new value.
|
||||
|
||||
+10
-6
@@ -1,4 +1,4 @@
|
||||
import { PageManager } from "../modules/pages.js";
|
||||
import { PageManager } from "./pages";
|
||||
|
||||
export function isPageEventBindable(object: any): object is PageEventBindable {
|
||||
return "bindPageEvents" in object;
|
||||
@@ -12,7 +12,7 @@ export class TabManager implements TabManager {
|
||||
private _current: string = "";
|
||||
private _baseOffset = -1;
|
||||
tabs: Map<string, Tab>;
|
||||
pages: PageManager;
|
||||
pages: Pages;
|
||||
|
||||
constructor() {
|
||||
this.tabs = new Map<string, Tab>();
|
||||
@@ -26,14 +26,16 @@ export class TabManager implements TabManager {
|
||||
addTab = (
|
||||
tabID: string,
|
||||
url: string,
|
||||
preFunc = () => void {},
|
||||
postFunc = () => void {},
|
||||
contentObject: AsTab | null,
|
||||
preFunc: (previous?: AsTab) => void = (_?: AsTab) => void {},
|
||||
postFunc: (previous?: AsTab) => void = (_?: AsTab) => void {},
|
||||
unloadFunc = () => void {},
|
||||
) => {
|
||||
let tab: Tab = {
|
||||
page: null,
|
||||
tabEl: document.getElementById("tab-" + tabID) as HTMLDivElement,
|
||||
buttonEl: document.getElementById("button-tab-" + tabID) as HTMLButtonElement,
|
||||
contentObject: contentObject,
|
||||
preFunc: preFunc,
|
||||
postFunc: postFunc,
|
||||
};
|
||||
@@ -91,14 +93,16 @@ export class TabManager implements TabManager {
|
||||
[t] = this.tabs.values();
|
||||
}
|
||||
|
||||
const prev = this.tabs.get(this.current);
|
||||
|
||||
this._current = t.page.name;
|
||||
|
||||
if (t.preFunc && !noRun) {
|
||||
t.preFunc();
|
||||
t.preFunc(prev?.contentObject);
|
||||
}
|
||||
this.pages.load(tabID);
|
||||
if (t.postFunc && !noRun) {
|
||||
t.postFunc();
|
||||
t.postFunc(prev?.contentObject);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user