diff --git a/contracts/Forum.sol b/contracts/Forum.sol index e96b908..7d9c5e3 100644 --- a/contracts/Forum.sol +++ b/contracts/Forum.sol @@ -8,6 +8,7 @@ contract Forum { OrbitDB orbitdb; uint[] topicIDs; // IDs of the topics the user created uint[] postIDs; // IDs of the posts the user created + uint timestamp; bool signedUp; // Helper variable for hasUserSignedUp() } @@ -20,7 +21,9 @@ contract Forum { function signUp(string username, string orbitDBId, string orbitTopicsDB, string orbitPostsDB, string orbitPublicKey, string orbitPrivateKey) public returns (bool) { require (!hasUserSignedUp(msg.sender), "User has already signed up."); require(!isUserNameTaken(username), "Username is already taken."); - users[msg.sender] = User(username, OrbitDB(orbitDBId, orbitTopicsDB, orbitPostsDB, orbitPublicKey, orbitPrivateKey), new uint[](0), new uint[](0), true); + users[msg.sender] = User(username, + OrbitDB(orbitDBId,orbitTopicsDB, orbitPostsDB, orbitPublicKey, orbitPrivateKey), + new uint[](0), new uint[](0), block.timestamp, true); userAddresses[username] = msg.sender; emit UserSignedUp(username, msg.sender); return true; @@ -56,15 +59,20 @@ contract Forum { } function getUserTopics(address userAddress) public view returns (uint[]) { - require (hasUserSignedUp(msg.sender), "User hasn't signed up yet."); + require (hasUserSignedUp(userAddress), "User hasn't signed up yet."); return users[userAddress].topicIDs; } function getUserPosts(address userAddress) public view returns (uint[]) { - require (hasUserSignedUp(msg.sender), "User hasn't signed up yet."); + require (hasUserSignedUp(userAddress), "User hasn't signed up yet."); return users[userAddress].postIDs; } + function getUserDateOfRegister(address userAddress) public view returns (uint) { + require (hasUserSignedUp(userAddress), "User hasn't signed up yet."); + return users[userAddress].timestamp; + } + //----------------------------------------OrbitDB---------------------------------------- struct OrbitDB { string id; // TODO: set an upper bound instead of arbitrary string @@ -136,8 +144,6 @@ contract Forum { event TopicCreated(uint topicID, uint postID); event PostCreated(uint postID, uint topicID); - /* event NumberOfTopicsReceived(uint numTopics); - event TopicReceived(string orbitTopicsDB, address author, string username, uint timestamp, uint[] postIDs); */ function createTopic() public returns (uint, uint) { require(hasUserSignedUp(msg.sender)); // Only registered users can create topics @@ -168,7 +174,6 @@ contract Forum { } function getNumberOfTopics() public view returns (uint) { - /* emit NumberOfTopicsReceived(numTopics); */ return numTopics; } diff --git a/src/assets/css/App.css b/src/assets/css/App.css index 1ff9452..c7946cf 100644 --- a/src/assets/css/App.css +++ b/src/assets/css/App.css @@ -184,15 +184,15 @@ body, /* FLOATING BUTTONS */ .floating-button{ - position:fixed; - width:60px; - height:60px; - bottom:40px; - right:40px; - background-color:#0C9; - color:#FFF; - border-radius:50px; - text-align:center; + position: fixed; + width: 60px; + height: 60px; + bottom: 40px; + right: 40px; + background-color: #0C9; + color: #FFF; + border-radius: 50px; + text-align: center; box-shadow: 2px 2px 3px #999; } diff --git a/src/components/FloatingButton.js b/src/components/FloatingButton.js index 649cf96..c6415f5 100644 --- a/src/components/FloatingButton.js +++ b/src/components/FloatingButton.js @@ -1,11 +1,19 @@ import React from 'react'; +import { Link } from 'react-router'; const FloatingButton = (props) => { return ( -
- -
++ +
+ + :+ +
+ }Number of posts: {props.numberOfPosts}
+ {props.dateOfRegister && ++ Member since: {props.dateOfRegister} +
+ } {props.self &&(this.handleTabClick("topics"))} @@ -83,11 +88,29 @@ class Profile extends Component { } componentWillReceiveProps() { + if (this.state.getDateOfRegisterTransactionState === null){ + if (this.drizzle.contracts[contract]){ //Waits until drizzle is initialized + this.dateOfRegisterKey = this.drizzle.contracts[contract] + .methods[contractMethods.getDateOfRegister].cacheCall(this.state.userAddress); + this.setState({'getDateOfRegisterTransactionState': "IN_PROGRESS"}); + } + } + if (this.state.getDateOfRegisterTransactionState === "IN_PROGRESS") { + let currentDrizzleState = this.drizzle.store.getState(); + let dataFetched = (currentDrizzleState + .contracts[contract][contractMethods.getDateOfRegister])[this.dateOfRegisterKey]; + if (dataFetched){ + this.setState({ + 'dateOfRegister': epochTimeConverter(dataFetched.value), + 'getDateOfRegisterTransactionState': "SUCCESS" + }); + } + } + if (this.state.getOrbitDBTransactionState === null){ if (this.drizzle.contracts[contract]){ //Waits until drizzle is initialized - //This gets called only once but should be called every time someone posts this.orbitDBIdKey = this.drizzle.contracts[contract] - .methods[contractMethods.getOrbitDB].cacheCall(this.match.userAddress); + .methods[contractMethods.getOrbitDB].cacheCall(this.state.userAddress); this.setState({'getOrbitDBTransactionState': "IN_PROGRESS"}); } } @@ -105,9 +128,8 @@ class Profile extends Component { if (this.state.getTopicsTransactionState === null){ if (this.drizzle.contracts[contract]){ //Waits until drizzle is initialized - //This gets called only once but should be called every time someone posts this.getTopicsKey = this.drizzle.contracts[contract] - .methods[contractMethods.getUserTopics].cacheCall(this.match.userAddress); + .methods[contractMethods.getUserTopics].cacheCall(this.state.userAddress); this.setState({'getTopicsTransactionState': "IN_PROGRESS"}); } } @@ -125,9 +147,8 @@ class Profile extends Component { if (this.state.getPostsTransactionState === null){ if (this.drizzle.contracts[contract]){ //Waits until drizzle is initialized - //This gets called only once but should be called every time someone posts this.getPostsKey = this.drizzle.contracts[contract] - .methods[contractMethods.getUserPosts].cacheCall(this.match.userAddress); + .methods[contractMethods.getUserPosts].cacheCall(this.state.userAddress); this.setState({'getPostsTransactionState': "IN_PROGRESS"}); } } diff --git a/src/containers/TopicContainer.js b/src/containers/TopicContainer.js index 1208c89..9bd1a46 100644 --- a/src/containers/TopicContainer.js +++ b/src/containers/TopicContainer.js @@ -63,18 +63,18 @@ class Topic extends Component { ); } else { topicContents = ( - this.state.posting - ?(