|
@@ -0,0 +1,177 @@
|
|
|
|
+import React, { useRef, useState } from 'react';
|
|
|
|
+import { View, Text, Image, StyleSheet, TouchableOpacity, Platform } from 'react-native';
|
|
|
|
+import ActionSheet, { SheetManager } from 'react-native-actions-sheet';
|
|
|
|
+import { Colors } from 'src/theme';
|
|
|
|
+import { getFontSize } from 'src/utils';
|
|
|
|
+import { FlashList } from '@shopify/flash-list';
|
|
|
|
+
|
|
|
|
+const MultipleSeriesModal = () => {
|
|
|
|
+ const [seriesData, setSeriesData] = useState<any>(null);
|
|
|
|
+ const [markers, setMarkers] = useState<any[]>([]);
|
|
|
|
+
|
|
|
|
+ const shouldOpenWarningModalRef = useRef(false);
|
|
|
|
+
|
|
|
|
+ const handleSheetOpen = (payload: any) => {
|
|
|
|
+ setSeriesData(payload);
|
|
|
|
+ setMarkers(payload?.markers || []);
|
|
|
|
+ };
|
|
|
|
+
|
|
|
|
+ const handleToggleSeries = (item: any) => {
|
|
|
|
+ if (!seriesData) return;
|
|
|
|
+
|
|
|
|
+ if (!seriesData.token) {
|
|
|
|
+ shouldOpenWarningModalRef.current = true;
|
|
|
|
+ SheetManager.hide('multiple-series-modal');
|
|
|
|
+
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ seriesData.setSelectedMarker(item);
|
|
|
|
+
|
|
|
|
+ seriesData.toggleSeries(item);
|
|
|
|
+ setMarkers((prevMarkers) =>
|
|
|
|
+ prevMarkers.map((marker) =>
|
|
|
|
+ marker.id === item.id ? { ...marker, visited: item.visited === 1 ? 0 : 1 } : marker
|
|
|
|
+ )
|
|
|
|
+ );
|
|
|
|
+ };
|
|
|
|
+
|
|
|
|
+ const handleItemPress = (item: any) => {
|
|
|
|
+ if (!seriesData) return;
|
|
|
|
+
|
|
|
|
+ seriesData.setSelectedMarker(item);
|
|
|
|
+ SheetManager.hide('multiple-series-modal');
|
|
|
|
+ };
|
|
|
|
+
|
|
|
|
+ return (
|
|
|
|
+ <ActionSheet
|
|
|
|
+ id="multiple-series-modal"
|
|
|
|
+ gestureEnabled={Platform.OS === 'ios'}
|
|
|
|
+ onBeforeShow={(sheetRef) => {
|
|
|
|
+ const payload = sheetRef || null;
|
|
|
|
+ handleSheetOpen(payload);
|
|
|
|
+ }}
|
|
|
|
+ onClose={() => {
|
|
|
|
+ if (shouldOpenWarningModalRef.current) {
|
|
|
|
+ if (!seriesData) return;
|
|
|
|
+
|
|
|
|
+ shouldOpenWarningModalRef.current = false;
|
|
|
|
+ seriesData.setIsWarningModalVisible(true);
|
|
|
|
+ }
|
|
|
|
+ }}
|
|
|
|
+ containerStyle={styles.sheetContainer}
|
|
|
|
+ defaultOverlayOpacity={0.5}
|
|
|
|
+ >
|
|
|
|
+ {seriesData && (
|
|
|
|
+ <View style={styles.container}>
|
|
|
|
+ <FlashList
|
|
|
|
+ data={markers}
|
|
|
|
+ keyExtractor={(item, index) => item.id.toString() + index.toString()}
|
|
|
|
+ showsVerticalScrollIndicator={false}
|
|
|
|
+ renderItem={({ item }) => (
|
|
|
|
+ <TouchableOpacity style={styles.option} onPress={() => handleItemPress(item)}>
|
|
|
|
+ <View style={styles.imageContainer}>
|
|
|
|
+ <Image
|
|
|
|
+ source={{ uri: item.icon?.uri || '' }}
|
|
|
|
+ style={styles.icon}
|
|
|
|
+ resizeMode="contain"
|
|
|
|
+ />
|
|
|
|
+ <View style={{ justifyContent: 'space-between', flex: 1 }}>
|
|
|
|
+ <Text style={styles.name}>{item.series_name}</Text>
|
|
|
|
+ <Text style={styles.description}>{item.name}</Text>
|
|
|
|
+ </View>
|
|
|
|
+ </View>
|
|
|
|
+
|
|
|
|
+ <TouchableOpacity
|
|
|
|
+ onPress={() => handleToggleSeries(item)}
|
|
|
|
+ style={[styles.markButton, item.visited === 1 && styles.visitedButton]}
|
|
|
|
+ >
|
|
|
|
+ {item.visited === 1 ? (
|
|
|
|
+ <View style={styles.completedContainer}>
|
|
|
|
+ <Text style={[styles.calloutButtonText, { color: Colors.DARK_BLUE }]}>
|
|
|
|
+ Completed
|
|
|
|
+ </Text>
|
|
|
|
+ </View>
|
|
|
|
+ ) : (
|
|
|
|
+ <Text style={styles.calloutButtonText}>To Complete</Text>
|
|
|
|
+ )}
|
|
|
|
+ </TouchableOpacity>
|
|
|
|
+ </TouchableOpacity>
|
|
|
|
+ )}
|
|
|
|
+ estimatedItemSize={50}
|
|
|
|
+ />
|
|
|
|
+ </View>
|
|
|
|
+ )}
|
|
|
|
+ </ActionSheet>
|
|
|
|
+ );
|
|
|
|
+};
|
|
|
|
+
|
|
|
|
+const styles = StyleSheet.create({
|
|
|
|
+ sheetContainer: {
|
|
|
|
+ height: '85%',
|
|
|
|
+ borderTopLeftRadius: 15,
|
|
|
|
+ borderTopRightRadius: 15
|
|
|
|
+ },
|
|
|
|
+ container: {
|
|
|
|
+ minHeight: 200,
|
|
|
|
+ height: '100%',
|
|
|
|
+ backgroundColor: 'white',
|
|
|
|
+ paddingHorizontal: 16,
|
|
|
|
+ paddingTop: 8,
|
|
|
|
+ gap: 16
|
|
|
|
+ },
|
|
|
|
+ completedContainer: { flexDirection: 'row', alignItems: 'center', gap: 6 },
|
|
|
|
+ calloutButtonText: {
|
|
|
|
+ color: Colors.WHITE,
|
|
|
|
+ fontSize: getFontSize(13),
|
|
|
|
+ fontWeight: '700'
|
|
|
|
+ },
|
|
|
|
+ icon: {
|
|
|
|
+ width: 32,
|
|
|
|
+ height: 32
|
|
|
|
+ },
|
|
|
|
+ markButton: {
|
|
|
|
+ paddingHorizontal: 12,
|
|
|
|
+ paddingVertical: 6,
|
|
|
|
+ backgroundColor: Colors.ORANGE,
|
|
|
|
+ borderRadius: 6,
|
|
|
|
+ height: 30,
|
|
|
|
+ alignItems: 'center',
|
|
|
|
+ justifyContent: 'center'
|
|
|
|
+ },
|
|
|
|
+ visitedButton: {
|
|
|
|
+ backgroundColor: Colors.WHITE,
|
|
|
|
+ borderWidth: 1,
|
|
|
|
+ borderColor: Colors.BORDER_LIGHT
|
|
|
|
+ },
|
|
|
|
+ option: {
|
|
|
|
+ flexDirection: 'row',
|
|
|
|
+ alignItems: 'center',
|
|
|
|
+ justifyContent: 'space-between',
|
|
|
|
+ backgroundColor: Colors.FILL_LIGHT,
|
|
|
|
+ paddingVertical: 8,
|
|
|
|
+ paddingHorizontal: 12,
|
|
|
|
+ borderRadius: 8,
|
|
|
|
+ marginBottom: 6
|
|
|
|
+ },
|
|
|
|
+ imageContainer: {
|
|
|
|
+ flexDirection: 'row',
|
|
|
|
+ alignItems: 'center',
|
|
|
|
+ gap: 8,
|
|
|
|
+ flex: 1,
|
|
|
|
+ marginRight: 8
|
|
|
|
+ },
|
|
|
|
+ name: {
|
|
|
|
+ fontSize: getFontSize(14),
|
|
|
|
+ fontFamily: 'montserrat-700',
|
|
|
|
+ color: Colors.DARK_BLUE,
|
|
|
|
+ flex: 1
|
|
|
|
+ },
|
|
|
|
+ description: {
|
|
|
|
+ fontSize: getFontSize(12),
|
|
|
|
+ fontWeight: '600',
|
|
|
|
+ color: Colors.DARK_BLUE,
|
|
|
|
+ flex: 1
|
|
|
|
+ }
|
|
|
|
+});
|
|
|
|
+
|
|
|
|
+export default MultipleSeriesModal;
|