@fy-/fws-vue 2.1.26 → 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,19 +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
- onMounted,
13
- onUnmounted,
14
- ref,
15
- watch,
16
- } from 'vue'
8
+ import { computed, ref, watch } from 'vue'
17
9
  import { useRoute } from 'vue-router'
18
10
  import { useEventBus } from '../../composables/event-bus'
19
11
  import { useServerRouter } from '../../stores/serverRouter'
@@ -35,8 +27,6 @@ const route = useRoute()
35
27
  const eventBus = useEventBus()
36
28
  const history = useServerRouter()
37
29
 
38
- const prevNextSeo = ref<{ prev?: string, next?: string }>({})
39
-
40
30
  function isNewPage(page: number) {
41
31
  return (
42
32
  page >= 1 && page <= props.items.page_max && page !== props.items.page_no
@@ -80,64 +70,62 @@ function page(page: number): RouteLocationRaw {
80
70
  }
81
71
  }
82
72
 
83
- function checkPageNumber(page: number = 1) {
84
- // Reset prev and next
85
- prevNextSeo.value.next = undefined
86
- prevNextSeo.value.prev = undefined
87
-
88
- if (hasFW()) {
89
- const url = getURL()
90
- if (url) {
91
- if (page + 1 <= props.items.page_max) {
92
- prevNextSeo.value.next = `${url.Scheme}://${url.Host}${url.Path}?page=${page + 1}${props.hash !== '' ? `#${props.hash}` : ''}`
93
- }
94
- if (page - 1 >= 1) {
95
- prevNextSeo.value.prev = `${url.Scheme}://${url.Host}${url.Path}?page=${page - 1}${props.hash !== '' ? `#${props.hash}` : ''}`
96
- }
97
- }
98
- }
99
- }
100
-
101
- // Watch for changes in the current page number
102
73
  pageWatcher.value = watch(
103
- () => props.items.page_no,
104
- (newPage) => {
105
- checkPageNumber(newPage)
74
+ () => route.query.page,
75
+ (v) => {
76
+ eventBus.emit(`${props.id}GoToPage`, v || 1)
106
77
  },
107
- { immediate: true }, // Ensure it's called initially
108
78
  )
109
79
 
110
- onMounted(() => {
111
- eventBus.on(`${props.id}GoToPage`, checkPageNumber)
112
- })
113
- onUnmounted(() => {
114
- eventBus.off(`${props.id}GoToPage`, checkPageNumber)
115
- if (pageWatcher.value) pageWatcher.value()
116
- })
117
-
118
- // Initial check
119
- checkPageNumber(props.items.page_no)
120
-
121
- // Setup SEO head
122
80
  useServerHead({
123
81
  link: computed(() => {
124
- const links: any[] = []
82
+ const result: any = []
83
+ const page = props.items.page_no
84
+ const page_max = props.items.page_max
85
+
86
+ let next
87
+ let prev
88
+
89
+ if (hasFW()) {
90
+ const url = getURL()
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
+ }
110
+ }
111
+ }
125
112
 
126
- if (prevNextSeo.value.next) {
127
- links.push({
128
- href: prevNextSeo.value.next,
113
+ if (next) {
114
+ result.push({
115
+ href: next,
129
116
  rel: 'next',
130
- key: 'paging-next',
117
+ key: `paging-next${props.id}`,
131
118
  })
132
119
  }
133
- if (prevNextSeo.value.prev) {
134
- links.push({
135
- href: prevNextSeo.value.prev,
120
+ if (prev) {
121
+ result.push({
122
+ href: prev,
136
123
  rel: 'prev',
137
- key: 'paging-prev',
124
+ key: `paging-prev${props.id}`,
138
125
  })
139
126
  }
140
- return links
127
+
128
+ return result
141
129
  }),
142
130
  })
143
131
  </script>
@@ -170,8 +158,7 @@ useServerHead({
170
158
  </li>
171
159
  <li v-if="items.page_no - 2 > 2">
172
160
  <div
173
- v-if="items.page_no - 2 > 2"
174
- 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"
175
162
  >
176
163
  ...
177
164
  </div>
@@ -179,7 +166,7 @@ useServerHead({
179
166
  <template v-for="i in 2">
180
167
  <li
181
168
  v-if="items.page_no - (3 - i) >= 1"
182
- :key="`page-${items.page_no + i}`"
169
+ :key="`page-${items.page_no - (3 - i)}`"
183
170
  >
184
171
  <router-link
185
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"
@@ -192,7 +179,7 @@ useServerHead({
192
179
  <li>
193
180
  <div
194
181
  aria-current="page"
195
- 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"
196
183
  >
197
184
  {{ items.page_no }}
198
185
  </div>
@@ -212,7 +199,7 @@ useServerHead({
212
199
  </template>
213
200
  <li v-if="items.page_no + 2 < items.page_max - 1">
214
201
  <div
215
- 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"
216
203
  >
217
204
  ...
218
205
  </div>
@@ -225,7 +212,7 @@ useServerHead({
225
212
  {{ items.page_max }}
226
213
  </router-link>
227
214
  </li>
228
- <li v-if="items.page_no < items.page_max - 1">
215
+ <li v-if="items.page_no < items.page_max">
229
216
  <button
230
217
  type="button"
231
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"
@@ -243,8 +230,8 @@ useServerHead({
243
230
  >
244
231
  {{
245
232
  $t("global_paging", {
246
- start: items.results_per_page * (items.page_no - 1),
247
- 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),
248
235
  total: items.count >= 10000 ? $t("paging_a_lot_of") : items.count,
249
236
  })
250
237
  }}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fy-/fws-vue",
3
- "version": "2.1.26",
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",