@fy-/fws-vue 2.1.27 → 2.1.28

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,17 +1,11 @@
1
1
  <script setup lang="ts">
2
- import type {
3
- WatchStopHandle,
4
- } from 'vue'
2
+ import type { WatchStopHandle } from 'vue'
5
3
  import type { RouteLocationRaw } from 'vue-router'
6
4
  import type { APIPaging } from '../../composables/rest'
7
5
  import { getURL, hasFW } from '@fy-/fws-js'
8
6
  import { ChevronLeftIcon, ChevronRightIcon } from '@heroicons/vue/24/solid'
9
7
  import { useServerHead } from '@unhead/vue'
10
- import {
11
- computed,
12
- ref,
13
- watch,
14
- } from 'vue'
8
+ import { computed, ref, watch } from 'vue'
15
9
  import { useRoute } from 'vue-router'
16
10
  import { useEventBus } from '../../composables/event-bus'
17
11
  import { useServerRouter } from '../../stores/serverRouter'
@@ -28,14 +22,17 @@ const props = withDefaults(
28
22
  hash: '',
29
23
  },
30
24
  )
25
+
31
26
  const route = useRoute()
32
27
  const eventBus = useEventBus()
33
28
  const history = useServerRouter()
29
+
34
30
  function isNewPage(page: number) {
35
31
  return (
36
32
  page >= 1 && page <= props.items.page_max && page !== props.items.page_no
37
33
  )
38
34
  }
35
+
39
36
  const pageWatcher = ref<WatchStopHandle>()
40
37
 
41
38
  function next() {
@@ -50,6 +47,7 @@ function next() {
50
47
  hash: props.hash !== '' ? `#${props.hash}` : undefined,
51
48
  })
52
49
  }
