@fy-/fws-vue 2.1.25 → 2.1.26

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.
@@ -30,15 +30,19 @@ const props = withDefaults(
30
30
  hash: '',
31
31
  },
32
32
  )
33
+
33
34
  const route = useRoute()
34
35
  const eventBus = useEventBus()
35
36
  const history = useServerRouter()
36
- const prevNextSeo = ref<any>({})
37
+
38
+ const prevNextSeo = ref<{ prev?: string, next?: string }>({})
39
+
37
40
  function isNewPage(page: number) {
38
41
  return (
39
42
  page >= 1 && page <= props.items.page_max && page !== props.items.page_no
40
43
  )
41
44
  }
45
+
42
46
  const pageWatcher = ref<WatchStopHandle>()
43
47
 
44
48
  function next() {
@@ -53,6 +57,7 @@ function next() {
53
57
  hash: props.hash !== '' ? `#${props.hash}` : undefined,
54
58
  })
55
59
  }
60
+
56
61
  function prev() {
57
62
  const page = props.items.page_no - 1
58
63
  if (!isNewPage(page)) return
@@ -76,60 +81,63 @@ function page(page: number): RouteLocationRaw {
76
81
  }
77
82
 
78
83
  function checkPageNumber(page: number = 1) {
84
+ // Reset prev and next
79
85
  prevNextSeo.value.next = undefined
80
86
  prevNextSeo.value.prev = undefined
81
87
 
82
88
  if (hasFW()) {
83
89
  const url = getURL()
84
- if (page + 1 <= props.items.page_max && url) {
85
- prevNextSeo.value.next
86
- = `${url.Scheme}://${url.Host}${url.Path}?page=${page + 1}${
87
- props.hash !== '' ? `#${props.hash}` : ''}`
88
- }
89
- if (page - 1 >= 1 && url) {
90
- prevNextSeo.value.prev
91
- = `${url.Scheme}://${url.Host}${url.Path}?page=${page - 1}${
92
- props.hash !== '' ? `#${props.hash}` : ''}`
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
+ }
93
97
  }
94
98
  }
95
99
  }
96
100
 
101
+ // Watch for changes in the current page number
97
102
  pageWatcher.value = watch(
98
- () => route.query.page,
99
- (v) => {
100
- eventBus.emit(`${props.id}GoToPage`, v || 1)
103
+ () => props.items.page_no,
104
+ (newPage) => {
105
+ checkPageNumber(newPage)
101
106
  },
107
+ { immediate: true }, // Ensure it's called initially
102
108
  )
109
+
103
110
  onMounted(() => {
104
111
  eventBus.on(`${props.id}GoToPage`, checkPageNumber)
105
112
  })
106
113
  onUnmounted(() => {
107
114
  eventBus.off(`${props.id}GoToPage`, checkPageNumber)
108
- // if (pageWatcher.value) pageWatcher.value();
115
+ if (pageWatcher.value) pageWatcher.value()
109
116
  })
110
117
 
118
+ // Initial check
111
119
  checkPageNumber(props.items.page_no)
112
120
 
121
+ // Setup SEO head
113
122
  useServerHead({
114
123
  link: computed(() => {
115
- const result: any = []
116
- checkPageNumber(props.items.page_no)
124
+ const links: any[] = []
125
+
117
126
  if (prevNextSeo.value.next) {
118
- result.push({
127
+ links.push({
119
128
  href: prevNextSeo.value.next,
120
129
  rel: 'next',
121
130
  key: 'paging-next',
122
131
  })
123
132
  }
124
133
  if (prevNextSeo.value.prev) {
125
- result.push({
134
+ links.push({
126
135
  href: prevNextSeo.value.prev,
127
136
  rel: 'prev',
128
137
  key: 'paging-prev',
129
138
  })
130
139
  }
131
-
132
- return result
140
+ return links
133
141
  }),
134
142
  })
135
143
  </script>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fy-/fws-vue",
3
- "version": "2.1.25",
3
+ "version": "2.1.26",
4
4
  "author": "Florian 'Fy' Gasquez <m@fy.to>",
5
5
  "license": "MIT",
6
6
  "homepage": "https://github.com/fy-to/FWJS#readme",