Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/582 add loading events #656

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions frontend/components/common/ScrollingPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ const props = defineProps({
hasNextPage: {
type: Boolean as PropType<boolean>,
required: true
},
prerender: {
type: Number as PropType<number>,
required: true
}
});

Expand Down Expand Up @@ -124,6 +128,7 @@ const sizeDependenciesFormatter = (item: NestedEventOnPoster): Array<string> =>
:min-item-size="minItemSize"
:buffer="buffer"
:page-mode="isPageMode"
:prerender="prerender"
class="scroll-list__content"
>
<template #before>
Expand Down
3 changes: 2 additions & 1 deletion frontend/constants/global.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export const maxRequests: number = 1
export const maxRequests: number = 20
export const pagesToLoad: number = 1
export const minItemCardSize: number = 336
export const distanceToLoadEvents: number = 10
13 changes: 7 additions & 6 deletions frontend/pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { RouteNameEnum } from '@/constants/enums/route';
import { useModal } from 'vue-final-modal';
import NeedAuthorize from '@/components/modal/NeedAuthorize.vue';
import EventModal from '@/components/modal/Event.client.vue';
import { maxRequests, minItemCardSize, distanceToLoadEvents } from '@/constants/global';
import { maxRequests, minItemCardSize, distanceToLoadEvents, pagesToLoad } from '@/constants/global';
import { type EventOnPoster } from '../../common/types';
import { useListStore } from '~/stores/list.store';

Expand Down Expand Up @@ -44,14 +44,14 @@ const debouncedEventsRequestQuery = refDebounced(
);

const posterEvents: Ref<EventOnPoster[] | null> = ref(listStore.events);
const requestLimit = ref(listStore.eventRequestLimit);
const requestPages = ref(listStore.eventRequestPages);
const hasMorePages = ref(true);
const now = Date.now();

watch(
[() => listStore.eventRequestLimit, () => listStore.events],
[() => listStore.eventRequestPages, () => listStore.events],
() => {
requestLimit.value = listStore.eventRequestLimit;
requestPages.value = listStore.eventRequestPages;
posterEvents.value = listStore.events;
}
);
Expand All @@ -69,7 +69,7 @@ onMounted(async () => {
const loadPosterEvents = async () => {
const query = {
...debouncedEventsRequestQuery.value,
paginationOptions: { limit: requestLimit.value }
paginationOptions: { limit: maxRequests, page: requestPages }
};
const { data } = await apiRouter.events.findMany.useQuery({
data: {
Expand All @@ -83,7 +83,7 @@ const loadPosterEvents = async () => {
listStore.$patch({
events: data.value.docs
});
hasNextPage ? listStore.incrementRequestLimit(maxRequests) : null;
hasNextPage ? listStore.incrementRequestPages(pagesToLoad) : null;
}
};

Expand All @@ -103,6 +103,7 @@ const onButtonClick = () => {
:min-item-size="minItemCardSize"
:distance="distanceToLoadEvents"
:has-next-page="hasMorePages"
:prerender="maxRequests"
:size-dependencies="[
'description',
'title',
Expand Down
10 changes: 5 additions & 5 deletions frontend/stores/list.store.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { defineStore } from 'pinia'
import { maxRequests } from '@/constants/global'
import { pagesToLoad } from '@/constants/global'
import type { EventOnPoster } from '../../common/types'

type lastAction = 'NONE' | 'INDEX' | 'HEADER'

type listStore = {
needScrollList: boolean,
eventRequestLimit: number,
eventRequestPages: number,
events: EventOnPoster[] | null,
scrollTop: number,
lastAction: lastAction
Expand All @@ -15,14 +15,14 @@ type listStore = {
export const useListStore = defineStore('eventList', {
state: (): listStore => ({
needScrollList: false,
eventRequestLimit: maxRequests,
eventRequestPages: pagesToLoad,
events: [],
scrollTop: 0,
lastAction: 'NONE'
}),
actions: {
incrementRequestLimit(maxRequests: number) {
this.eventRequestLimit += maxRequests
incrementRequestPages(pagesToLoad: number) {
this.eventRequestPages += pagesToLoad
}
}
})