@@ -2,20 +2,19 @@ import React, { Component } from "react";
22import { Link } from "react-router-dom" ;
33import { Avatar , Card } from "antd" ;
44import { UserOutlined } from "@ant-design/icons" ;
5- import "../styles/styles.css" ;
5+ import "../../ styles/styles.css" ;
66
77import { connect } from "react-redux" ;
88import {
99 getUser ,
10- followUser ,
11- unFollowUser ,
1210 getBookmarks ,
1311 getFollowers ,
1412 getFollowing ,
1513 getUserWrittenArticles ,
1614 getArticlesLiked ,
17- } from "../redux/actions/get-user" ;
18- import ArticlesList from "./article/articles-list" ;
15+ } from "../../redux/actions/get-user" ;
16+ import ArticlesList from "../article/articles-list" ;
17+ import FollowButton from "./FollowButton" ;
1918
2019class ErrorBoundary extends Component {
2120 state = {
@@ -67,6 +66,9 @@ class User extends Component {
6766 componentDidMount ( ) {
6867 this . props . dispatch ( getUser ( this . props . match . params . id ) ) ;
6968 this . props . dispatch ( getBookmarks ( this . props . match . params . id ) ) ;
69+ if ( this . props . loggedIn ) {
70+ this . props . dispatch ( getFollowing ( this . props . user . id ) ) ;
71+ }
7072 }
7173 componentDidUpdate ( prevProps ) {
7274 if ( this . props . userDetails !== prevProps . userDetails ) {
@@ -92,35 +94,6 @@ class User extends Component {
9294 // return false;
9395 // }
9496
95- handleFollow = ( e ) => {
96- if ( this . props . loggedIn && this . props . user . id !== this . state . user . _id ) {
97- this . props . dispatch ( followUser ( this . props . user . id , this . state . user . _id ) ) ;
98- } else if (
99- this . props . loggedIn &&
100- this . props . user . id === this . state . user . _id
101- ) {
102- alert ( "You cannot follow yourself." ) ;
103- } else {
104- e . preventDefault ( ) ;
105- alert ( "Log In or Register to follow." ) ;
106- }
107- } ;
108-
109- handleUnfollow = ( e ) => {
110- if ( this . props . loggedIn && this . props . user . id !== this . state . user . _id ) {
111- this . props . dispatch (
112- unFollowUser ( this . props . user . id , this . state . user . _id )
113- ) ;
114- } else if (
115- this . props . loggedIn &&
116- this . props . user . id === this . state . user . _id
117- ) {
118- alert ( "You cannot un follow yourself." ) ;
119- } else {
120- e . preventDefault ( ) ;
121- alert ( "Log In or Register to Unfollow." ) ;
122- }
123- } ;
12497 getFollowers = ( e ) => {
12598 e . preventDefault ( ) ;
12699 if ( this . state . user . followers . length === 0 ) {
@@ -186,19 +159,6 @@ class User extends Component {
186159 } ) ;
187160 } ;
188161
189- followButton = ( ) => {
190- return (
191- < div >
192- < button className = "btn btn-primary" onClick = { this . handleFollow } >
193- Follow
194- </ button >
195- < button className = "btn btn-primary" onClick = { this . handleUnfollow } >
196- Un Follow
197- </ button >
198- </ div >
199- ) ;
200- } ;
201-
202162 render ( ) {
203163 return (
204164 // <div>
@@ -333,9 +293,9 @@ class User extends Component {
333293 </ a >
334294 </ small >
335295 </ p >
336- < button className = "btn btn-success btn-block" >
337- < span className = "fa fa-plus-circle" > </ span > Follow { " " }
338- </ button >
296+
297+ < FollowButton />
298+
339299 < button
340300 type = "button"
341301 className = "btn btn-success btn-block"
0 commit comments