loadmore+viewed-fix
This commit is contained in:
parent
3d2125d99f
commit
7ca7acc487
|
@ -19,11 +19,12 @@ export const LoadMoreWrapper = (props: LoadMoreProps) => {
|
|||
const { t } = useLocalize()
|
||||
const [items, setItems] = createSignal<LoadMoreItems>([])
|
||||
const [offset, setOffset] = createSignal(0)
|
||||
const [isLoadMoreButtonVisible, setIsLoadMoreButtonVisible] = createSignal(false)
|
||||
const [isLoadMoreButtonVisible, setIsLoadMoreButtonVisible] = createSignal(props.hidden)
|
||||
const [isLoading, setIsLoading] = createSignal(false)
|
||||
|
||||
createEffect(
|
||||
on(items, (iii) => {
|
||||
// console.debug('LoadMoreWrapper.fx:', iii)
|
||||
if (Array.isArray(iii)) {
|
||||
setIsLoadMoreButtonVisible(iii.length - offset() >= 0)
|
||||
setOffset(iii.length)
|
||||
|
@ -36,7 +37,8 @@ export const LoadMoreWrapper = (props: LoadMoreProps) => {
|
|||
saveScrollPosition()
|
||||
const newItems = await props.loadFunction(offset())
|
||||
if (!Array.isArray(newItems)) return
|
||||
setItems(
|
||||
if (newItems.length === 0) setIsLoadMoreButtonVisible(false)
|
||||
else setItems(
|
||||
(prev) =>
|
||||
Array.from(new Set([...prev, ...newItems])).sort(
|
||||
byCreated as SortFunction<unknown>
|
||||
|
|
|
@ -39,10 +39,10 @@ export type TopicPageProps = { articles?: Shout[]; topics: Topic[]; authors?: Au
|
|||
|
||||
export default function TopicPage(props: RouteSectionProps<TopicPageProps>) {
|
||||
const { t } = useLocalize()
|
||||
const { addTopics } = useTopics()
|
||||
const [loadingError, setLoadingError] = createSignal(false)
|
||||
|
||||
// all topics
|
||||
const { addTopics } = useTopics()
|
||||
const [loadingError, setLoadingError] = createSignal(false)
|
||||
const topics = createAsync(async () => {
|
||||
const result = props.data.topics || (await fetchAllTopics())
|
||||
if (!result) setLoadingError(true)
|
||||
|
@ -61,7 +61,7 @@ export default function TopicPage(props: RouteSectionProps<TopicPageProps>) {
|
|||
const [title, setTitle] = createSignal<string>('')
|
||||
const [desc, setDesc] = createSignal<string>('')
|
||||
const [cover, setCover] = createSignal<string>('')
|
||||
|
||||
const [viewed, setViewed] = createSignal(false)
|
||||
createEffect(on([topics, () => window], ([ttt, win]) => {
|
||||
if (ttt && win) {
|
||||
// console.debug('all topics:', ttt)
|
||||
|
@ -80,11 +80,14 @@ export default function TopicPage(props: RouteSectionProps<TopicPageProps>) {
|
|||
)
|
||||
|
||||
// views google counter increment
|
||||
window?.gtag?.('event', 'page_view', {
|
||||
if (viewed()) {
|
||||
window?.gtag?.('event', 'page_view', {
|
||||
page_title: tpc.title,
|
||||
page_location: window?.location.href,
|
||||
page_path: window?.location.pathname
|
||||
})
|
||||
setViewed(true)
|
||||
}
|
||||
}
|
||||
}, {}))
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@ export function paginate<T>(arr: T[], startIndex: number, pageSize: number): T[]
|
|||
}
|
||||
|
||||
// Добавляем текущий элемент на последнюю страницу
|
||||
acc.at(-1)?.push(item)
|
||||
acc[acc.length - 1].push(item)
|
||||
return acc
|
||||
}, [] as T[][]) // Инициализируем аккумулятор как пустой массив массивов
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user