diff --git a/app/js/components/App.js b/app/js/components/App.js
index cd43917..cf52724 100644
--- a/app/js/components/App.js
+++ b/app/js/components/App.js
@@ -1,5 +1,6 @@
import React, { Component } from 'react';
import { CreatePost } from './CreatePost';
+import { List } from './List';
export class App extends Component {
@@ -8,6 +9,7 @@ export class App extends Component {
DReddit
+
)
}
diff --git a/app/js/components/List.js b/app/js/components/List.js
new file mode 100644
index 0000000..8c5ff8d
--- /dev/null
+++ b/app/js/components/List.js
@@ -0,0 +1,47 @@
+import React, { Component } from 'react';
+import EmbarkJS from 'Embark/EmbarkJS';
+import DReddit from 'Embark/contracts/Dreddit';
+import { Post } from './Post';
+
+export class List extends Component {
+
+ constructor(props) {
+ super(props);
+ this.state = {
+ posts: []
+ };
+ }
+
+ async componentDidMount() {
+ const totalPosts = await DReddit.methods.numPosts().call();
+
+ let list = [];
+
+ for (let i = 0; i < totalPosts; i++) {
+ const post = DReddit.methods.posts(i).call();
+ list.push(post);
+ }
+
+ list = await Promise.all(list);
+ list = list.map((post, index) => {
+ post.id = index;
+ return post;
+ });
+
+ this.setState({ posts: list });
+ }
+
+ render() {
+ return (
+ {this.state.posts.map(post => {
+ return ()
+ })}
+
+ )
+ }
+}
diff --git a/contracts/DReddit.sol b/contracts/DReddit.sol
index 027261c..7a4abe4 100644
--- a/contracts/DReddit.sol
+++ b/contracts/DReddit.sol
@@ -69,5 +69,9 @@ contract DReddit {
Post storage post = posts[_postId];
return uint8(post.voters[msg.sender]);
}
+
+ function numPosts() public view returns (uint) {
+ return posts.length;
+ }
}