fix(frontend): a filter written to the url survives another url write, the chat picked with alt and arrows stays in view
This commit is contained in:
1 parent
8a1723e99f
commit
e977ab77a8
2 files changed
+26
-6
No files matched your search
@@ -83,6 +83,11 @@
|
|||||||
if (index === -1 || viewport === null) {
|
if (index === -1 || viewport === null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
const row = viewport.querySelector<HTMLElement>(".Chat.selected");
|
||||||
|
if (row) {
|
||||||
|
row.scrollIntoView({ block: "nearest" });
|
||||||
|
return;
|
||||||
|
}
|
||||||
const top = index * rowHeight;
|
const top = index * rowHeight;
|
||||||
if (top < viewport.scrollTop) {
|
if (top < viewport.scrollTop) {
|
||||||
viewport.scrollTop = top;
|
viewport.scrollTop = top;
|
||||||
|
|||||||
@@ -1,17 +1,32 @@
|
|||||||
import { goto } from "$app/navigation";
|
import { goto } from "$app/navigation";
|
||||||
import { page } from "$app/state";
|
import { page } from "$app/state";
|
||||||
|
|
||||||
export async function replaceParam(
|
const ATTEMPTS = 2;
|
||||||
key: string,
|
|
||||||
value: string | null
|
function withParam(key: string, value: string | null): URL {
|
||||||
): Promise<void> {
|
|
||||||
const url = new URL(page.url.href);
|
const url = new URL(page.url.href);
|
||||||
if (value === null) {
|
if (value === null) {
|
||||||
url.searchParams.delete(key);
|
url.searchParams.delete(key);
|
||||||
} else {
|
} else {
|
||||||
url.searchParams.set(key, value);
|
url.searchParams.set(key, value);
|
||||||
}
|
}
|
||||||
if (url.href !== page.url.href) {
|
return url;
|
||||||
await goto(url, { replace: true, reset: false, state: { ...page.state } });
|
}
|
||||||
|
|
||||||
|
export async function replaceParam(
|
||||||
|
key: string,
|
||||||
|
value: string | null
|
||||||
|
): Promise<void> {
|
||||||
|
for (let attempt = 0; attempt < ATTEMPTS; attempt += 1) {
|
||||||
|
const url = withParam(key, value);
|
||||||
|
if (url.href === page.url.href) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// biome-ignore lint/performance/noAwaitInLoops: a write overtaken by another navigation is retried once
|
||||||
|
await goto(url, {
|
||||||
|
replace: true,
|
||||||
|
reset: false,
|
||||||
|
state: { ...page.state },
|
||||||
|
}).catch(() => undefined);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user