Spaces:
Sleeping
Sleeping
File size: 14,797 Bytes
cd23862 8f79bc5 cd23862 8f79bc5 cd23862 8f79bc5 cd23862 8f79bc5 cd23862 8f79bc5 cd23862 8f79bc5 cd23862 8f79bc5 cd23862 8f79bc5 cd23862 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 |
import React, { useEffect, useState, useCallback, useContext, useRef, useMemo } from 'react';
import { Link, router, useLocalSearchParams, useFocusEffect } from 'expo-router';
import { Image as RNImage, StyleSheet, useWindowDimensions, ScrollView, Pressable, RefreshControl, Platform, FlatList, TouchableOpacity } from 'react-native';
import { SafeAreaView } from 'react-native-safe-area-context';
import { Icon, MD3Colors, Button, Text, TextInput, TouchableRipple } from 'react-native-paper';
import CircularProgress from 'react-native-circular-progress-indicator';
import { ActivityIndicator } from 'react-native-paper';
import { FlashList } from "@shopify/flash-list";
import uuid from 'react-native-uuid';
import Toast from 'react-native-toast-message';
import { View, AnimatePresence } from 'moti';
import * as Clipboard from 'expo-clipboard';
import * as FileSystem from 'expo-file-system';
import NetInfo from "@react-native-community/netinfo";
import { Marquee } from '@animatereactnative/marquee';
import { Slider } from '@rneui/themed-edge';
import BookmarkComponent from './components/bookmark_component';
import ComicComponent from './components/comic_component';
import BookmarkWidget from './components/widgets/bookmark';
import { __styles } from './stylesheet/styles';
import Storage from '@/constants/module/storages/storage';
import ChapterStorage from '@/constants/module/storages/chapter_storage';
import Image from '@/components/Image';
import {CONTEXT} from '@/constants/module/context';
import {blobToBase64, base64ToBlob, getImageLayout} from "@/constants/module/file_manager";
import Theme from '@/constants/theme';
import ComicStorage from '@/constants/module/storages/comic_storage';
const Index = ({}:any) => {
const Dimensions = useWindowDimensions();
const controller = new AbortController();
const signal = controller.signal;
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 [isLoading, setIsLoading] = useState<boolean>(true)
const [onRefresh, setOnRefresh] = useState(false)
const [search, setSearch] = useState<any>({state:false,text:""})
const [BOOKMARK_DATA, SET_BOOKMARK_DATA]:any = useState([])
const [SELECTED_BOOKMARK, SET_SELECTED_BOOKMARK] = useState<string>("")
const [COMIC_DATA, SET_COMIC_DATA] = useState<any>([])
const [reRender, setReRender] = useState(false)
const max_column = useRef(0)
useFocusEffect(useCallback(() => {
if (!reRender) return
else setReRender(false)
},[reRender]))
useFocusEffect(useCallback(() => {
const item_box = Math.max(((Dimensions.width+Dimensions.height)/2)*0.225,100) + (Math.max((Dimensions.width+Dimensions.height)/2*0.015,8))*2;
const number_of_column = Math.floor((Dimensions.width-(((Dimensions.width+Dimensions.height)/2)*0.035)-32)/item_box)
if (max_column.current !== number_of_column) {
max_column.current = number_of_column
setReRender(true)
}
}, [Dimensions]))
// First load + Refresh ->
useFocusEffect(useCallback(() => {
(async ()=>{
if (!onRefresh) return
else setOnRefresh(false)
})()
},[onRefresh]))
useFocusEffect(useCallback(() => {
(async ()=>{
if (!SELECTED_BOOKMARK) return
const stored_comic = await ComicStorage.getByTag(SELECTED_BOOKMARK)
SET_COMIC_DATA(stored_comic)
})()
},[SELECTED_BOOKMARK]))
useFocusEffect(useCallback(() => {
(async ()=>{
setIsLoading(true)
const stored_bookmark = await Storage.get("bookmark") || []
SET_BOOKMARK_DATA(stored_bookmark)
if (stored_bookmark.length) {
SET_SELECTED_BOOKMARK(stored_bookmark[0])
}
setIsLoading(false)
})()
},[onRefresh]))
const renderBookmarkComponent = useCallback(({item,index}:any) => {
return <BookmarkComponent key={index.toString()} item={item}
SELECTED_BOOKMARK={SELECTED_BOOKMARK} SET_SELECTED_BOOKMARK={SET_SELECTED_BOOKMARK}
/>
},[SELECTED_BOOKMARK])
const renderComicComponent = useCallback(({item,index}:any) => {
return <ComicComponent key={index.toString()} item={item}
/>
},[SELECTED_BOOKMARK])
useFocusEffect(useCallback(() => {
setIsLoading(true)
setShowMenuContext(true)
setStyles(__styles(themeTypeContext,Dimensions))
return () => {
controller.abort();
};
},[]))
// <- End
return (<>{styles && ! isLoading
? <>
<View style={styles.screen_container}
>
<View style={styles.header_container}>
<Text style={styles.header_text}>Bookmark</Text>
<View style={styles.header_button_box}>
<TouchableRipple
rippleColor={Theme[themeTypeContext].ripple_color_outlined}
style={{
...styles.header_search_button,
backgroundColor: search.state ? Theme[themeTypeContext].button_selected_color : "transparent",
}}
onPress={() => {
setSearch({...search,state:!search.state})
}}
>
<Icon source={"magnify"} size={((Dimensions.width+Dimensions.height)/2)*0.04} color={Theme[themeTypeContext].icon_color}/>
</TouchableRipple>
</View>
</View>
<>{search.state && (
<View
style={{
width:"100%",
height:"auto",
paddingHorizontal:12,
paddingVertical:18,
borderBottomWidth:2,
borderColor:Theme[themeTypeContext].border_color,
}}
>
<TextInput mode="outlined" label="Search" textColor={Theme[themeTypeContext].text_color}
style={{
backgroundColor:Theme[themeTypeContext].background_color,
borderColor:Theme[themeTypeContext].border_color,
}}
outlineColor={Theme[themeTypeContext].text_input_border_color}
value={search.text}
onChange={(event)=>{
setSearch({...search,text:event.nativeEvent.text})
}}
/>
</View>
)}</>
<View
style={{
display:"flex",
flexDirection:"row",
width:"100%",
height:"auto",
backgroundColor:"transparent",
borderBottomWidth:2,
borderColor:Theme[themeTypeContext].border_color,
}}
>
<FlatList
contentContainerStyle={{
flex:1,
flexGrow: 1,
}}
horizontal={true}
data={BOOKMARK_DATA}
renderItem={renderBookmarkComponent}
ItemSeparatorComponent={undefined}
/>
<TouchableRipple
rippleColor={Theme[themeTypeContext].ripple_color_outlined}
style={{
borderRadius:5,
borderWidth:0,
backgroundColor: "transparent",
padding:5,
justifyContent:"center",
alignItems:"center",
}}
onPress={() => {
setWidgetContext({state:true,component:
<BookmarkWidget
setIsLoading={setIsLoading}
onRefresh={()=>{setOnRefresh(true)}}
/>
})
}}
>
<Icon source={require("@/assets/icons/tag-edit-outline.png")} size={((Dimensions.width+Dimensions.height)/2)*0.0325} color={Theme[themeTypeContext].icon_color}/>
</TouchableRipple>
</View>
<>{!reRender && (
<FlatList
contentContainerStyle={{
padding:12,
marginHorizontal:"auto",
}}
numColumns={max_column.current}
renderItem={renderComicComponent}
ItemSeparatorComponent={undefined}
data={COMIC_DATA.filter((item:any) => item.info.title.toLowerCase().includes(search.text.toLowerCase()))}
ListEmptyComponent={
<View
style={{
width:"100%",
height:"100%",
backgroundColor:"transparent",
display:"flex",
justifyContent:"center",
alignItems:"center",
flexDirection:"row",
gap:12,
}}
>
<>{BOOKMARK_DATA.length
? <>
{search.text && COMIC_DATA.length
? <>
<Icon source={"magnify-scan"} color={Theme[themeTypeContext].icon_color} size={((Dimensions.width+Dimensions.height)/2)*0.03}/>
<Text selectable={false}
style={{
fontFamily:"roboto-bold",
fontSize:((Dimensions.width+Dimensions.height)/2)*0.025,
color:Theme[themeTypeContext].text_color,
}}
>Search no result</Text>
</>
: <>
<Icon source={require("@/assets/icons/tag-hidden.png")} color={Theme[themeTypeContext].icon_color} size={((Dimensions.width+Dimensions.height)/2)*0.03}/>
<Text selectable={false}
style={{
fontFamily:"roboto-bold",
fontSize:((Dimensions.width+Dimensions.height)/2)*0.025,
color:Theme[themeTypeContext].text_color,
}}
>This tag is empty.</Text>
</>
}
</>
: <View style={{
display:"flex",
flexDirection:"column",
justifyContent:"center",
alignItems:"center",
width:"100%",
height:"auto",
}}>
<Text selectable={false}
style={{
fontFamily:"roboto-bold",
fontSize:((Dimensions.width+Dimensions.height)/2)*0.025,
color:Theme[themeTypeContext].text_color,
textAlign:"center",
}}
>
No tag found. {"\n"}Press{" "}
<Icon source={require("@/assets/icons/tag-edit-outline.png")} color={Theme[themeTypeContext].icon_color} size={((Dimensions.width+Dimensions.height)/2)*0.03}/>
{" "}to create bookmark tag.
</Text>
</View>
}
</>
</View>
}
/>
)}</>
</View>
</>
: <View style={{zIndex:5,width:"100%",height:"100%",display:"flex",justifyContent:"center",alignItems:"center",backgroundColor:Theme[themeTypeContext].background_color}}>
<Image setShowCloudflareTurnstile={setShowCloudflareTurnstileContext} source={require("@/assets/gif/cat-loading.gif")} style={{width:((Dimensions.width+Dimensions.height)/2)*0.15,height:((Dimensions.width+Dimensions.height)/2)*0.15}}/>
</View>
}</>)
}
export default Index;
|