- 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.
32 lines
996 B
TypeScript
32 lines
996 B
TypeScript
|
|
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;
|
|
}
|
|
};
|