This repository has been archived by the owner on Mar 15, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 61
/
Copy pathNewsfeed.js
97 lines (93 loc) · 1.96 KB
/
Newsfeed.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import React from "react";
import InlineCss from "react-inline-css";
import Transmit from "lib/react-transmit";
import Story from "example/Story";
/**
* @class Newsfeed
*/
const Newsfeed = React.createClass({
render () {
/**
* Transmitted prop is guaranteed.
*/
const newsfeed = this.props.newsfeed;
return (
<InlineCss stylesheet={Newsfeed.css()}>
<main>
{newsfeed.map((story, key) => {
return <Story story={story} key={key}/>;
})}
</main>
<footer>
<button onMouseDown={this.onLoadMore}>
Load more
</button>
</footer>
</InlineCss>
);
},
onLoadMore () {
/**
* Call this.props.setQueryParams() to tell Transmit to query again.
*/
this.props.setQueryParams({
currentNewsfeed: this.props.newsfeed,
nextStoryId: this.props.queryParams.nextStoryId + 1
}).then((queryResults) => {
/**
* This part is optional. It allows you to capture the query results.
*/
console.log("Newsfeed.setQueryParams: ", queryResults);
});
}
});
/**
* Higher-order Transmit component that will contain the above React component.
*/
export default Transmit.createContainer(Newsfeed, {
/**
* Default query params.
*/
queryParams: {
currentNewsfeed: [],
nextStoryId: 1
},
queries: {
/**
* The "newsfeed" query will concatenate the next Story to the current newsfeed, and returns
* the updated newsfeed in a Promise.
*/
newsfeed (queryParams) {
return (
Story.getQuery(
"story", {storyId: queryParams.nextStoryId}
).then((nextStory) => {
return queryParams.currentNewsfeed.concat([nextStory]);
})
);
}
}
});
/**
* Style this example app like a Facebook feed.
*/
Newsfeed.css = function () {
return `
& {
width: 500px;
margin: 0 auto;
}
& > footer {
text-align: center;
margin: 20px;
}
& button {
border: 1px solid #ccc;
background: #f4f4f4;
padding: 5px 15px;
border-radius: 3px;
cursor: pointer;
outline: 0;
}
`;
};