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