forked from Mirrors/elk
refactor: don't pass down context
This commit is contained in:
parent
6e5ef04bb6
commit
6c114c6f14
4 changed files with 7 additions and 10 deletions
|
@ -11,15 +11,13 @@ const {
|
|||
virtualScroller = false,
|
||||
eventType = 'update',
|
||||
preprocess,
|
||||
context = 'public',
|
||||
} = defineProps<{
|
||||
paginator: Paginator<T[], O>
|
||||
keyProp?: keyof T
|
||||
virtualScroller?: boolean
|
||||
stream?: Promise<WsEvents>
|
||||
eventType?: 'notification' | 'update'
|
||||
preprocess?: (items: (U | T)[], context?: mastodon.v2.FilterContext) => U[]
|
||||
context?: mastodon.v2.FilterContext
|
||||
preprocess?: (items: (U | T)[]) => U[]
|
||||
}>()
|
||||
|
||||
defineSlots<{
|
||||
|
@ -44,7 +42,7 @@ defineSlots<{
|
|||
|
||||
const { t } = useI18n()
|
||||
|
||||
const { items, prevItems, update, state, endAnchor, error } = usePaginator(paginator, $$(stream), eventType, preprocess, context)
|
||||
const { items, prevItems, update, state, endAnchor, error } = usePaginator(paginator, $$(stream), eventType, preprocess)
|
||||
</script>
|
||||
|
||||
<template>
|
||||
|
|
|
@ -22,7 +22,7 @@ const showOriginSite = $computed(() =>
|
|||
</script>
|
||||
|
||||
<template>
|
||||
<CommonPaginator v-bind="{ paginator, stream, preprocess, buffer }" :virtual-scroller="virtualScroller" :context="context">
|
||||
<CommonPaginator v-bind="{ paginator, stream, preprocess, buffer }" :virtual-scroller="virtualScroller">
|
||||
<template #updater="{ number, update }">
|
||||
<button py-4 border="b base" flex="~ col" p-3 w-full text-primary font-bold @click="update">
|
||||
{{ $t('timeline.show_new_items', number, { named: { v: formatNumber(number) } }) }}
|
||||
|
|
|
@ -6,8 +6,7 @@ export function usePaginator<T, P, U = T>(
|
|||
_paginator: Paginator<T[], P>,
|
||||
stream: Ref<Promise<WsEvents> | undefined>,
|
||||
eventType: 'notification' | 'update' = 'update',
|
||||
preprocess: (items: (T | U)[], context?: mastodon.v2.FilterContext) => U[] = items => items as unknown as U[],
|
||||
context?: mastodon.v2.FilterContext,
|
||||
preprocess: (items: (T | U)[]) => U[] = items => items as unknown as U[],
|
||||
buffer = 10,
|
||||
) {
|
||||
// called `next` method will mutate the internal state of the variable,
|
||||
|
@ -27,7 +26,7 @@ export function usePaginator<T, P, U = T>(
|
|||
const deactivated = useDeactivated()
|
||||
|
||||
async function update() {
|
||||
(items.value as U[]).unshift(...preprocess(prevItems.value as T[], context))
|
||||
(items.value as U[]).unshift(...preprocess(prevItems.value as T[]))
|
||||
prevItems.value = []
|
||||
}
|
||||
|
||||
|
@ -74,7 +73,7 @@ export function usePaginator<T, P, U = T>(
|
|||
const result = await paginator.next()
|
||||
|
||||
if (!result.done && result.value.length) {
|
||||
const preprocessedItems = preprocess([...nextItems.value, ...result.value] as (U | T)[], context)
|
||||
const preprocessedItems = preprocess([...nextItems.value, ...result.value] as (U | T)[])
|
||||
const itemsToShowCount
|
||||
= preprocessedItems.length <= buffer
|
||||
? preprocessedItems.length
|
||||
|
|
|
@ -9,7 +9,7 @@ function areStatusesConsecutive(a: mastodon.v1.Status, b: mastodon.v1.Status) {
|
|||
return !!inReplyToId && (inReplyToId === a.reblog?.id || inReplyToId === a.id)
|
||||
}
|
||||
|
||||
export function reorderedTimeline(items: mastodon.v1.Status[], context: mastodon.v1.FilterContext = 'public') {
|
||||
export function reorderedTimeline(items: mastodon.v1.Status[], context: mastodon.v1.FilterContext) {
|
||||
let steps = 0
|
||||
|
||||
const isStrict = (filter: mastodon.v1.FilterResult) => filter.filter.filterAction === 'hide' && filter.filter.context.includes(context)
|
||||
|
|
Loading…
Reference in a new issue