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

react1-week3/GizemSavci #286

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

react1-week3/GizemSavci #286

wants to merge 16 commits into from

Conversation

GizemSavci
Copy link

No description provided.

@github-actions github-actions bot changed the title React1 week3/gizem savci react1-week3/GizemSavci Apr 7, 2024
Copy link

@BrantalikP BrantalikP left a comment

Choose a reason for hiding this comment

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

Besides few things, as always @GizemSavci amazing job!I can see all the hard work behind it and I appreciate that you are not afraid to do that one extra step to achieve better results. Big Kudos 👏

function App() {
const [todos, setTodos] = useState([]);

const { data, error } = useSWR("https://gist.githubusercontent.com/benna100/391eee7a119b50bd2c5960ab51622532/raw", fetcher);

Choose a reason for hiding this comment

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

well, this is cool. good job! Here is some really popular alternative if you are interested :) https://tanstack.com/query/latest

}
}, [data]);

if (!data) return <div>Loading...</div>;

Choose a reason for hiding this comment

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

we should show the loading state only if the data is really loading and it is empty, otherwise, it could confuse the user by letting him stuck on the loading page even if there is no data. please add isLoading prop from useSwr as well :)

}

const removeTodo = (todoIdToRemove) => {
setTodos(todos.filter(todo => todo.id !== todoIdToRemove));

Choose a reason for hiding this comment

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

to keep the code consistent, please use the same approach as you did above in addTodo with prevTodos


function BorderWrapper({ children }){
return (
<div style={{

Choose a reason for hiding this comment

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

there is no need for inline styling, please use CSS styles from CSS file


function DateSelector({ selectedDate, onDateChange }) {
return (
<div className='App'>

Choose a reason for hiding this comment

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

I've noticed that you are using this class in multiple places but I cannot see such a style anywhere if it's not doing anything please remove it :)


export default Deadline;

Deadline.propTypes = {

Choose a reason for hiding this comment

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

well done for using Proptypes 👏

@@ -0,0 +1,6 @@
let nextId = 0;
export function generateId() {

Choose a reason for hiding this comment

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

This approach is not safe, it would work only till the user won't refresh the page.

Lets say that you would store the user's data,

  1. The user comes to the page and will create a todo "some todo" id: 0 (nextId current value)
  2. He decided that he will the rest later so he closes the browser, then he comes back after some time and create another todo, but because the previous instance of the page was terminated the nextId start from 0 again

There are other ways how to achieve a uniq ID:

  1. using timestamp, you can use Date API to get the current timestamp, to make it more robust, you can combine it with the todo description
  2. Math.random method
  3. maybe overkill for the app of this scale, but the safest approach is using uuid library https://github.com/uuidjs/uuid

const todo = {
id:generateId(),
description: description,
deadline: selectedDate.toISOString().split('T')[0],

Choose a reason for hiding this comment

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

This will also cause some issues with in your timezone as well. If you've noticed, the displayed date will differ from the selected one by one day. This is caused by the toISOString method, which converts the date to UTC time. Alternatively, you can use this approach if you know that only people from Denmark will use it.

selectedDate.toLocaleDateString("en-CA", {
        timeZone: "Europe/Copenhagen",
      });

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.

None yet

2 participants