-
-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathAddToBucket.jsx
More file actions
79 lines (70 loc) · 1.88 KB
/
AddToBucket.jsx
File metadata and controls
79 lines (70 loc) · 1.88 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
71
72
73
74
75
76
77
78
79
import { createSignal } from "solid-js";
import { isFutureDate } from "./util/dateTimeUtil";
import { saveWish } from "./util/localStorageUtil";
export function AddToBucket(props) {
const [newItem, setNewItem] = createSignal({
text: "",
deadline: null,
});
const handleWishDeadlineChange = (e) => {
const deadlineTime = e.target.value;
if (!isFutureDate(new Date(deadlineTime))) {
alert("You must pick a deadline time in the future.");
return;
}
setNewItem({ ...newItem(), deadline: deadlineTime });
};
const handleWishTextChange = (e) => {
setNewItem({ ...newItem(), text: e.target.value });
};
const isValidWish = (wish) => {
if (!wish.deadline) return false;
return true;
};
const handleWishCreate = (e) => {
e.preventDefault();
const newWish = newItem();
if (!isValidWish(newWish)) {
return alert("Please Enter valid wish deadline");
}
props.setItems((items) => {
const allWishes = [
{
id: crypto.randomUUID(),
text: newWish.text,
complete: false,
createdAt: new Date(),
deadline: newWish.deadline,
},
...items,
];
saveWish(allWishes);
return allWishes;
});
setNewItem("");
};
return (
<form class="flex items-center gap-2">
<input
type="text"
class="w-60 border px-2 py-1.5 rounded-md text-xl"
placeholder="Make a wish"
value={newItem().text}
onChange={handleWishTextChange}
/>
<input
class="w-40 border px-2 py-1.5 rounded-md text-xl"
type="dateTime-local"
name="deadline"
onchange={handleWishDeadlineChange}
/>
<button
type="submit"
class="px-3 py-1.5 text-xl rounded-md bg-blue-600 text-white"
onClick={handleWishCreate}
>
Add
</button>
</form>
);
}