import React, { useEffect, useState } from 'react'; import { Linking, SafeAreaView, ScrollView, StyleSheet, Text, TouchableOpacity, View } from 'react-native'; import { Item } from 'types/Item'; const API_URL = "http://192.168.178.22:8000"; export default function HomeScreen() { const [data, setData] = useState([]); const [selected, setSelected] = useState<'home' | 'royal-road' | 'podcasts' | 'mixtapes'>('home'); const [menuOpen, setMenuOpen] = useState(false); useEffect(() => { fetch(API_URL) .then(res => res.json()) .then(json => { if (json.status === "ok" && Array.isArray(json.data)) { setData(json.data); } }) .catch(err => console.error("API error:", err)); }, []); // Filter items for current category const filteredData = selected === "home" ? data : data.filter(item => item.category === selected); const menuItems = [ { label: 'Home', key: 'home' }, { label: 'Royal Road', key: 'royal-road' }, { label: 'Podcasts', key: 'podcasts' }, { label: 'Mixtapes', key: 'mixtapes' }, ]; return ( {/* Side Menu */} {menuItems.map(item => ( { setSelected(item.key as any); setMenuOpen(false); }} > {item.label} ))} {/* Main Content */} setMenuOpen(!menuOpen)}> {selected === 'home' && 'Welcome to Home!'} {selected === 'royal-road' && 'Royal Road Updates'} {selected === 'podcasts' && 'Latest Podcasts'} {selected === 'mixtapes' && 'New Mixtapes'} {filteredData.map(item => ( {item.title} {item.info} Linking.openURL(item.link)}> Read more ))} ); } const styles = StyleSheet.create({ container: { flex: 1, flexDirection: 'row', backgroundColor: '#f2f2f2', }, sideMenu: { width: 0, backgroundColor: '#333', paddingTop: 40, paddingHorizontal: 0, overflow: 'hidden', }, sideMenuOpen: { width: 180, paddingHorizontal: 16, }, menuItem: { paddingVertical: 16, paddingHorizontal: 8, borderRadius: 4, marginBottom: 8, }, menuItemSelected: { backgroundColor: '#555', }, menuText: { color: '#fff', fontSize: 18, }, mainContent: { flex: 1, justifyContent: 'center', alignItems: 'center', position: 'relative', }, menuButton: { position: 'absolute', top: 40, left: 16, zIndex: 1, backgroundColor: '#333', borderRadius: 20, padding: 8, }, menuButtonText: { color: '#fff', fontSize: 24, }, title: { fontSize: 24, fontWeight: 'bold', marginTop: 60, color: '#333', }, dataContainer: { marginTop: 24, width: '90%', }, dataItem: { backgroundColor: '#fff', borderRadius: 8, padding: 16, marginBottom: 12, shadowColor: '#000', shadowOpacity: 0.05, shadowRadius: 4, elevation: 2, }, dataTitle: { fontSize: 18, fontWeight: 'bold', color: '#222', marginBottom: 4, }, dataDescription: { fontSize: 15, color: '#555', }, });