50
+
53
51
  function prev() {
54
52
  const page = props.items.page_no - 1
55
53
  if (!isNewPage(page)) return
@@ -90,15 +88,25 @@ useServerHead({
90
88
 
91
89
  if (hasFW()) {
92
90
  const url = getURL()
93
- if (page + 1 <= page_max && url) {
94
- next = `${url.Scheme}://${url.Host}${url.Path}?page=${page + 1}${
95
- props.hash !== '' ? `#${props.hash}` : ''
96
- }`
97
- }
98
- if (page - 1 >= 1 && url) {
99
- prev = `${url.Scheme}://${url.Host}${url.Path}?page=${page - 1}${
100
- props.hash !== '' ? `#${props.hash}` : ''
101
- }`
91
+ if (url) {
92
+ const currentQuery = { ...route.query }
93
+ // Remove the existing 'page' parameter to avoid duplicates
94
+ delete currentQuery.page
95
+
96
+ const baseURL = `${url.Scheme}://${url.Host}${url.Path}`
97
+ const hashPart = props.hash !== '' ? `#${props.hash}` : ''
98
+
99
+ if (page + 1 <= page_max) {
100
+ const nextQuery = { ...currentQuery, page: (page + 1).toString() }
101
+ const nextQueryString = new URLSearchParams(nextQuery).toString()
102
+ next = `${baseURL}?${nextQueryString}${hashPart}`
103
+ }
104
+
105
+ if (page - 1 >= 1) {
106
+ const prevQuery = { ...currentQuery, page: (page - 1).toString() }
107
+ const prevQueryString = new URLSearchParams(prevQuery).toString()
108
+ prev = `${baseURL}?${prevQueryString}${hashPart}`
109
+ }
102
110
  }
103
111
  }
104
112
 
@@ -106,14 +114,14 @@ useServerHead({
106
114
  result.push({
107
115
  href: next,
108
116
  rel: 'next',
109
- key: 'paging-next',
117
+ key: `paging-next${props.id}`,
110
118
  })
111
119
  }
112
120
  if (prev) {
113
121
  result.push({
114
122
  href: prev,
115
123
  rel: 'prev',
116
- key: 'paging-prev',
124
+ key: `paging-prev${props.id}`,
117
125
  })
118
126
  }
119
127
 
@@ -150,8 +158,7 @@ useServerHead({
150
158
  </li>
151
159
  <li v-if="items.page_no - 2 > 2">
152
160
  <div
153
- v-if="items.page_no - 2 > 2"
154
- class="flex items-center justify-center px-1.5 h-8 leading-tight text-fv-neutral-500 bg-white border border-fv-neutral-300 hover:bg-fv-neutral-100 hover:text-fv-neutral-700 dark:bg-fv-neutral-800 dark:border-fv-neutral-700 dark:text-fv-neutral-400 dark:hover:bg-fv-neutral-700 dark:hover:text-white"
161
+ class="flex items-center justify-center px-1.5 h-8 leading-tight text-fv-neutral-500 bg-white border border-fv-neutral-300 dark:bg-fv-neutral-800 dark:border-fv-neutral-700 dark:text-fv-neutral-400"
155
162
  >
156
163
  ...
157
164
  </div>
@@ -159,7 +166,7 @@ useServerHead({
159
166
  <template v-for="i in 2">
160
167
  <li
161
168
  v-if="items.page_no - (3 - i) >= 1"
162
- :key="`page-${items.page_no + i}`"
169
+ :key="`page-${items.page_no - (3 - i)}`"
163
170
  >
164
171
  <router-link
165
172
  class="flex items-center justify-center px-3 h-8 leading-tight text-fv-neutral-500 bg-white border border-fv-neutral-300 hover:bg-fv-neutral-100 hover:text-fv-neutral-700 dark:bg-fv-neutral-800 dark:border-fv-neutral-700 dark:text-fv-neutral-400 dark:hover:bg-fv-neutral-700 dark:hover:text-white"
@@ -172,7 +179,7 @@ useServerHead({
172
179
  <li>
173
180
  <div
174
181
  aria-current="page"
175
- class="z-10 flex items-center justify-center px-3 h-8 leading-tight text-primary-600 border border-primary-300 bg-primary-50 hover:bg-primary-100 hover:text-primary-700 dark:border-fv-neutral-700 dark:bg-fv-neutral-700 dark:text-white"
182
+ class="z-10 flex items-center justify-center px-3 h-8 leading-tight text-primary-600 border border-primary-300 bg-primary-50 dark:border-fv-neutral-700 dark:bg-fv-neutral-700 dark:text-white"
176
183
  >
177
184
  {{ items.page_no }}
178
185
  </div>
@@ -192,7 +199,7 @@ useServerHead({
192
199
  </template>
193
200
  <li v-if="items.page_no + 2 < items.page_max - 1">
194
201
  <div
195
- class="flex items-center justify-center px-1.5 h-8 leading-tight text-fv-neutral-500 bg-white border border-fv-neutral-300 hover:bg-fv-neutral-100 hover:text-fv-neutral-700 dark:bg-fv-neutral-800 dark:border-fv-neutral-700 dark:text-fv-neutral-400 dark:hover:bg-fv-neutral-700 dark:hover:text-white"
202
+ class="flex items-center justify-center px-1.5 h-8 leading-tight text-fv-neutral-500 bg-white border border-fv-neutral-300 dark:bg-fv-neutral-800 dark:border-fv-neutral-700 dark:text-fv-neutral-400"
196
203
  >
197
204
  ...
198
205
  </div>
@@ -205,7 +212,7 @@ useServerHead({
205
212
  {{ items.page_max }}
206
213
  </router-link>
207
214
  </li>
208
- <li v-if="items.page_no < items.page_max - 1">
215
+ <li v-if="items.page_no < items.page_max">
209
216
  <button
210
217
  type="button"
211
218
  class="flex items-center justify-center px-1.5 h-8 leading-tight text-fv-neutral-500 bg-white border border-fv-neutral-300 hover:bg-fv-neutral-100 hover:text-fv-neutral-700 dark:bg-fv-neutral-800 dark:border-fv-neutral-700 dark:text-fv-neutral-400 dark:hover:bg-fv-neutral-700 dark:hover:text-white"
@@ -223,8 +230,8 @@ useServerHead({
223
230
  >
224
231
  {{
225
232
  $t("global_paging", {
226
- start: items.results_per_page * (items.page_no - 1),
227
- end: items.results_per_page * items.page_no,
233
+ start: items.results_per_page * (items.page_no - 1) + 1,
234
+ end: Math.min(items.results_per_page * items.page_no, items.count),
228
235
  total: items.count >= 10000 ? $t("paging_a_lot_of") : items.count,
229
236
  })
230
237
  }}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fy-/fws-vue",
3
- "version": "2.1.27",
3
+ "version": "2.1.28",
4
4
  "author": "Florian 'Fy' Gasquez <m@fy.to>",
5
5
  "license": "MIT",
6
6
  "homepage": "https://github.com/fy-to/FWJS#readme",