feat: Add alert when deleting todo
Signed-off-by: SindreKjelsrud <sindre@kjelsrud.dev>
This commit is contained in:
parent
43aa945fc9
commit
479f030b45
1 changed files with 24 additions and 3 deletions
27
app/todo.tsx
27
app/todo.tsx
|
@ -2,7 +2,7 @@ import AsyncStorage from "@react-native-async-storage/async-storage";
|
|||
import { useRouter } from "expo-router";
|
||||
import React, { useEffect, useState } from "react";
|
||||
import {
|
||||
Alert,
|
||||
Alert, // Make sure Alert is imported
|
||||
ImageBackground,
|
||||
KeyboardAvoidingView,
|
||||
Platform,
|
||||
|
@ -71,8 +71,29 @@ export default function CoordinateConverter() {
|
|||
};
|
||||
|
||||
const removeTodo = (index: number) => {
|
||||
const updatedTodos = todos.filter((_, i) => i !== index);
|
||||
setTodos(updatedTodos);
|
||||
const todoToRemove = todos[index];
|
||||
|
||||
Alert.alert(
|
||||
"Delete Todo",
|
||||
`Are you sure you want to delete "${todoToRemove}"?`,
|
||||
[
|
||||
{
|
||||
text: "Cancel",
|
||||
onPress: () => console.log("Delete Cancelled"),
|
||||
style: "cancel"
|
||||
},
|
||||
{
|
||||
text: "Delete",
|
||||
onPress: () => {
|
||||
const updatedTodos = todos.filter((_, i) => i !== index);
|
||||
setTodos(updatedTodos);
|
||||
console.log("Todo deleted:", todoToRemove);
|
||||
},
|
||||
style: "destructive"
|
||||
}
|
||||
],
|
||||
{ cancelable: true }
|
||||
);
|
||||
};
|
||||
|
||||
return (
|
||||
|
|
Loading…
Add table
Reference in a new issue