Skip to content

Commit 83d1f5c

Browse files
authored
fix: paginator values being cloned (#3433)
1 parent ac7cbbb commit 83d1f5c

File tree

14 files changed

+408
-276
lines changed

14 files changed

+408
-276
lines changed

app/components/modal/ModalMediaPreviewCarousel.vue

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -159,14 +159,16 @@ function handleTap([positionX, positionY]: Vector2) {
159159
goToFocusedSlide()
160160
}
161161
else {
162-
const focusedSlideBounding = slide.value[modelValue.value].getBoundingClientRect()
163-
const slideCenterX = focusedSlideBounding.left + focusedSlideBounding.width / 2
164-
const slideCenterY = focusedSlideBounding.top + focusedSlideBounding.height / 2
165-
166-
scale.value = 3
167-
x.value += positionX - slideCenterX
168-
y.value += positionY - slideCenterY
169-
restrictShiftToInsideSlide()
162+
const focusedSlideBounding = slide.value[modelValue.value]?.getBoundingClientRect()
163+
if (focusedSlideBounding) {
164+
const slideCenterX = focusedSlideBounding.left + focusedSlideBounding.width / 2
165+
const slideCenterY = focusedSlideBounding.top + focusedSlideBounding.height / 2
166+
167+
scale.value = 3
168+
x.value += positionX - slideCenterX
169+
y.value += positionY - slideCenterY
170+
restrictShiftToInsideSlide()
171+
}
170172
}
171173
}
172174

app/components/timeline/TimelineHome.vue

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@ function reorderAndFilter(items: mastodon.v1.Status[]) {
1111
return reorderedTimeline(items, 'home')
1212
}
1313
14-
let followedTags: mastodon.v1.Tag[] | undefined
14+
let followedTags: mastodon.v1.Tag[]
1515
if (currentUser.value !== undefined) {
16-
followedTags = (await useMasto().client.value.v1.followedTags.list({ limit: 0 }))
16+
const { client } = useMasto()
17+
const paginator = client.value.v1.followedTags.list()
18+
followedTags = (await paginator.values().next()).value ?? []
1719
}
1820
</script>
1921

app/components/timeline/TimelineNotifications.vue

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ const options = { limit: 30, types: filter ? [filter] : [] }
1313
1414
// Default limit is 20 notifications, and servers are normally caped to 30
1515
const paginator = useMastoClient().v1.notifications.list(options)
16+
17+
// @ts-expect-error Type error should be fixed with the following PR to masto.js: https://github.com/neet/masto.js/pull/1355
1618
const stream = useStreaming(client => client.user.notification.subscribe())
1719
1820
lastAccessedNotificationRoute.value = route.path.replace(/\/notifications\/?/, '')

app/components/timeline/TimelinePublic.vue

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@ function reorderAndFilter(items: mastodon.v1.Status[]) {
77
return reorderedTimeline(items, 'public')
88
}
99
10-
let followedTags: mastodon.v1.Tag[] | undefined
10+
let followedTags: mastodon.v1.Tag[]
1111
if (currentUser.value !== undefined) {
12-
followedTags = (await useMasto().client.value.v1.followedTags.list({ limit: 0 }))
12+
const { client } = useMasto()
13+
const paginator = client.value.v1.followedTags.list()
14+
followedTags = (await paginator.values().next()).value ?? []
1315
}
1416
</script>
1517

app/components/timeline/TimelinePublicLocal.vue

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@ function reorderAndFilter(items: mastodon.v1.Status[]) {
77
return reorderedTimeline(items, 'public')
88
}
99
10-
let followedTags: mastodon.v1.Tag[] | undefined
10+
let followedTags: mastodon.v1.Tag[]
1111
if (currentUser.value !== undefined) {
12-
followedTags = (await useMasto().client.value.v1.followedTags.list({ limit: 0 }))
12+
const { client } = useMasto()
13+
const paginator = client.value.v1.followedTags.list()
14+
followedTags = (await paginator.values().next()).value ?? []
1315
}
1416
</script>
1517

