diff --git a/src/ActionTypes/actionTypes.js b/src/ActionTypes/actionTypes.js
index fceafd8..b469a55 100644
--- a/src/ActionTypes/actionTypes.js
+++ b/src/ActionTypes/actionTypes.js
@@ -2,3 +2,4 @@ export const FETCH_ALL = 'FETCH_ALL';
export const CREATE = 'CREATE';
export const UPDATE = 'UPDATE';
export const DELETE = 'DELETE';
+export const lIKE_POST = 'LIKE_POST';
diff --git a/src/actions/posts.js b/src/actions/posts.js
index 8957b3a..e47c79b 100644
--- a/src/actions/posts.js
+++ b/src/actions/posts.js
@@ -1,17 +1,14 @@
import * as api from '../api';
-import { FETCH_ALL, CREATE, UPDATE, DELETE } from '../ActionTypes/actionTypes';
+import { FETCH_ALL, CREATE, UPDATE, DELETE, lIKE_POST } from '../ActionTypes/actionTypes';
// Create the actions.
export const getPosts = () => async (dispatch) => {
try {
const { data } = await api.fetchPosts();
- // debug line
-
const action = { type: FETCH_ALL, payload: data };
dispatch(action);
} catch (error) {
- /* eslint-disable no-console */
console.log(error);
}
};
@@ -45,3 +42,13 @@ export const deletePost = (id) => async (dispatch) => {
console.log(error);
}
};
+
+export const likePost = (id) => async (dispatch) => {
+ try {
+ const { data } = await api.likePost(id);
+ const action = { type: lIKE_POST, payload: data };
+ dispatch(action);
+ } catch (error) {
+ console.log(error);
+ }
+};
diff --git a/src/api/index.js b/src/api/index.js
index 8f860f5..b00a511 100644
--- a/src/api/index.js
+++ b/src/api/index.js
@@ -13,3 +13,6 @@ export const updatePost = (id, updatedPost) =>
export const deletePost = (id) =>
axios.delete(`${url}/${id}`, { headers: { 'Access-Control-Allow-Origin': '*' } });
+
+export const likePost = (id) =>
+ axios.patch(`${url}/${id}/likedPost`, { headers: { 'Access-Control-Allow-Origin': '*' } });
diff --git a/src/components/Form/Form.js b/src/components/Form/Form.js
index 0ce7a86..66d8354 100644
--- a/src/components/Form/Form.js
+++ b/src/components/Form/Form.js
@@ -35,8 +35,6 @@ const Form = ({ currentId, setCurrentId }) => {
const handleSubmit = (event) => {
event.preventDefault();
- console.log(postData);
-
if (currentId) {
dispatch(updatePost(currentId, postData));
} else {
diff --git a/src/components/Posts/Post/Post.js b/src/components/Posts/Post/Post.js
index db84e2e..6628efb 100644
--- a/src/components/Posts/Post/Post.js
+++ b/src/components/Posts/Post/Post.js
@@ -1,6 +1,6 @@
import React from 'react';
import { useDispatch } from 'react-redux';
-import { deletePost } from '../../../actions/posts';
+import { deletePost, likePost } from '../../../actions/posts';
import makeStyles from './styles';
@@ -17,6 +17,7 @@ const Post = ({ post, setCurrentId }) => {
const dispatch = useDispatch();
const handleClickEdit = (event) => {
+ console.log(event.target.value);
setCurrentId(post._id);
};
@@ -25,7 +26,8 @@ const Post = ({ post, setCurrentId }) => {
};
const handleClickLike = (event) => {
- console.log('Clicking the Like button');
+ console.log(event.target.value);
+ dispatch(likePost(post._id));
};
return (
@@ -52,28 +54,18 @@ const Post = ({ post, setCurrentId }) => {
{post.title}
-
+
{post.message}
-
diff --git a/src/components/Posts/PostSkeleton/PostSkeleton.js b/src/components/Posts/PostSkeleton/PostSkeleton.js
index 5c73f2a..4574e52 100644
--- a/src/components/Posts/PostSkeleton/PostSkeleton.js
+++ b/src/components/Posts/PostSkeleton/PostSkeleton.js
@@ -1,25 +1,37 @@
import React, { useState } from 'react';
-import { nanoid } from 'nanoid';
-
import Skeleton from '@material-ui/lab/Skeleton';
import { Grid } from '@material-ui/core';
+import { nanoid } from 'nanoid';
import makeStyles from '../styles';
const PostSkeleton = () => {
const classes = makeStyles();
- const [id] = useState(nanoid);
+ const [uuid] = useState(nanoid);
return (
- {[1, 2, 3, 4].map((index) => (
-
-
-
-
-
-
-
- ))}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
);
};
diff --git a/src/index.js b/src/index.js
index 53a3f45..9063a20 100644
--- a/src/index.js
+++ b/src/index.js
@@ -1,7 +1,7 @@
import React from 'react';
import ReactDOM from 'react-dom';
import { Provider } from 'react-redux';
-import { createStore, applyMiddleware } from 'redux';
+import { createStore, applyMiddleware, compose } from 'redux';
import { composeWithDevTools } from 'redux-devtools-extension';
import thunk from 'redux-thunk';
import reducers from './reducers';
diff --git a/src/reducers/posts.js b/src/reducers/posts.js
index dde98be..0941544 100644
--- a/src/reducers/posts.js
+++ b/src/reducers/posts.js
@@ -1,4 +1,4 @@
-import { FETCH_ALL, CREATE, UPDATE, DELETE } from '../ActionTypes/actionTypes';
+import { FETCH_ALL, CREATE, UPDATE, DELETE, lIKE_POST } from '../ActionTypes/actionTypes';
const posts = (posts = [], action) => {
switch (action.type) {
@@ -15,6 +15,10 @@ const posts = (posts = [], action) => {
case DELETE:
return posts.filter((post) => post._id !== action.payload);
+ case lIKE_POST:
+ console.log(action.payload._id);
+ return posts.map((post) => (post._id === action.payload._id ? action.payload : post));
+
default:
return posts;
}