From c88b17bb269cc50577aabdd12890532e9460d6d8 Mon Sep 17 00:00:00 2001 From: Netcup Gituser Date: Tue, 19 Dec 2023 16:41:31 +0100 Subject: [PATCH] better list handling --- src/pages/calendar/calendar.tsx | 69 +++++++++++++++++++++++++++------ 1 file changed, 57 insertions(+), 12 deletions(-) diff --git a/src/pages/calendar/calendar.tsx b/src/pages/calendar/calendar.tsx index 7707f10..44e6523 100644 --- a/src/pages/calendar/calendar.tsx +++ b/src/pages/calendar/calendar.tsx @@ -1,6 +1,7 @@ import {MyTouchableOpacity} from '@components/MyTouchableOpacity'; -import {Text} from '@gluestack-ui/themed'; +import {Spinner, Text} from '@gluestack-ui/themed'; import {RootState} from '@redux/store'; +import {useState} from 'react'; import {Image} from 'react-native'; import {FlatList} from 'react-native'; import {View} from 'react-native'; @@ -13,17 +14,11 @@ const baseUrls = [ 'https://i.ytimg.com/vi/RDrJ1VmRi0w/hqdefault.jpg', ]; -const events: ArrayLike | null | undefined = []; - -for (let i = 1; i <= 100; i++) { - const randomUrlIndex = Math.floor(Math.random() * baseUrls.length); - - events.push({ - id: i, - url: baseUrls[randomUrlIndex], - title: 'Bootshaus', - description: '01.12.2023 20:00 Uhr', - }); +interface Event { + id: number; + url: string; + title: string; + description: string; } /* @@ -59,6 +54,28 @@ export function CalendarScreen() { (state: RootState) => state.nonSaveVariables.theme.colors, ); + const [refreshing, setRefreshing] = useState(false); + //const [paginationPage, setPaginationPage] = useState(1); + + const newEvents = () => { + let list = []; + + for (let i = 1; i <= 10; i++) { + const randomUrlIndex = Math.floor(Math.random() * baseUrls.length); + + list.push({ + id: i, + url: baseUrls[randomUrlIndex], + title: 'Bootshaus', + description: '01.12.2023 20:00 Uhr', + }); + } + + return list; + }; + + const [events, setEvents] = useState(newEvents()); + return ( )} + refreshing={refreshing} + onRefresh={() => { + console.log('refresh'); + + setRefreshing(true); + + setTimeout(() => { + setRefreshing(false); + }, 1000); + }} + onEndReached={() => { + console.log('end reached'); + + setEvents([...events, ...newEvents()]); + }} + onEndReachedThreshold={0} + ListFooterComponent={() => { + return ( + + + + ); + }} /> );