// Importing the useState hook to manage component state
import { useState } from 'react';
// Importing React Native core components
import {
View, Text,
StyleSheet, TouchableOpacity
} from 'react-native';
// Importing Ionicons from react-native-vector-icons for using icons
import Icon from 'react-native-vector-icons/Ionicons';
// Main functional component
const DashboardApp = () => {
// Declaring state variable to track the currently active section
const [activeSection, setActiveSection] = useState('Home');
// Function to render the component based on the selected section
const renderSection = () => {
switch (activeSection) {
case 'Profile':
return <ProfileSection />;
case 'Settings':
return <SettingsSection />;
case 'Analytics':
return <AnalyticsSection />;
case 'Messages':
return <MessagesSection />;
case 'Tasks':
return <TasksSection />;
case 'Calendar':
return <CalendarSection />;
default:
return <HomeSection />; // Fallback to Home
}
};
// Function to render a back button that returns to the Home section
const renderBackButton = () => (
<TouchableOpacity
onPress={() => setActiveSection('Home')}
style={styles.backButton}>
<Icon name="arrow-back" size={30} color="#000000" />
<Text style={styles.backButtonText}>Back to Home</Text>
</TouchableOpacity>
);
// Component for the Home section of the dashboard
const HomeSection = () => (
<View style={styles.container}>
<View style={styles.headerContainer}>
<Text style={styles.headerTitle}>Welcome to the Dashboard!</Text>
<View style={styles.buttonsContainer}>
{/* Profile button */}
<TouchableOpacity
onPress={() => setActiveSection('Profile')}
style={styles.button}>
<Icon name="person" size={30} color="white" />
<Text style={styles.buttonText}>Profile</Text>
</TouchableOpacity>
{/* Settings button */}
<TouchableOpacity
onPress={() => setActiveSection('Settings')}
style={styles.button}>
<Icon name="settings" size={30} color="white" />
<Text style={styles.buttonText}>Settings</Text>
</TouchableOpacity>
</View>
</View>
{/* Features grid */}
<View style={styles.featuresContainer}>
{/* Analytics feature */}
<PressableFeatureBox name="Analytics" icon="stats-chart" onPress={() => setActiveSection('Analytics')} />
{/* Messages feature */}
<PressableFeatureBox name="Messages" icon="chatbox" onPress={() => setActiveSection('Messages')} />
{/* Tasks feature */}
<PressableFeatureBox name="Tasks" icon="checkbox-outline" onPress={() => setActiveSection('Tasks')} />
{/* Calendar feature */}
<PressableFeatureBox name="Calendar" icon="calendar" onPress={() => setActiveSection('Calendar')} />
</View>
</View>
);
// Profile section component
const ProfileSection = () => (
<View style={styles.container}>
<View style={styles.headerContainer}>
{renderBackButton()}
<Text style={styles.headerTitle}>Profile Section</Text>
</View>
<View style={styles.contentContainer}>
<Icon name="person" size={80} color="#3498db" />
<Text style={styles.contentText}>Username: gfg</Text>
<Text style={styles.contentText}>Email: gfg@gmail.com</Text>
</View>
</View>
);
// Settings section component
const SettingsSection = () => (
<View style={styles.container}>
<View style={styles.headerContainer}>
{renderBackButton()}
<Text style={styles.headerTitle}>Settings Section</Text>
</View>
<View style={styles.contentContainer}>
<Icon name="settings" size={80} color="#3498db" />
<Text style={styles.contentText}>Notifications: On</Text>
<Text style={styles.contentText}>Theme: Light</Text>
</View>
</View>
);
// Reusable component for each feature box in the Home section
const PressableFeatureBox = ({ name, icon, onPress }) => (
<TouchableOpacity onPress={onPress} style={styles.featureBox}>
<Icon name={icon} size={50} color="#3498db" />
<Text style={styles.featureName}>{name}</Text>
</TouchableOpacity>
);
// Analytics section component
const AnalyticsSection = () => (
<View style={styles.container}>
<View style={styles.headerContainer}>
{renderBackButton()}
<Text style={styles.headerTitle}>Analytics Section</Text>
</View>
<View style={styles.contentContainer}>
<Text style={styles.contentText}>Analytics Content Goes Here</Text>
</View>
</View>
);
// Messages section component
const MessagesSection = () => (
<View style={styles.container}>
<View style={styles.headerContainer}>
{renderBackButton()}
<Text style={styles.headerTitle}>Messages Section</Text>
</View>
<View style={styles.contentContainer}>
<Text style={styles.contentText}>Messages Content Goes Here</Text>
</View>
</View>
);
// Tasks section component with task items
const TasksSection = () => (
<View style={styles.container}>
<View style={styles.headerContainer}>
{renderBackButton()}
<Text style={styles.headerTitle}>Tasks Section</Text>
</View>
<View style={styles.contentContainer}>
<Text style={styles.contentTitle}>Upcoming Tasks</Text>
<TaskItem title="Task 1" description="Geekforgeeks contest." />
<TaskItem title="Task 2" description="mock interview" />
<TaskItem title="Task 3" description="Sample paper solution." />
</View>
</View>
);
// Calendar section component with events
const CalendarSection = () => (
<View style={styles.container}>
<View style={styles.headerContainer}>
{renderBackButton()}
<Text style={styles.headerTitle}>Calendar Section</Text>
</View>
<View style={styles.contentContainer}>
<Text style={styles.contentTitle}>Events This Week</Text>
<EventItem
date="Mon, Jan 10"
time="3:00 PM - 5:00 PM"
title="Meeting with Team"
location="Office Conference Room"
/>
<EventItem
date="Thu, Jan 13"
time="10:00 AM - 12:00 PM"
title="Client Presentation"
location="Online"
/>
<EventItem
date="Sat, Jan 15"
time="6:00 PM - 8:00 PM"
title="Dinner with Friends"
location="Local Restaurant"
/>
</View>
</View>
);
// Component to show each task item
const TaskItem = ({ title, description }) => (
<View style={styles.taskItem}>
<Text style={styles.taskTitle}>{title}</Text>
<Text style={styles.taskDescription}>{description}</Text>
</View>
);
// Component to show each calendar event
const EventItem = ({ date, time, title, location }) => (
<View style={styles.eventItem}>
<View style={styles.eventDateTime}>
<Text style={styles.eventDate}>{date}</Text>
<Text style={styles.eventTime}>{time}</Text>
</View>
<Text style={styles.eventTitle}>{title}</Text>
<Text style={styles.eventLocation}>{location}</Text>
</View>
);
// Render the currently selected section
return renderSection();
};
// Style definitions for all UI components
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#f4f6f8',
},
headerContainer: {
backgroundColor: '#3498db',
paddingVertical: 24,
paddingHorizontal: 20,
borderBottomLeftRadius: 24,
borderBottomRightRadius: 24,
elevation: 8,
shadowColor: '#000',
shadowOpacity: 0.2,
shadowRadius: 5,
shadowOffset: { width: 0, height: 3 },
},
headerTitle: {
fontSize: 26,
fontWeight: '700',
color: '#fff',
marginBottom: 12,
},
buttonsContainer: {
flexDirection: 'row',
justifyContent: 'space-around',
marginTop: 10,
},
button: {
flexDirection: 'row',
alignItems: 'center',
backgroundColor: '#2ecc71',
paddingVertical: 12,
paddingHorizontal: 16,
borderRadius: 10,
elevation: 3,
},
buttonText: {
color: 'white',
fontSize: 16,
fontWeight: '600',
marginLeft: 10,
},
featuresContainer: {
flex: 1,
flexDirection: 'row',
flexWrap: 'wrap',
justifyContent: 'space-around',
padding: 16,
},
featureBox: {
alignItems: 'center',
justifyContent: 'center',
width: '42%',
aspectRatio: 1,
backgroundColor: '#ffffff',
borderRadius: 20,
marginVertical: 12,
elevation: 5,
shadowColor: '#aaa',
shadowOpacity: 0.3,
shadowOffset: { width: 0, height: 3 },
},
featureName: {
marginTop: 10,
fontSize: 15,
fontWeight: '600',
color: '#333',
},
backButton: {
flexDirection: 'row',
alignItems: 'center',
marginBottom: 12,
},
backButtonText: {
color: '#ffffff',
fontSize: 16,
fontWeight: '600',
marginLeft: 10,
},
contentContainer: {
flex: 1,
padding: 20,
backgroundColor: '#fff',
margin: 12,
borderRadius: 12,
elevation: 3,
},
contentText: {
fontSize: 16,
marginBottom: 10,
color: '#333',
},
contentTitle: {
fontSize: 18,
fontWeight: '700',
color: '#2c3e50',
marginBottom: 16,
},
taskItem: {
backgroundColor: '#ecf0f1',
padding: 16,
borderRadius: 12,
marginBottom: 12,
},
taskTitle: {
fontSize: 16,
fontWeight: '600',
color: '#2c3e50',
},
taskDescription: {
fontSize: 14,
color: '#7f8c8d',
},
eventItem: {
backgroundColor: '#ecf0f1',
padding: 16,
borderRadius: 12,
marginBottom: 12,
},
eventDateTime: {
flexDirection: 'row',
justifyContent: 'space-between',
},
eventDate: {
fontSize: 14,
color: '#34495e',
fontWeight: '500',
},
eventTime: {
fontSize: 14,
color: '#34495e',
fontWeight: '500',
},
eventTitle: {
fontSize: 16,
fontWeight: '600',
marginTop: 6,
color: '#2c3e50',
},
eventLocation: {
fontSize: 14,
color: '#7f8c8d',
},
});
export default DashboardApp;