Skip to content

Commit

Permalink
[Assistants] Fix/clear searchParams while changing models (#783)
Browse files Browse the repository at this point in the history
* [Assistants] Fix/clear searchParams while changing models

* fix another reactivity bug
  • Loading branch information
Mishig authored Feb 5, 2024
1 parent 2468399 commit f3c82b6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
10 changes: 5 additions & 5 deletions src/lib/components/Pagination.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
$: pageIndex = parseInt($page.url.searchParams.get("p") ?? "0");
$: pageIndexes = getPageIndexes(pageIndex, numTotalPages);
function getHref(pageIdx: number) {
const newUrl = new URL($page.url);
function getHref(url: URL | string, pageIdx: number) {
const newUrl = new URL(url);
newUrl.searchParams.set("p", pageIdx.toString());
return newUrl.toString();
}
Expand Down Expand Up @@ -66,7 +66,7 @@
>
<li>
<PaginationArrow
href={getHref(pageIndex - 1)}
href={getHref($page.url, pageIndex - 1)}
direction="previous"
isDisabled={pageIndex - 1 < 0}
/>
Expand All @@ -81,15 +81,15 @@
: ''}
"
class:pointer-events-none={pageIdx === ELLIPSIS_IDX || pageIndex === pageIdx}
href={getHref(pageIdx)}
href={getHref($page.url, pageIdx)}
>
{pageIdx === ELLIPSIS_IDX ? "..." : pageIdx + 1}
</a>
</li>
{/each}
<li>
<PaginationArrow
href={getHref(pageIndex + 1)}
href={getHref($page.url, pageIndex + 1)}
direction="next"
isDisabled={pageIndex + 1 >= numTotalPages}
/>
Expand Down
5 changes: 2 additions & 3 deletions src/routes/assistants/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@
const onModelChange = (e: Event) => {
const newUrl = new URL($page.url);
if ((e.target as HTMLSelectElement).value === "") {
newUrl.searchParams.delete("modelId");
} else {
newUrl.search = ""; // clear searchParams (such as "p" for pagination)
if ((e.target as HTMLSelectElement).value) {
newUrl.searchParams.set("modelId", (e.target as HTMLSelectElement).value);
}
goto(newUrl);
Expand Down

0 comments on commit f3c82b6

Please sign in to comment.