Skip to content

Commit

Permalink
same reorganisation
Browse files Browse the repository at this point in the history
  • Loading branch information
KaratSergio committed Jan 25, 2024
1 parent 5e59a11 commit e8fef69
Show file tree
Hide file tree
Showing 15 changed files with 36 additions and 22 deletions.
2 changes: 1 addition & 1 deletion src/components/ContactList/ContactList.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useDispatch, useSelector } from 'react-redux';
import { deleteContact } from '../../redux/operations';
import * as selectors from '../../redux/selectors';
import * as selectors from '../../redux/contacts/selectors';
import { Loader } from '../Loader/Loader';

import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
Expand Down
2 changes: 1 addition & 1 deletion src/components/Filter/Filter.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useDispatch, useSelector } from 'react-redux';
import { setFilter } from '../../redux/filterSlice';
import * as selectors from '../../redux/selectors';
import * as selectors from '../../redux/contacts/selectors';

import css from './Filter.module.css';

Expand Down
2 changes: 1 addition & 1 deletion src/components/Form/ContactForm/ContactForm.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useDispatch, useSelector } from 'react-redux';
import { addContact } from '../../../redux/operations';
import * as selectors from '../../../redux/selectors';
import * as selectors from '../../../redux/contacts/selectors';
import { nanoid } from '@reduxjs/toolkit';

import Notiflix from 'notiflix';
Expand Down
3 changes: 2 additions & 1 deletion src/components/Form/authForms/LoginForm.jsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { useDispatch, useSelector } from 'react-redux';
import { selectErrorLogin } from '../../../redux/auth/selectors';

export const LoginForm = () => {
const dispatch = useDispatch();
const errorLogin = useSelector(state => state.error); // Dont FORGET !!! import selector
const errorLogin = useSelector(selectErrorLogin);

const handleSubmit = e => {
e.preventDefault();
Expand Down
8 changes: 4 additions & 4 deletions src/components/Navigation/Navigation.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { UseSelector } from "react-redux";
import { NavLink } from 'react-router-dom';

import { UserMenu } from '../UserMenu/UserMenu'
import { useSelector } from 'react-redux';
import { selectIsLoggedIn } from '../../redux/auth/selectors';
import { UserMenu } from '../UserMenu/UserMenu';

const Navigation = () => {
const isLoggedIn = useSelector(selectIsLoggedIn);
Expand All @@ -25,4 +25,4 @@ const Navigation = () => {
);
};

export default Navigation;
export default Navigation;
28 changes: 15 additions & 13 deletions src/components/UserMenu/UserMenu.jsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
import { useDispatch, useSelector } from "react-redux";
import { useDispatch, useSelector } from 'react-redux';
import { logOut } from '../../redux/auth/operations';
import { selectUser } from '../../redux/auth/selectors';

const UserMenu = () => {
const dispatch = useDispatch();
const user = useSelector(selectUser);
const dispatch = useDispatch();
const user = useSelector(selectUser);

return (
<dir>
<p>Welcome, {user.name}</p>
<button type="button" onClick={() => dispatch(logOut())}>
Logout
</button>
</dir>
);
}
return (
<dir>
<p>Welcome, {user.name}</p>
<button type="button" onClick={() => dispatch(logOut())}>
Logout
</button>
</dir>
);
};

export default UserMenu;
export default UserMenu;
9 changes: 8 additions & 1 deletion src/pages/Contacts.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,19 @@ import { useSelector, useDispatch } from 'react-redux';
import { useEffect } from 'react';
import { Grid } from 'react-loader-spinner';

import { fetchContacts } from '../redux/contacts/operations';
import { selectLoading, selectError } from '../redux/contacts/selectors';

import { Filter } from '../components/Filter/Filter';
import { ContactList } from '../components/ContactList/ContactList';
import { ContactForm } from '../components/form/ContactForm/ContactForm';

const { useEffect } = require('react');
const { useDispatch, useSelector } = require('react-redux');

const Contacts = () => {
const dispatch = useDispatch();
const isLoading = useSelector(selectIsloading);
const isLoading = useSelector(selectLoading);
const error = useSelector(selectError);

useEffect(() => {
Expand Down
Empty file added src/redux/auth/operations.js
Empty file.
4 changes: 4 additions & 0 deletions src/redux/auth/selectors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export const selectIsLoggedIn = state => state.auth.isLoggedIn;
export const selectUser = state => state.auth.user;
export const selectIsRefreshing = state => state.auth.isRefreshing;
export const selectErrorLogin = state => state.auth.error;
Empty file added src/redux/auth/slice.js
Empty file.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit e8fef69

Please sign in to comment.