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:
Mekan1206
2025-09-20 13:21:20 +05:00
parent 803bbfc30f
commit 3ee7ec87be
2 changed files with 120 additions and 63 deletions

31
utils/programs.ts Normal file
View 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;
}
};