From fd0b60a589239039c9c158fbf361c23385c96b30 Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Mon, 20 May 2019 01:00:49 +1000 Subject: [PATCH] Refactoring, smoothed out button visibility --- src/components/pages/profile.jsx | 165 +++++++++++++++++++++---------- 1 file changed, 111 insertions(+), 54 deletions(-) diff --git a/src/components/pages/profile.jsx b/src/components/pages/profile.jsx index cad3a29..917cfc8 100644 --- a/src/components/pages/profile.jsx +++ b/src/components/pages/profile.jsx @@ -48,63 +48,17 @@ class Profile extends React.Component { //main panel let MainPanel; - if (this.state.username != '') { - MainPanel = () => { - return ( -
-
-

Username:

-

{this.state.username}

-
-
-
- -
-

Gold:

-

{this.state.gold}

-
-
-
- -
-

Recruits:

-

{this.state.recruits}

- -
- -
-

Soldiers:

-

{this.state.soldiers}

- - -
- -
-

Spies:

-

{this.state.spies}

- - -
- -
-

Scientists:

-

{this.state.scientists}

- - -
-
- ); - } + if (this.state.username === this.props.username && this.state.username !== '') { + MainPanel = this.MyProfileMainPanel.bind(this); } else { - MainPanel = () => { - return ( -
-

No profile found!

-
- ); + if (this.state.username !== '') { + MainPanel = this.NotMyProfileMainPanel.bind(this); + } else { + MainPanel = this.ProfileNotFoundMainPanel.bind(this); } } + //finally return (

KINGDOM BATTLES!

@@ -199,17 +153,112 @@ class Profile extends React.Component { ); } + MyProfileMainPanel() { + return ( +
+
+

Username:

+

{this.state.username}

+
+
+
+ +
+

Gold:

+

{this.state.gold}

+
+
+
+ +
+

Recruits:

+

{this.state.recruits}

+ +
+ +
+

Soldiers:

+

{this.state.soldiers}

+ + +
+ +
+

Spies:

+

{this.state.spies}

+ + +
+ +
+

Scientists:

+

{this.state.scientists}

+ + +
+
+ ); + } + NotMyProfileSidePanel() { //finally return the side panel return (

Return home

-

Go to { e.preventDefault(); this.requestProfileData(this.props.username); this.props.history.push('/profile'); }}>your profile

+

Go to { e.preventDefault(); this.requestProfileData(this.props.username); this.setWarning(''); this.props.history.push('/profile'); }}>your profile

this.props.history.push('/')} />
); } + NotMyProfileMainPanel() { + return ( +
+
+

Username:

+

{this.state.username}

+
+
+
+ +
+

Gold:

+

{this.state.gold}

+
+
+
+ +
+

Recruits:

+

{this.state.recruits}

+
+
+
+ +
+

Soldiers:

+

{this.state.soldiers}

+
+
+
+ +
+

Spies:

+

{this.state.spies}

+
+
+
+ +
+

Scientists:

+

{this.state.scientists}

+
+
+
+
+ ); + } + LoggedOutSidePanel() { return (
@@ -218,6 +267,14 @@ class Profile extends React.Component { ); } + ProfileNotFoundMainPanel() { + return ( +
+

No profile found!

+
+ ); + } + setWarning(s) { this.setState({ warning: s