import { StyleSheet, ScrollView, SafeAreaView, StatusBar, Image, TouchableOpacity } from 'react-native'; import React, { useState, useEffect, useRef } from 'react'; import { router } from 'expo-router'; import type { AutocompleteDropdownRef } from 'react-native-autocomplete-dropdown' import { AutocompleteDropdown } from 'react-native-autocomplete-dropdown'; import Modal from "react-native-modal"; import { useTranslation } from 'react-i18next'; import { ThemedText } from '@/src/components/themed/ThemedText'; import { ThemedView } from '@/src/components/themed/ThemedView'; import { Colors } from '@/src/constants/Colors'; import { useColorScheme } from '@/src/hooks/useColorScheme'; import { Request } from '@/src/services/request'; import List from '@/src/components/List'; import { store } from '@/src/store/store'; import { setViewCategory } from '@/src/store/dataStore'; export default function ExploreScreen() { const colorScheme = useColorScheme() ?? 'light'; const { t } = useTranslation(); const [ categories, setCategories ] = useState( [] ); const [ types, setTypes ] = useState( [] ); const [ activeCategory, setActiveCategory ] = useState( null ); const searchRef = useRef( null ); const dropdownController = useRef( null ) useEffect( () => { // Load categories Request.get( 'categories' ).then( (response) => { const list: any = []; response.forEach( (category: any, index: any) => { list.push( { id: index, title: category.name, category: category, } ) } ); setCategories( list ); } ) // Load waste types Request.get( 'waste-types' ).then( (response) => { setTypes( response ); } ); }, [] ); // View selected item in modal const selectItem = (item: any | null) => { if (item == null) { return; } // Clear select dropdownController.current?.clear() const { category } = item; setActiveCategory( category ); } // View item in sub screen const viewItem = async (item: any) => { store.dispatch( setViewCategory( item ) ); router.push( '/(explore)/category' ); }; return ( {t( "what-where" )} {t( "what-why" )} {t( "what-separate" )} { dropdownController.current = controller }} textInputProps={{ placeholder: t( "what-separate" ), autoCorrect: false, autoCapitalize: 'none', }} clearOnFocus={false} closeOnBlur={false} closeOnSubmit={false} emptyResultText={t( "nothing-found" )} onSelectItem={selectItem} dataSet={categories} showClear={false} /> {t( "choose-category" )}: ( viewItem( item )}> {item.image != null ? ( ) : ( ) } {item.name} )} /> {activeCategory?.name} {activeCategory?.type && {activeCategory?.type?.image && } {activeCategory?.type?.name} } {t( "description" )}: {activeCategory?.description} setActiveCategory( null )} style={{ ...styles.modalClose, backgroundColor: Colors[ colorScheme ].tint }}> {t( "close" )} ); } const styles = StyleSheet.create( { container: { marginTop: StatusBar.currentHeight, padding: 25, }, titleContainer: { flexDirection: 'row', alignItems: 'center', gap: 8, paddingBottom: 8, }, searchContainer: { marginTop: 10, }, categoriesContainer: { marginTop: 25, }, listContainer: { marginTop: 20, paddingBottom: 50 }, listItem: { flex: 1, display: 'flex', gap: 8, flexDirection: 'row', alignItems: 'center', paddingBottom: 20, marginBottom: 20, borderBottomWidth: 1, borderBottomColor: '#f2f2f2', }, listImage: { width: 30, height: 30, borderRadius: 5, marginRight: 8, }, modalView: { margin: 20, borderRadius: 5, padding: 35, alignItems: 'center', textAlign: 'center', }, modalType: { gap: 8, flexDirection: 'row', alignItems: 'center', paddingBottom: 10, marginBottom: 15, }, modalTypeImage: { width: 40, height: 40, borderRadius: 5, marginRight: 8, }, modalClose: { borderRadius: 5, paddingTop: 10, paddingBottom: 10, paddingLeft: 40, paddingRight: 40, marginTop: 30, }, } );