-
Notifications
You must be signed in to change notification settings - Fork 0
/
redditapi.js
32 lines (30 loc) · 1003 Bytes
/
redditapi.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
let auther;
export default {
search: function (searchTerm, searchLimit, sortBy) {
console.log(
`http://www.reddit.com/r/${searchTerm}/${sortBy}/.json?limit=${searchLimit}`
);
return fetch(
`http://www.reddit.com/r/${searchTerm}/${sortBy}/.json?limit=${searchLimit}`
)
.then((res) => res.json())
.then((data) => {
auther = data.data.after;
return data.data.children.map((data) => data.data);
})
.catch((err) => console.log(err));
},
LoadMore: function(searchTerm, searchLimit, sortBy){
console.log(
`http://www.reddit.com/r/${searchTerm}/${sortBy}/.json?limit=${searchLimit}&after=${auther}`
);
return fetch(
`http://www.reddit.com/r/${searchTerm}/${sortBy}/.json?limit=${searchLimit}&after=${auther}`
)
.then((res) => res.json())
.then((data) => {
auther = data.data.after;
return data.data.children.map((data) => data.data);
});
}
};