11import React , { useState } from "react" ;
2- import { ScrollView , StyleSheet , View } from "react-native" ;
2+ import { ScrollView , StyleSheet , View , Alert } from "react-native" ;
33import { Avatar , Card , Text , Modal , Portal , Button , TextInput } from "react-native-paper" ;
44import { useFocusEffect } from '@react-navigation/native' ;
55import useCategories from "../hooks/useCategories" ;
@@ -22,7 +22,7 @@ const Categories = ({ navigation }) => {
2222 day : "numeric" ,
2323 } ) ;
2424
25- const { moreCategories, addCategory } = useCategories ( ) ;
25+ const { moreCategories, addCategory, removeCategory } = useCategories ( ) ;
2626 const { setSync } = useSyncContext ( ) ;
2727
2828 const [ newCategory , setNewCategory ] = useState ( "" ) ;
@@ -45,6 +45,24 @@ const Categories = ({ navigation }) => {
4545 hideModal ( ) ;
4646 }
4747
48+ function handleRemoveCategory ( categoryName ) {
49+ Alert . alert (
50+ "Delete Category" ,
51+ `Are you sure you want to delete "${ categoryName } "?` ,
52+ [
53+ {
54+ text : "Cancel" ,
55+ style : "cancel"
56+ } ,
57+ {
58+ text : "Delete" ,
59+ style : "destructive" ,
60+ onPress : ( ) => removeCategory ( categoryName )
61+ }
62+ ]
63+ ) ;
64+ }
65+
4866 return (
4967 < >
5068 < Portal >
@@ -127,6 +145,7 @@ const Categories = ({ navigation }) => {
127145 key = { index }
128146 style = { styles . card }
129147 onPress = { ( ) => navigation . navigate ( "Tasks" , { category } ) }
148+ onLongPress = { ( ) => handleRemoveCategory ( category ) }
130149 mode = "contained"
131150 >
132151 < Card . Title
0 commit comments