Skip to content

Commit

Permalink
✨ feat: added delete sound, add task on enter and drop task if leaved…
Browse files Browse the repository at this point in the history
… empty
  • Loading branch information
bytevictor committed Mar 28, 2024
1 parent cefc195 commit 642b12b
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 7 deletions.
30 changes: 26 additions & 4 deletions app/Components/TasksApp/TaskList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ function Task({
audio.play();
};

const playSoundDelete = () => {
console.log("Playing sound");

const audio = new Audio("/sounds/delete.mp3");
audio.play();
}

console.log("Task", task);

const [isEditing, setIsEditing] = useState(task.isNew);
Expand All @@ -52,15 +59,27 @@ function Task({
taskContent = (
<>
<input
className="input input-bordered col-span-3"
className="input input-bordered col-span-3 font-semibold text-xl"
value={task.text}
onChange={(e) => {
onChange({
...task,
text: e.target.value,
});
}}
onBlur={() => setIsEditing(false)}
onBlur={(e) => {
setIsEditing(false);

//If empty onLeave, drop the task
if (e.target.value === "") {
onDelete(task.id);
}
}}
onKeyDown={(e) => {
if (e.key === "Enter") {
(e.target as HTMLInputElement).blur();
}
}}
autoFocus
/>
</>
Expand All @@ -69,7 +88,7 @@ function Task({
taskContent = (
<>
<span
className="col-span-3 self-center align-middle text-start w-full min-h-6"
className="col-span-3 self-center align-middle text-start w-full min-h-12 font-semibold text-xl items-center inline-flex"
onDoubleClick={() => setIsEditing(true)}
>
{task.text}
Expand Down Expand Up @@ -98,7 +117,10 @@ function Task({
{taskContent}

<button
onClick={() => onDelete(task.id)}
onClick={() => {
onDelete(task.id);
playSoundDelete();
}}
className="btn btn-md btn-circle btn-outline btn-error self-end justify-self-end"
>
<TrashIcon />
Expand Down
6 changes: 3 additions & 3 deletions app/_lib/icons/TrashIcon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ export default function TrashIcon() {
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
strokeWidth="2"
strokeLinecap="round"
strokeLinejoin="round"
className="lucide lucide-trash-2 h-6 w-6"
>
<path d="M3 6h18" />
Expand Down
Binary file added public/sounds/delete.mp3
Binary file not shown.

0 comments on commit 642b12b

Please sign in to comment.