Implement program fetching and loading state in Programs component
- Added asynchronous fetching of program activities using getPrograms. - Introduced loading and error states to enhance user experience. - Refactored activity rendering to handle dynamic data and improved icon rendering logic.
This commit is contained in:
31
utils/programs.ts
Normal file
31
utils/programs.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
|
||||
import { FontAwesome, FontAwesome5, MaterialCommunityIcons } from '@expo/vector-icons';
|
||||
|
||||
export type ProgramActivity = {
|
||||
time: string;
|
||||
title: string;
|
||||
description: string;
|
||||
iconSet: 'FontAwesome' | 'FontAwesome5' | 'MaterialCommunityIcons';
|
||||
iconName: React.ComponentProps<typeof FontAwesome>['name'] | React.ComponentProps<typeof FontAwesome5>['name'] | React.ComponentProps<typeof MaterialCommunityIcons>['name'];
|
||||
transport?: string;
|
||||
};
|
||||
|
||||
export type ProgramActivities = {
|
||||
[date: string]: ProgramActivity[];
|
||||
};
|
||||
|
||||
const PROGRAMS_URL = 'http://kepilhyzmat.com/assets/programs.json';
|
||||
|
||||
export const getPrograms = async (): Promise<ProgramActivities> => {
|
||||
try {
|
||||
const response = await fetch(PROGRAMS_URL);
|
||||
if (!response.ok) {
|
||||
throw new Error(`Request failed with status ${response.status}`);
|
||||
}
|
||||
const data: ProgramActivities = await response.json();
|
||||
return data;
|
||||
} catch (error) {
|
||||
console.error('Failed to fetch programs:', error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user