app/composables/cache.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ export async function fetchAccountByHandle(acct: string): Promise<mastodon.v1.Ac
7474
}
7575
else {
7676
const userAcctDomain = userAcct.includes('@') ? userAcct : `${userAcct}@${domain}`
77-
account = (await client.v1.search.fetch({ q: `@${userAcctDomain}`, type: 'accounts' })).accounts[0]
77+
account = (await client.v1.search.list({ q: `@${userAcctDomain}`, type: 'accounts' })).accounts[0]
7878
}
7979

8080
if (account.acct && !account.acct.includes('@') && domain)

app/composables/masto/notification.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,10 @@ export function useNotifications() {
4545

4646
const position = await client.value.v1.markers.fetch({ timeline: ['notifications'] })
4747
const paginator = client.value.v1.notifications.list({ limit: 30 })
48+
const paginatorValues = paginator.values()
4849

4950
do {
50-
const result = await paginator.next()
51+
const result = await paginatorValues.next()
5152
if (!result.done && result.value.length) {
5253
for (const notification of result.value) {
5354
if (notification.id === position.notifications.lastReadId)

app/composables/masto/search.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ export function useSearch(query: MaybeRefOrGetter<string>, options: UseSearchOpt
7777
...resolveUnref(options),
7878
resolve: !!currentUser.value,
7979
})
80-
const nextResults = await paginator.next()
80+
const nextResults = await paginator.values().next()
8181

8282
done.value = !!nextResults.done
8383
if (!nextResults.done)
@@ -91,7 +91,7 @@ export function useSearch(query: MaybeRefOrGetter<string>, options: UseSearchOpt
9191
return
9292

9393
loading.value = true
94-
const nextResults = await paginator.next()
94+
const nextResults = await paginator.values().next()
9595
loading.value = false
9696

9797
done.value = !!nextResults.done

app/composables/paginator.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type { mastodon } from 'masto'
33
import type { Ref } from 'vue'
44

55
export function usePaginator<T, P, U = T>(
6-
_paginator: mastodon.Paginator<T[], P>,
6+
paginator: mastodon.Paginator<T[], P>,
77
stream: Ref<mastodon.streaming.Subscription | undefined>,
88
eventType: 'update' | 'notification' = 'update',
99
preprocess: (items: (T | U)[]) => U[] = items => items as unknown as U[],
@@ -12,8 +12,8 @@ export function usePaginator<T, P, U = T>(
1212
// called `next` method will mutate the internal state of the variable,
1313
// and we need its initial state after HMR
1414
// so clone it
15-
const paginator = _paginator.clone()
1615

16+
const paginatorValues = paginator.values()
1717
const state = ref<PaginatorState>(isHydrated.value ? 'idle' : 'loading')
1818
const items = ref<U[]>([])
1919
const nextItems = ref<U[]>([])
@@ -75,7 +75,7 @@ export function usePaginator<T, P, U = T>(
7575

7676
state.value = 'loading'
7777
try {
78-
const result = await paginator.next()
78+
const result = await paginatorValues.next()
7979

8080
if (!result.done && result.value.length) {
8181
const preprocessedItems = preprocess([...nextItems.value, ...result.value] as (U | T)[])

app/composables/tiptap/suggestion.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export const TiptapMentionSuggestion: Partial<SuggestionOptions> = import.meta.s
2828
return []
2929

3030
const paginator = useMastoClient().v2.search.list({ q: query, type: 'accounts', limit: 25, resolve: true })
31-
return (await paginator.next()).value?.accounts ?? []
31+
return (await paginator.values().next()).value?.accounts ?? []
3232
},
3333
render: createSuggestionRenderer(TiptapMentionList),
3434
}
@@ -47,7 +47,7 @@ export const TiptapHashtagSuggestion: Partial<SuggestionOptions> = {
4747
resolve: false,
4848
excludeUnreviewed: true,
4949
})
50-
return (await paginator.next()).value?.hashtags ?? []
50+
return (await paginator.values().next()).value?.hashtags ?? []
5151
},
5252
render: createSuggestionRenderer(TiptapHashtagList),
5353
}

0 commit comments

Comments
 (0)