From 6419b9dd97d00a2f4f12f7c5ebcd74c2e8374c4b Mon Sep 17 00:00:00 2001 From: M1kola Date: Thu, 23 Mar 2023 16:43:37 +0300 Subject: [PATCH] fixes --- src/components/UI/ModalCreate/ModalCreate.js | 10 +++--- src/pages/Tracker/Tracker.js | 34 ++++++++++---------- src/redux/projectsTrackerSlice.js | 4 +-- 3 files changed, 23 insertions(+), 25 deletions(-) diff --git a/src/components/UI/ModalCreate/ModalCreate.js b/src/components/UI/ModalCreate/ModalCreate.js index 2b99b042..04a2894c 100644 --- a/src/components/UI/ModalCreate/ModalCreate.js +++ b/src/components/UI/ModalCreate/ModalCreate.js @@ -1,13 +1,11 @@ import React, { useState } from "react"; -import { useDispatch, useSelector } from "react-redux"; -import { addProject } from "../../../redux/projectsTrackerSlice"; +import { useDispatch } from "react-redux"; +import { setProject } from "../../../redux/projectsTrackerSlice"; import "./ModalCreate.scss"; export const ModalCreate = ({ active, setActive, title }) => { const [inputValue, setInputValue] = useState(""); - - const projectInfo = useSelector(addProject); const dispatch = useDispatch(); function createName() { @@ -15,9 +13,9 @@ export const ModalCreate = ({ active, setActive, title }) => { name: inputValue, count: 0, }; - dispatch(addProject(newItem)); - // console.log(newItem); + dispatch(setProject(newItem)); setActive(false); + setInputValue("") } return ( diff --git a/src/pages/Tracker/Tracker.js b/src/pages/Tracker/Tracker.js index e8119213..bcb337af 100644 --- a/src/pages/Tracker/Tracker.js +++ b/src/pages/Tracker/Tracker.js @@ -17,24 +17,24 @@ import search from "../../images/search.svg"; import "./tracker.scss"; import { useDispatch, useSelector } from "react-redux"; -import { addProject } from "../../redux/projectsTrackerSlice"; +import { getProjects } from "../../redux/projectsTrackerSlice"; export const Tracker = () => { const [toggleTab, setToggleTab] = useState(1); - const [projects] = useState([ - { - name: "Разработка трекера", - count: 4, - }, - { - name: "Кинотеатр", - count: 4, - }, - { - name: "Проект страхование", - count: 4, - }, - ]); + // const [projects] = useState([ + // { + // name: "Разработка трекера", + // count: 4, + // }, + // { + // name: "Кинотеатр", + // count: 4, + // }, + // { + // name: "Проект страхование", + // count: 4, + // }, + // ]); const [tabTaskMok, setTabTaskMok] = useState([ { name: "Открытые", @@ -256,8 +256,8 @@ export const Tracker = () => { false, ]); - // const projectInfo = useSelector(addProject); - // const dispatch = useDispatch(); + const projects = useSelector(getProjects); + const dispatch = useDispatch(); const toggleTabs = (index) => { setToggleTab(index); diff --git a/src/redux/projectsTrackerSlice.js b/src/redux/projectsTrackerSlice.js index f87eb14c..c35991bf 100644 --- a/src/redux/projectsTrackerSlice.js +++ b/src/redux/projectsTrackerSlice.js @@ -21,7 +21,7 @@ export const projectsTrackerSlice = createSlice({ name: "projectsTracker", initialState, reducers: { - setProject(state, action) { + setProject: (state, action) => { state.project.push(action.payload); }, }, @@ -29,6 +29,6 @@ export const projectsTrackerSlice = createSlice({ export const { setProject } = projectsTrackerSlice.actions; -export const addProject = (state) => state.projectsTracker.setProject; +export const getProjects = (state) => state.tracker.project; export default projectsTrackerSlice.reducer;