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
23
app/todo.tsx
23
app/todo.tsx
|
@ -2,7 +2,7 @@ import AsyncStorage from "@react-native-async-storage/async-storage";
|
||||||
import { useRouter } from "expo-router";
|
import { useRouter } from "expo-router";
|
||||||
import React, { useEffect, useState } from "react";
|
import React, { useEffect, useState } from "react";
|
||||||
import {
|
import {
|
||||||
Alert,
|
Alert, // Make sure Alert is imported
|
||||||
ImageBackground,
|
ImageBackground,
|
||||||
KeyboardAvoidingView,
|
KeyboardAvoidingView,
|
||||||
Platform,
|
Platform,
|
||||||
|
@ -71,8 +71,29 @@ export default function CoordinateConverter() {
|
||||||
};
|
};
|
||||||
|
|
||||||
const removeTodo = (index: number) => {
|
const removeTodo = (index: number) => {
|
||||||
|
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);
|
const updatedTodos = todos.filter((_, i) => i !== index);
|
||||||
setTodos(updatedTodos);
|
setTodos(updatedTodos);
|
||||||
|
console.log("Todo deleted:", todoToRemove);
|
||||||
|
},
|
||||||
|
style: "destructive"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
{ cancelable: true }
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
Loading…
Add table
Reference in a new issue