import React, { useEffect, useState, useCallback, useContext, useRef } from 'react'; import { Link, router, useFocusEffect } from 'expo-router'; import Image from '@/components/Image'; import { StyleSheet, useWindowDimensions, ScrollView, Pressable, RefreshControl } from 'react-native'; import { SafeAreaView } from 'react-native-safe-area-context'; import { Icon, MD3Colors, Button, Text, TextInput, TouchableRipple } from 'react-native-paper'; import CountryFlag from "react-native-country-flag"; import Dropdown from '@/components/dropdown'; import Theme from '@/constants/theme'; import { __styles } from './stylesheet/styles'; import Storage from '@/constants/module/storages/storage'; import ImageStorage from '@/constants/module/storages/image_cache_storage'; import { CONTEXT } from '@/constants/module/context'; import { get_list } from '@/app/explore/module/content' import { transformAsync } from '@babel/core'; import { View, AnimatePresence } from 'moti'; import { PageNavigationWidget } from './components/widgets'; const Index = ({}:any) => { const Dimensions = useWindowDimensions(); const {showMenuContext, setShowMenuContext}:any = useContext(CONTEXT) const {themeTypeContext, setThemeTypeContext}:any = useContext(CONTEXT) const {apiBaseContext, setApiBaseContext}:any = useContext(CONTEXT) const {widgetContext, setWidgetContext}:any = useContext(CONTEXT) const {showCloudflareTurnstileContext, setShowCloudflareTurnstileContext}:any = useContext(CONTEXT) const [styles, setStyles]:any = useState("") const [CONTENT, SET_CONTENT]:any = useState([]) const [isLoading, setIsLoading]:any = useState(true); const [refreshing, setRefreshing] = useState(false); const [feedBack, setFeedBack] = useState("") const scrollOffset = useRef(0); const [showOption, setShowOption]:any = useState({type:null}) const [translate, setTranslate]:any = useState({}); const [search, setSearch]:any = useState({text:"",type:1}); const [source, setSource]:any = useState("colamanga") const [page, setPage] = useState(1); const controller = new AbortController(); const signal = controller.signal; useFocusEffect(useCallback(() => { setShowMenuContext(true) return () => { }; }, [])) useFocusEffect(useCallback(() => { (async ()=>{ setStyles(__styles(themeTypeContext,Dimensions)) let __translate:any = await Storage.get("explore_translate") if (!__translate) { __translate = {state:false,from:"auto",to:"en"} await Storage.store("explore_translate",__translate) }else __translate = __translate setTranslate(__translate) get_list(setShowCloudflareTurnstileContext,setFeedBack,signal,setIsLoading,__translate,SET_CONTENT,search,page) })() return () => { controller.abort(); }; },[])) const onRefresh = () => { if (!(styles && themeTypeContext && apiBaseContext)) return setIsLoading(true); SET_CONTENT([]) get_list(setShowCloudflareTurnstileContext,setFeedBack,signal,setIsLoading,translate,SET_CONTENT,search,page) } useEffect(()=>{ onRefresh() },[page]) return (<>{(styles && !isLoading) ? <> { if (!isLoading) onRefresh() }} /> } > Explore { if (showOption.type === "translate"){ setShowOption({type:null}) }else{ setShowOption({type:"translate"}) } }} > { if (showOption.type === "search"){ setShowOption({type:null}) }else{ setShowOption({type:"search"}) } }} > {showOption.type === "translate" && { setTranslate({...translate,from:item.value}) await Storage.store("explore_translate",{...translate,from:item.value}) }} /> { setTranslate({...translate,to:item.value}) await Storage.store("explore_translate",{...translate,to:item.value}) }} /> } {showOption.type === "search" && { setSearch({...search,text:event.nativeEvent.text}) }} /> { setSearch({...search,type:item.value}) }} /> } {feedBack ? {feedBack} : <> {CONTENT.map((item:any,index:number)=>( {router.navigate(`/view/${source}/${item.id}`)}} key={index} style={styles.item_box} > <> {console.log("load image error",error)}} source={{uri:`${apiBaseContext}${item.cover}`}} style={styles.item_cover} contentFit="cover" transition={1000} /> {item.title} ))} } {CONTENT.length ? : <> } : }); } export default Index;