Mishig commited on
Commit
f3c82b6
1 Parent(s): 2468399

[Assistants] Fix/clear searchParams while changing models (#783)

Browse files

* [Assistants] Fix/clear searchParams while changing models

* fix another reactivity bug

src/lib/components/Pagination.svelte CHANGED
@@ -12,8 +12,8 @@
12
  $: pageIndex = parseInt($page.url.searchParams.get("p") ?? "0");
13
  $: pageIndexes = getPageIndexes(pageIndex, numTotalPages);
14
 
15
- function getHref(pageIdx: number) {
16
- const newUrl = new URL($page.url);
17
  newUrl.searchParams.set("p", pageIdx.toString());
18
  return newUrl.toString();
19
  }
@@ -66,7 +66,7 @@
66
  >
67
  <li>
68
  <PaginationArrow
69
- href={getHref(pageIndex - 1)}
70
  direction="previous"
71
  isDisabled={pageIndex - 1 < 0}
72
  />
@@ -81,7 +81,7 @@
81
  : ''}
82
  "
83
  class:pointer-events-none={pageIdx === ELLIPSIS_IDX || pageIndex === pageIdx}
84
- href={getHref(pageIdx)}
85
  >
86
  {pageIdx === ELLIPSIS_IDX ? "..." : pageIdx + 1}
87
  </a>
@@ -89,7 +89,7 @@
89
  {/each}
90
  <li>
91
  <PaginationArrow
92
- href={getHref(pageIndex + 1)}
93
  direction="next"
94
  isDisabled={pageIndex + 1 >= numTotalPages}
95
  />
 
12
  $: pageIndex = parseInt($page.url.searchParams.get("p") ?? "0");
13
  $: pageIndexes = getPageIndexes(pageIndex, numTotalPages);
14
 
15
+ function getHref(url: URL | string, pageIdx: number) {
16
+ const newUrl = new URL(url);
17
  newUrl.searchParams.set("p", pageIdx.toString());
18
  return newUrl.toString();
19
  }
 
66
  >
67
  <li>
68
  <PaginationArrow
69
+ href={getHref($page.url, pageIndex - 1)}
70
  direction="previous"
71
  isDisabled={pageIndex - 1 < 0}
72
  />
 
81
  : ''}
82
  "
83
  class:pointer-events-none={pageIdx === ELLIPSIS_IDX || pageIndex === pageIdx}
84
+ href={getHref($page.url, pageIdx)}
85
  >
86
  {pageIdx === ELLIPSIS_IDX ? "..." : pageIdx + 1}
87
  </a>
 
89
  {/each}
90
  <li>
91
  <PaginationArrow
92
+ href={getHref($page.url, pageIndex + 1)}
93
  direction="next"
94
  isDisabled={pageIndex + 1 >= numTotalPages}
95
  />
src/routes/assistants/+page.svelte CHANGED
@@ -18,9 +18,8 @@
18
 
19
  const onModelChange = (e: Event) => {
20
  const newUrl = new URL($page.url);
21
- if ((e.target as HTMLSelectElement).value === "") {
22
- newUrl.searchParams.delete("modelId");
23
- } else {
24
  newUrl.searchParams.set("modelId", (e.target as HTMLSelectElement).value);
25
  }
26
  goto(newUrl);
 
18
 
19
  const onModelChange = (e: Event) => {
20
  const newUrl = new URL($page.url);
21
+ newUrl.search = ""; // clear searchParams (such as "p" for pagination)
22
+ if ((e.target as HTMLSelectElement).value) {
 
23
  newUrl.searchParams.set("modelId", (e.target as HTMLSelectElement).value);
24
  }
25
  goto(newUrl);