Skip to content

Commit

Permalink
Merge pull request #29 from andela/ft-users-should-coment-on-articles…
Browse files Browse the repository at this point in the history
…-164047029

#164047029 User can comment on articles
  • Loading branch information
Derrickkip committed May 6, 2019
2 parents 40139f0 + 795559f commit bbf5af6
Show file tree
Hide file tree
Showing 48 changed files with 1,562 additions and 308 deletions.
23 changes: 12 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@
"draft-js": "^0.10.5",
"draft-js-export-html": "^1.3.3",
"draftjs-to-html": "^0.8.4",
"enzyme": "^3.8.0",
"enzyme-adapter-react-16": "^1.9.1",
"enzyme": "^3.9.0",
"enzyme-adapter-react-16": "^1.12.1",
"enzyme-to-json": "^3.3.5",
"eslint-plugin-import": "^2.16.0",
"eslint-plugin-jest": "^22.4.1",
"eslint-plugin-import": "^2.17.2",
"eslint-plugin-jest": "^22.5.1",
"eslint-plugin-jsx-a11y": "^6.2.1",
"eslint-plugin-react": "^7.12.4",
"html-react-parser": "^0.7.0",
"jest-fetch-mock": "^2.1.2",
"fetch-mock": "^7.3.1",
"html-to-draftjs": "^1.4.0",
"import": "0.0.6",
"jest-fetch-mock": "^2.1.2",
"jest-mock": "^24.7.0",
"mdbreact": "^4.12.0",
"mdbreact": "^4.13.0",
"moxios": "^0.4.0",
"node-sass": "^4.11.0",
"npm-run-all": "^4.1.5",
Expand All @@ -37,16 +37,18 @@
"react-draft-wysiwyg": "^1.13.2",
"react-facebook-login": "^4.1.1",
"react-google-login": "^5.0.4",
"react-moment": "^0.9.2",
"react-native-cloudinary": "^1.0.1",
"react-redux": "^6.0.1",
"react-redux": "^7.0.2",
"react-router": "^5.0.0",
"react-router-dom": "^5.0.0",
"react-scripts": "2.1.8",
"react-share": "^2.4.0",
"react-scripts": "3.0.0",
"react-social-login": "^3.4.4",
"react-tag-input": "^6.4.0",
"react-tagsinput": "^3.19.0",
"react-testing-library": "^6.1.2",
"reactstrap": "^8.0.0",
"reading-time": "^1.2.0",
"redux": "^4.0.1",
"redux-devtools-extension": "^2.13.8",
Expand Down Expand Up @@ -90,13 +92,12 @@
"eslint-config-airbnb": "^17.1.0",
"eslint-config-airbnb-base": "^13.1.0",
"eslint-config-prettier": "^4.1.0",
"eslint-plugin-import": "^2.16.0",
"eslint-plugin-jest": "^22.4.1",
"eslint-plugin-import": "^2.17.2",
"eslint-plugin-jest": "^22.5.1",
"eslint-plugin-jsx-a11y": "^6.2.1",
"eslint-plugin-react": "^7.12.4",
"node-sass": "^4.11.0",
"npm-run-all": "^4.1.5",
"prettier": "^1.16.4",
"redux-mock-store": "^1.5.3",
"redux-promise-middleware": "^6.1.0",
"sinon": "^7.3.2"
Expand Down
11 changes: 11 additions & 0 deletions src/App.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.App-header {
background-color: #F6FAF9;
min-height: 100vh;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
font-size: calc(10px + 2vmin);
color: black; }
.App-header label {
color: black; }
11 changes: 11 additions & 0 deletions src/actions/action_types.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,21 @@ export const REGISTER_SUMBITTABLE = 'REGISTER_SUBMITTABLE';
export const SOCIAL_LOGIN_SUCCESS = 'SOCIAL_LOGIN_SUCCESS';

export const SOCIAL_LOGIN_ERROR = 'SOCIAL_LOGIN_ERROR';

export const FETCH_FOLLOWING = 'FETCH_FOLLOWING';

export const FETCH_FOLLOWERS = 'FETCH_FOLLOWERS';

export const FOLLOW_USER = 'FOLLOW_USER';

export const UNFOLLOW_USER = 'UNFOLLOW_USER';

export const FETCH_COMMENTS = 'FETCH_COMMENTS';

export const COMMENT_ON_ARTICLE = 'COMMENT_ON_ARTICLE';

export const COMMENT_ON_COMMENT = 'COMMENT_ON_COMMENT';

export const EDIT_COMMENT = 'EDIT_COMMENT';

export const LOCAL_STORAGE = 'LOCAL_STORAGE';
85 changes: 85 additions & 0 deletions src/actions/comments.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import axios from 'axios';
import axiosHeader from '../axios_config';
import {
FETCH_COMMENTS, COMMENT_ON_ARTICLE, COMMENT_ON_COMMENT, EDIT_COMMENT,
} from './action_types';

export const fetchArticleComments = slug => async (dispatch) => {
await axios
.get(
`${
process.env.REACT_APP_BASE_URL
}/articles/${slug}/comments/`,
axiosHeader,
)
.then((result) => {
dispatch({
type: FETCH_COMMENTS,
payload: result.data,
});
})
.catch(() => {});
};

