-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathapp.js
More file actions
49 lines (42 loc) · 1.81 KB
/
app.js
File metadata and controls
49 lines (42 loc) · 1.81 KB
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
const dsteem = require('dsteem');
let opts = {};
//connect to production server
opts.addressPrefix = 'STM';
opts.chainId =
'0000000000000000000000000000000000000000000000000000000000000000';
//connect to server which is connected to the network/production
const client = new dsteem.Client('https://api.steemit.com');
//filter change selection function
window.getPosts = async () => {
const filter = document.getElementById('filters').value;
const query = {
tag: document.getElementById('tag').value,
limit: 5,
};
console.log('Post assembled.\nFilter:', filter, '\nQuery:', query);
client.database
.getDiscussions(filter, query)
.then(result => {
console.log('Response received:', result);
if (result) {
var posts = [];
result.forEach(post => {
const json = JSON.parse(post.json_metadata);
const image = json.image ? json.image[0] : '';
const title = post.title;
const author = post.author;
const created = new Date(post.created).toDateString();
posts.push(
`<div class="list-group-item"><h4 class="list-group-item-heading">${title}</h4><p>by ${author}</p><center><img src="${image}" class="img-responsive center-block" style="max-width: 450px"/></center><p class="list-group-item-text text-right text-nowrap">${created}</p></div>`
);
});
document.getElementById('postList').innerHTML = posts.join('');
} else {
document.getElementById('postList').innerHTML = 'No result.';
}
})
.catch(err => {
console.log(err);
alert(`Error:${err}, try again`);
});
};