better list handling

master
Netcup Gituser 2023-12-19 16:41:31 +01:00
parent cc569a8187
commit c88b17bb26
1 changed files with 57 additions and 12 deletions

View File

@ -1,6 +1,7 @@
import {MyTouchableOpacity} from '@components/MyTouchableOpacity'; import {MyTouchableOpacity} from '@components/MyTouchableOpacity';
import {Text} from '@gluestack-ui/themed'; import {Spinner, Text} from '@gluestack-ui/themed';
import {RootState} from '@redux/store'; import {RootState} from '@redux/store';
import {useState} from 'react';
import {Image} from 'react-native'; import {Image} from 'react-native';
import {FlatList} from 'react-native'; import {FlatList} from 'react-native';
import {View} from 'react-native'; import {View} from 'react-native';
@ -13,17 +14,11 @@ const baseUrls = [
'https://i.ytimg.com/vi/RDrJ1VmRi0w/hqdefault.jpg', 'https://i.ytimg.com/vi/RDrJ1VmRi0w/hqdefault.jpg',
]; ];
const events: ArrayLike<any> | null | undefined = []; interface Event {
id: number;
for (let i = 1; i <= 100; i++) { url: string;
const randomUrlIndex = Math.floor(Math.random() * baseUrls.length); title: string;
description: string;
events.push({
id: i,
url: baseUrls[randomUrlIndex],
title: 'Bootshaus',
description: '01.12.2023 20:00 Uhr',
});
} }
/* /*
@ -59,6 +54,28 @@ export function CalendarScreen() {
(state: RootState) => state.nonSaveVariables.theme.colors, (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 ( return (
<View> <View>
<FlatList <FlatList
@ -94,6 +111,34 @@ export function CalendarScreen() {
</View> </View>
</MyTouchableOpacity> </MyTouchableOpacity>
)} )}
refreshing={refreshing}
onRefresh={() => {
console.log('refresh');
setRefreshing(true);
setTimeout(() => {
setRefreshing(false);
}, 1000);
}}
onEndReached={() => {
console.log('end reached');
setEvents([...events, ...newEvents()]);
}}
onEndReachedThreshold={0}
ListFooterComponent={() => {
return (
<View
style={{
height: 40,
justifyContent: 'center',
alignItems: 'center',
}}>
<Spinner />
</View>
);
}}
/> />
</View> </View>
); );