@wyxos/vibe 1.2.15 → 1.2.16

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wyxos/vibe",
3
- "version": "1.2.15",
3
+ "version": "1.2.16",
4
4
  "main": "index.js",
5
5
  "module": "index.js",
6
6
  "type": "module",
package/src/Masonry.vue CHANGED
@@ -129,14 +129,38 @@ async function getContent(page) {
129
129
  }
130
130
 
131
131
  async function loadPage(page) {
132
- const response = await getContent(page)
133
- paginationHistory.value.push(response.nextPage)
134
- return response
132
+ if (isLoading.value) return // Prevent concurrent loading
133
+
134
+ isLoading.value = true
135
+
136
+ try {
137
+ const response = await getContent(page)
138
+ paginationHistory.value.push(response.nextPage)
139
+ return response
140
+ } catch (error) {
141
+ console.error('Error loading page:', error)
142
+ throw error
143
+ } finally {
144
+ isLoading.value = false
145
+ }
135
146
  }
136
147
 
137
148
  async function loadNext() {
138
- const currentPage = paginationHistory.value[paginationHistory.value.length - 1]
139
- return await loadPage(currentPage)
149
+ if (isLoading.value) return // Prevent concurrent loading
150
+
151
+ isLoading.value = true
152
+
153
+ try {
154
+ const currentPage = paginationHistory.value[paginationHistory.value.length - 1]
155
+ const response = await getContent(currentPage)
156
+ paginationHistory.value.push(response.nextPage)
157
+ return response
158
+ } catch (error) {
159
+ console.error('Error loading next page:', error)
160
+ throw error
161
+ } finally {
162
+ isLoading.value = false
163
+ }
140
164
  }
141
165
 
142
166
  function onRemove(item) {
@@ -149,25 +173,25 @@ function onResize() {
149
173
  }
150
174
 
151
175
  onMounted(async () => {
152
- isLoading.value = true
153
-
154
- columns.value = getColumnCount(layout.value)
155
-
156
- // For cursor-based pagination, loadAtPage can be null for the first request
157
- const initialPage = props.loadAtPage
158
- paginationHistory.value = [initialPage]
159
-
160
- // Skip initial load if skipInitialLoad prop is true
161
- if (!props.skipInitialLoad) {
162
- await loadPage(paginationHistory.value[0])
163
- } else {
164
- await nextTick()
165
- // Just refresh the layout with any existing items
166
- refreshLayout(masonry.value)
176
+ try {
177
+ columns.value = getColumnCount(layout.value)
178
+
179
+ // For cursor-based pagination, loadAtPage can be null for the first request
180
+ const initialPage = props.loadAtPage
181
+ paginationHistory.value = [initialPage]
182
+
183
+ // Skip initial load if skipInitialLoad prop is true
184
+ if (!props.skipInitialLoad) {
185
+ await loadPage(paginationHistory.value[0]) // loadPage manages its own loading state
186
+ } else {
187
+ await nextTick()
188
+ // Just refresh the layout with any existing items
189
+ refreshLayout(masonry.value)
190
+ }
191
+ } catch (error) {
192
+ console.error('Error during component initialization:', error)
167
193
  }
168
194
 
169
- isLoading.value = false
170
-
171
195
  container.value?.addEventListener('scroll', debounce(handleScroll, 200));
172
196
 
173
197
  window.addEventListener('resize', debounce(onResize, 200));
@@ -24,16 +24,17 @@ export function useMasonryScroll({
24
24
  const reachedContainerBottom = scrollTop + clientHeight >= containerHeight.value - 1
25
25
 
26
26
  if ((whitespaceVisible || reachedContainerBottom) && !isLoading.value) {
27
- isLoading.value = true
27
+ try {
28
+ // Handle cleanup when too many items
29
+ if (masonry.value.length > maxItems) {
30
+ await handleItemCleanup(columnHeights)
31
+ }
28
32
 
29
- // Handle cleanup when too many items
30
- if (masonry.value.length > maxItems) {
31
- await handleItemCleanup(columnHeights)
33
+ await loadNext() // loadNext manages its own loading state
34
+ await nextTick()
35
+ } catch (error) {
36
+ console.error('Error in scroll handler:', error)
32
37
  }
33
-
34
- await loadNext()
35
- await nextTick()
36
- isLoading.value = false
37
38
  }
38
39
  }
39
40
 
@@ -41,9 +42,7 @@ export function useMasonryScroll({
41
42
  const firstItem = masonry.value[0]
42
43
 
43
44
  if (!firstItem) {
44
- await loadNext()
45
- await nextTick()
46
- isLoading.value = false
45
+ // Don't set isLoading here - let main handleScroll manage it
47
46
  return
48
47
  }
49
48
 
@@ -51,9 +50,7 @@ export function useMasonryScroll({
51
50
  const removedItems = masonry.value.filter(i => i.page !== page)
52
51
 
53
52
  if (removedItems.length === masonry.value.length) {
54
- await loadNext()
55
- await nextTick()
56
- isLoading.value = false
53
+ // Don't set isLoading here - let main handleScroll manage it
57
54
  return
58
55
  }
59
56