diff --git a/screens/HistoryScreen.tsx b/screens/HistoryScreen.tsx index 8d9c4d8..d4fff4b 100644 --- a/screens/HistoryScreen.tsx +++ b/screens/HistoryScreen.tsx @@ -1,5 +1,5 @@ import React, { useContext, useState } from 'react'; -import { View, Text, StyleSheet, FlatList, TouchableOpacity } from 'react-native'; +import { View, Text, StyleSheet, FlatList, TouchableOpacity, Image, Modal } from 'react-native'; import { QRCodeContext, QRCode } from '../types'; // Import QRCode type import ScannedDataBox from '../components/ScannedDataBox'; import { Ionicons } from '@expo/vector-icons'; @@ -13,6 +13,8 @@ const HistoryScreen: React.FC = () => { const [selectedData, setSelectedData] = useState(null); const [selectedScanResult, setSelectedScanResult] = useState(null); const [showBookmarks, setShowBookmarks] = useState(false); + const [isModalVisible, setIsModalVisible] = useState(false); + const [indexToDelete, setIndexToDelete] = useState(null); const toggleBookmark = (index: number) => { setQrCodes((prev: QRCode[]) => { @@ -23,11 +25,15 @@ const HistoryScreen: React.FC = () => { }); }; - const deleteQRCode = (index: number) => { - setQrCodes((prev: QRCode[]) => { - const originalIndex = prev.length - 1 - index; // Compute the original index - return prev.filter((_, i) => i !== originalIndex); - }); + const deleteQRCode = () => { + if (indexToDelete !== null) { + setQrCodes((prev: QRCode[]) => { + const originalIndex = prev.length - 1 - indexToDelete; // Compute the original index + return prev.filter((_, i) => i !== originalIndex); + }); + setIndexToDelete(null); + setIsModalVisible(false); + } }; const filteredQrCodes = (showBookmarks ? qrCodes.filter(qr => qr.bookmarked) : qrCodes.slice().reverse()); @@ -37,6 +43,11 @@ const HistoryScreen: React.FC = () => { setSelectedScanResult(item.scanResult); }; + const confirmDelete = (index: number) => { + setIndexToDelete(index); + setIsModalVisible(true); + }; + return ( @@ -58,8 +69,8 @@ const HistoryScreen: React.FC = () => { return ( - - handleItemPress(item)}> + handleItemPress(item)} style={styles.itemContent}> + {itemData} {new Date().toLocaleDateString('en-GB', { @@ -70,7 +81,7 @@ const HistoryScreen: React.FC = () => { toggleBookmark(index)}> - deleteQRCode(index)}> + confirmDelete(index)}> @@ -80,6 +91,27 @@ const HistoryScreen: React.FC = () => { keyExtractor={(item, index) => index.toString()} contentContainerStyle={styles.flatListContent} /> + setIsModalVisible(false)} + > + + + Are you sure? + If bookmarked, this will be removed from both History and Bookmarks. + + + Yes, Delete + + setIsModalVisible(false)}> + No, Keep It + + + + + ); }; @@ -117,24 +149,68 @@ const styles = StyleSheet.create({ itemLeft: { flexDirection: 'column', }, + itemContent: { + flexDirection: 'row', + alignItems: 'center', + }, itemRight: { flexDirection: 'row', + alignItems: 'center', }, dataText: { fontSize: 16, color: '#000', - marginBottom: 5, + marginLeft: 10, }, dateText: { fontSize: 12, color: '#000', + marginLeft: 10, }, - qrIcon: { - marginBottom: 5, + scanIcon: { + width: 40, + height: 40, }, flatListContent: { paddingBottom: 100, }, + modalContainer: { + flex: 1, + justifyContent: 'center', + alignItems: 'center', + backgroundColor: 'rgba(0, 0, 0, 0.5)', + }, + modalContent: { + width: '80%', + backgroundColor: 'white', + borderRadius: 10, + padding: 20, + alignItems: 'center', + }, + modalTitle: { + fontSize: 20, + fontWeight: 'bold', + marginBottom: 10, + }, + modalText: { + fontSize: 16, + marginBottom: 20, + textAlign: 'center', + }, + modalButtons: { + flexDirection: 'row', + justifyContent: 'space-between', + width: '100%', + }, + modalButton: { + flex: 1, + alignItems: 'center', + padding: 10, + }, + modalButtonText: { + fontSize: 16, + color: '#000', + }, }); export default HistoryScreen;