-
-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathApp.jsx
More file actions
70 lines (62 loc) · 2.36 KB
/
App.jsx
File metadata and controls
70 lines (62 loc) · 2.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import { createSignal } from "solid-js";
import { BucketListItem } from "./BucketListItem";
import { AddToBucket } from "./AddToBucket";
import Modal from './Modal';
import { getWishes, saveWish } from "./util/localStorageUtil";
function App() {
const [items, setItems] = createSignal(getWishes());
const [isOpen, setIsOpen] = createSignal(false);
const handleOneOrMoreDeleteItem = () => {
setItems((items) => {
const ItemsWithoutTheDeletedOnes = items.filter(
(item) => item.delete === false
);
saveWish(ItemsWithoutTheDeletedOnes);
return ItemsWithoutTheDeletedOnes;
});
};
const noOfItemsToBeDeleted = () => {
const itemsToBeDeleted = items().filter((item) => item.delete);
return itemsToBeDeleted.length;
};
return (
<div class="container flex flex-col justify-center items-center gap-4">
<h1 class="text-4xl font-bold">Solid Bucket List</h1>
<AddToBucket setItems={setItems} />
<div class="flex justify-center sm:justify-between items-center flex-wrap gap-6">
<p class="flex justify-center items-center flex-col">
<span class="font-bold">No of items to be deleted</span>
<span class="font-bold">{noOfItemsToBeDeleted()}</span>
</p>
<button
type="button"
class="bg-[crimson] text-white py-2 px-4 rounded-lg font-bold text-center cursor-pointer hover:bg-red-500"
onclick={() => setIsOpen(true)}
>
{noOfItemsToBeDeleted() > 1 ? 'Delete All' : 'Delete'}
</button>
</div>
{isOpen() && (
<Modal
title="Delete Confirmation"
text={
noOfItemsToBeDeleted() === 0
? `You haven't selected any item 😕`
: `Are you sure? You want to delete ${
noOfItemsToBeDeleted() > 1 ? 'those' : 'this'
}! 😕`
}
setIsOpen={setIsOpen}
handleOneOrMoreDeleteItem={handleOneOrMoreDeleteItem}
noOfItemsToBeDeleted={noOfItemsToBeDeleted}
/>
)}
<ul class="text-2xl">
<For each={items()}>
{(item) => <BucketListItem item={item} setItems={setItems} />}
</For>
</ul>
</div>
);
}
export default App;