Skip to content

Commit

Permalink
sun
Browse files Browse the repository at this point in the history
  • Loading branch information
EuJinnLucaShow committed Jan 3, 2024
1 parent b71cb50 commit dc285fb
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
2 changes: 2 additions & 0 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import React from 'react';
import 'react-toastify/dist/ReactToastify.css';
import InputForm from 'components/InputForm';
import Title from 'components/Title';
import TodoList from 'components/TodoList';
Expand Down
13 changes: 10 additions & 3 deletions src/components/TodoList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import TodoItem from './TodoItem';
import { selectTodo } from 'redux/selectors';
import { fetchTodos, sendTodos } from 'redux/operations';
import Pagination from '../utils/Pagination';
import { toast } from 'react-toastify';

const PAGE_SIZE = 5;

Expand All @@ -25,7 +26,11 @@ const TodoList = () => {
}, [currentPage, todos]);

useEffect(() => {
dispatch(fetchTodos());
toast.promise(dispatch(fetchTodos()), {
pending: 'TODO List is pending',
success: 'TODO List resolved 👌',
error: 'TODO List rejected 🤯',
});
}, [dispatch]);

const handlePageChange = ({ selected }) => {
Expand All @@ -45,8 +50,10 @@ const TodoList = () => {
const [removed] = items.splice(result.source.index, 1);
items.splice(result.destination.index, 0, removed);
setItems(items);
const reversed = [...items].reverse();
dispatch(sendTodos(reversed));
console.log(items);
console.log(todos);
// const reversed = [...items].reverse();
// dispatch(sendTodos(reversed));
};

return (
Expand Down
1 change: 0 additions & 1 deletion src/redux/operations.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ export const editTodo = createAsyncThunk(
export const sendTodos = createAsyncThunk(
'todos/sendTodos',
async (todosArray, thunkAPI) => {
console.log(todosArray);
try {
const response = await axios.post('/save-todos', todosArray);
return response.data;
Expand Down
2 changes: 2 additions & 0 deletions src/redux/selectors.js
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
export const selectTodo = state => state.todos.todos;
export const isLoading = state => state.todos.isLoading;
export const error = state => state.todos.error;

0 comments on commit dc285fb

Please sign in to comment.