export const CommentOnArticle = (slug, comment) => async (dispatch) => {
await axios
.post(
`${
process.env.REACT_APP_BASE_URL
}/articles/${slug}/comments/`,
{ comment },
axiosHeader,
)
.then((result) => {
dispatch({
type: COMMENT_ON_ARTICLE,
payload: result.data,
});
dispatch(fetchArticleComments(slug));
})
.catch(() => {
alert('Server Error'); // eslint-disable-line no-alert
});
};

export const CommentOnComment = (slug, commentId, comment) => async (dispatch) => {
await axios
.post(
`${
process.env.REACT_APP_BASE_URL
}/articles/${slug}/comments/${commentId}/subcomment`,
{ comment },
axiosHeader,
)
.then((result) => {
dispatch({
type: COMMENT_ON_COMMENT,
payload: result.data,
});
dispatch(fetchArticleComments(slug));
})
.catch(() => {
alert('Server Error'); // eslint-disable-line no-alert
});
};

export const editComment = (slug, commentId, comment) => async (dispatch) => {
await axios
.put(
`${
process.env.REACT_APP_BASE_URL
}/articles/${slug}/comments/${commentId}`,
{ comment },
axiosHeader,
)
.then((result) => {
dispatch({
type: EDIT_COMMENT,
payload: result.data,
});
dispatch(fetchArticleComments(slug));
})
.catch(() => {
alert('Server Error'); // eslint-disable-line no-alert
});
};
7 changes: 4 additions & 3 deletions src/actions/getArticles.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import axios from 'axios';
import axiosHeader from '../axios_config';
import { FETCH_ARTICLES, ACTION_FAILED } from './types';

const apiURL = 'https://aholympian.herokuapp.com/api/';

export const getArticles = () => async (dispatch) => {
const getArticles = () => async (dispatch) => {
await axios
.get(`${apiURL}articles`, axiosHeader)
.get(`${apiURL}articles`, { headers: { 'Content-Type': 'application/json' } })
.then((result) => {
dispatch({ type: FETCH_ARTICLES, payload: result.data });
})
Expand All @@ -17,3 +16,5 @@ export const getArticles = () => async (dispatch) => {
});
});
};

export default getArticles;
2 changes: 2 additions & 0 deletions src/actions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ export * from './register';
export * from './profile';
export * from './following';
export * from './followUnfollow';
export * from './comments';
export * from './localStorage';
18 changes: 18 additions & 0 deletions src/actions/localStorage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { LOCAL_STORAGE } from './action_types';

export const userDefault = {
username: '',
email: '',
token: '',
};

export const fetchLocalStorage = () => (dispatch) => {
let userDetails = { user: userDefault };
if (localStorage.getItem('user')) {
userDetails = JSON.parse(localStorage.getItem('user'));
}

dispatch({
type: LOCAL_STORAGE, payload: userDetails.user,
});
};
3 changes: 1 addition & 2 deletions src/actions/register.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import axios from 'axios';
import axiosHeader from '../axios_config';
import * as actionTypes from './action_types';

export const submitStatus = submitState => dispatch => dispatch({
Expand All @@ -13,7 +12,7 @@ export const registerSuccess = () => dispatch => dispatch({
export const registerUser = userdata => async (dispatch) => {
const postData = JSON.stringify({ user: userdata });
await axios
.post(`${process.env.REACT_APP_BASE_URL}/users/`, postData, axiosHeader)
.post(`${process.env.REACT_APP_BASE_URL}/users/`, postData, { headers: { 'Content-Type': 'application/json' } })
.then((result) => {
dispatch({ type: actionTypes.REGISTER_USER, payload: result.data.user });
setTimeout(() => {
Expand Down
2 changes: 1 addition & 1 deletion src/actions/tests/getarticles.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import thunk from 'redux-thunk';
import moxios from 'moxios';

import { FETCH_ARTICLES } from '../types';
import { getArticles } from '../getArticles';
import getArticles from '../getArticles';

const middlewares = [thunk];
const mockStore = configureMockStore(middlewares);
Expand Down
11 changes: 3 additions & 8 deletions src/axios_config.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
import axios from 'axios';
let userToken = 'none';

let user = JSON.parse(localStorage.getItem('user'));

let userToken;
try {
user = JSON.parse(localStorage.getItem('user'));
const user = JSON.parse(localStorage.getItem('user'));
const { token } = user.user;
userToken = token;
} catch (err) {
const error = err.message;
}
} catch (err) {}


const axiosHeader = {
Expand Down
39 changes: 39 additions & 0 deletions src/components/Articles/Articles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
.side-bar {
position: sticky;
top: 4rem;
z-index: 1000;
height: calc(100vh - 4rem);
background-color: #f7f7f7; }

.draw-line-horizontal {
border-bottom: 1px solid; }

.draw-line-vertical {
border-right: 1px solid;
top: 50px;
font-size: small;
text-align: left; }

.draw-line-vertical:hover {
color: #17907C; }

.container-height {
padding-top: 150px; }

.article-container {
background: #FFFFFF;
border: 1px solid #efefef;
min-width: 80%;
border-radius: 5px;
padding: 50px;
margin-bottom: 30px;
text-align: justify; }

.image-wrapper img {
width: 100% !important; }

.view-font {
font-size: 16px !important; }

.demo-editor {
font-size: 16px !important; }
Loading

0 comments on commit bbf5af6

Please sign in to comment.