Browse Source

action creators added (broken)

pocu46 4 years ago
parent
commit
054f63112b
2 changed files with 19 additions and 4 deletions
  1. 5 2
      hipstagram/src/Content/Profile/My posts/my posts.js
  2. 14 2
      hipstagram/src/Redux/state.js

+ 5 - 2
hipstagram/src/Content/Profile/My posts/my posts.js

@@ -1,6 +1,8 @@
 import React from 'react';
 import Post from './Post/post';
 import './my posts.css';
+import { addPostActionCreator, updateNewPostTextActionCreator } from '../../../Redux/state';
+// import { addPostActionCreator } from '../../../Redux/state';
 
 function MyPosts(props) {
 
@@ -9,12 +11,13 @@ function MyPosts(props) {
     let newPostElement = React.createRef();
 
     let addPost = () => {
-        props.dispatch({ type: 'ADD-POST'});
+        props.dispatch(addPostActionCreator());
     }
 
     let onPostChange = () => {
         let text = newPostElement.current.value;
-        let action = ({ type: 'UPDATE-NEW-POST-TEXT', newText: text});
+        // let action = ({ type: 'UPDATE-NEW-POST-TEXT', newText: text});
+        let action = updateNewPostTextActionCreator(text);
         props.dispatch(action);
     }
 

+ 14 - 2
hipstagram/src/Redux/state.js

@@ -1,3 +1,6 @@
+const ADD_POST = 'ADD-POST';
+const UPDATE_NEW_POST_TEXT = 'UPDATE-NEW-POST-TEXT';
+
 let store = {
     _state: {
         profilePage: {
@@ -31,7 +34,7 @@ let store = {
         this._callSubscriber = observer;
     },
     dispatch(action) {
-        if (action.type === 'ADD-POST') {
+        if (action.type === ADD_POST) {
             let newPost = {
                 id: 5,
                 message: this._state.profilePage.newPostText,
@@ -40,11 +43,20 @@ let store = {
             this._state.profilePage.post.push(newPost);
             this._state.profilePage.newPostText = "";
             this._callSubscriber(this._state);
-        } else if(action.type === 'UPDATE-NEW-POST-TEXT') {
+        } else if(action.type === UPDATE_NEW_POST_TEXT) {
             this._state.profilePage.newPostText = action.newText;
             this._callSubscriber(this._state);
         }
     }
 };
 
+export const addPostActionCreator = () => ({ type: 'ADD-POST' });
+
+export const updateNewPostTextActionCreator = () {
+    return {
+        type: 'UPDATE-NEW-POST-TEXT', 
+        newText: text
+    }
+}
+
 export default store;