Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

react-todo-list-challenge/Steven-Carcamo #11

Open
wants to merge 16 commits into
base: master
Choose a base branch
from

Conversation

stevenlara-ravn
Copy link

No description provided.

import { createPortal } from "react-dom";
import TaskForm from "./TaskForm";

export default function CreateTaskFloatingButton() {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest you separate the button from the form, maybe you can extract the logic here and move this to it's parent level that must be a better approach for handling this

});

const onSubmit = (data: TaskFormData) => {
const newTask = {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const newTask = {
const newTask = {
id,
...data,
}

dueDate: data.dueDate
};

const existingTasks = JSON.parse(localStorage.getItem("tasks") || "[]");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can define this outside of the function right?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I'll work on this improvements tomorrow


addTask(newTask);

reset();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can define a helper function called onSuccess and wrap this two functions there

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's just what I thought, actually there is still some refactor I want to do

errors={errors}
register={register}
dataItem={task}
formMode="edit"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice


export default function SearchTask() {
const [searchTerm, setSearchTerm] = useState<string>("");
const [termDebounced] = useDebounce(searchTerm, 500);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice job

setSearchTerm(e.currentTarget.value);
};

useEffect(() => {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering if a useEffect is really needed

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll figure it out

const deleteTask = useTasksStore((state: any) => state.deleteTask);

const handleDelete = (taskId: string) => {
const existingTasks = JSON.parse(localStorage.getItem("tasks") || "[]");
Copy link

@marceloev123 marceloev123 Dec 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are using this multiple times, I think you also defined this variable in your store, why are you not using it?

Copy link
Author

@stevenlara-ravn stevenlara-ravn Dec 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I got what you mean, I'll check it out



export default function TaskList() {
const tasks = useTasksStore((state: TasksStore) => state.tasks) as Task[];

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is the cast needed?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You already defined the types in the zustand store

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I forgot to remove it, this is no longer needed

import { z } from "zod";

export const taskSchema = z.object({
id: z.string().optional(),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this can be
z.string().uuid() if I'm not wrong

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, I'll change it

id: z.string().optional(),
title: z.string().min(5, { message: "Task title is required" }).max(30, { message: "Task title is too long" }),
priority: z.enum(["Urgent", "High", "Normal", "Low"]),
storyPoints: z.coerce.number().min(1, { message: "Number must be a number between 1 and 10" }).max(20, { message: "Number must be a number between 1 and 20" }),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why coerce is needed?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem is that input type="number" when is accessed by the form, for some reason is taking it as string, so this parses to string.

import { create } from "zustand";
import { Task, TasksStore } from "../types/Task";

export const useTasksStore = create<TasksStore>((set) => ({

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Zustand has a middleware called persist that you can use to avoid doing all the JSON.parse localStorage... stuff
https://arc.net/l/quote/cbgffbxe

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll check it out

import { Task, TaskFormMode } from "../types/Task";

interface FormLayoutProps {
handleSubmit: (data: any) => any;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any usage!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants