Skip to content
This repository has been archived by the owner on Dec 11, 2023. It is now read-only.

Commit

Permalink
User-tag posts and hide broken thumbnails
Browse files Browse the repository at this point in the history
Issue #2
Can now display a proper list of posts for a user and tag combination.

Thumbnails only display if they load correctly.
  • Loading branch information
toniwidmo committed Dec 24, 2017
1 parent a7fce86 commit e83b818
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 19 deletions.
2 changes: 1 addition & 1 deletion config.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"menu": [
{"label": "Home", "type": "static", "args": "home.html"},
{"label": "Profile", "type": "steem", "args": {"show":"profile", "user":"antonchanning"}},
{"label": "Posts", "type": "steem", "args": {"show":"posts", "user":"antonchanning", "tag":"blockpress", "count":3}},
{"label": "Posts", "type": "steem", "args": {"show":"posts", "user":"antonchanning", "tag":"blockpress", "count":10}},
{"label": "Post", "type": "steem", "args": {"show":"post", "user":"dana-varahi", "postid":"first-snow"}},
{"label": "Link", "type": "link", "args": "https://blockpress.me"}
]
Expand Down
2 changes: 1 addition & 1 deletion module/steem/steem-posts.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div class="steem_posts steem_posts_{steem_posts_tag}" id="steem_posts_{steem_post_permlink}">
<h2><a href="javascript:steem_load('{&quot;show&quot;:&quot;post&quot;,&quot;user&quot;:&quot;{steem_posts_author}&quot;,&quot;postid&quot;:&quot;{steem_posts_permlink}&quot;}');">{steem_posts_title}</a></h2>
<img class="steemposts_thumbnail"src="{steem_posts_img}">
<img class="steemposts_thumbnail" src="{steem_posts_img}" style="display:none;" onload="this.style.display = 'inline-block'">
<span class="steem_posts_preview">{steem_posts_preview}</span>
</div>
36 changes: 19 additions & 17 deletions module/steem/steem.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ console.log('args JSON parsed: '+args);
// First clear contentArea, because we might need to make multiple calls to refill it.
$('#contentArea').html('');
steem_posts_displayed = new Array();
getSteemPosts(args.user,args.tag,args.count,'2100-01-01T00:00:00','');
getSteemPosts(args.user,args.tag,args.count,'');
console.log("Get posts for: user(s): "+args.user+", tag(s): "+args.tag+", count: "+args.count);
break;
case "post":
Expand All @@ -57,8 +57,9 @@ function displaySteemPosts(err, posts) {

console.log("steem_username: "+steem_username);

var args = steem_args;
console.log("displaySteemPosts args: "+args);
var content = '', display_count = 0;
var content = '', display_count = steem_posts_displayed.length;
var json_metadata, post_tags, post_obj, body, show_post, last_date, last_permlink, loop_end = false;

var converter = new showdown.Converter();
Expand Down Expand Up @@ -86,16 +87,15 @@ console.log("displaySteemPosts args: "+args);
console.log("created "+i+": "+JSON.stringify(post_obj.created));

if(steem_posts_displayed.indexOf(post_obj.permlink) !== -1) {
loop_end = true;
//loop_end = true;
show_post = false;
} else {
steem_posts_displayed.push(post_obj.permlink);
if (typeof post_obj.created !== "undefined") last_date = post_obj.created;
last_permlink = post_obj.permlink;
console.log("Last permlink: "+last_permlink);
}

if(show_post) {
steem_posts_displayed.push(post_obj.permlink);
display_count++;
//template+="post_obj "+i+": "+JSON.stringify(post_obj)+"<br><br>";
//template+="json_metadata "+i+": "+JSON.stringify(json_metadata);
Expand Down Expand Up @@ -128,25 +128,27 @@ console.log("username: "+steem_username);
console.log("steem_tags: "+steem_tags);
console.log("steem_posts_count: "+steem_posts_count);
console.log("last_permlink: "+last_permlink);
getSteemPosts(steem_username,steem_tags,steem_posts_count,last_date ,last_permlink);
getSteemPosts(steem_username,steem_tags,steem_posts_count,last_permlink);
}
if(loop_end) console.log('Blocked infinite loop. Quitting...');
if(display_count >= steem_posts_count) {
console.log('Reached post limit. Quitting...');
console.log(steem_posts_displayed);
}
if(!loop_end) console.log('Blocked infinite loop. Quitting...');
if(display_count >= steem_posts_count) console.log('Reached post limit. Quitting...');
// Append content to contentArea
$('#contentArea').append(content);
}
function getSteemPosts(usernames,tags,count,beforeDate,lastPermlink) {
console.log('getSteemPosts usernames: '+usernames+' tags: '+tags+' count: '+count+' beforeDate: '+beforeDate+' lastPermlink: '+lastPermlink);
function getSteemPosts(usernames,tags,count,lastPermlink) {
console.log('getSteemPosts usernames: '+usernames+' tags: '+tags+' count: '+count+' lastPermlink: '+lastPermlink);
if (typeof count === "undefined") count=10; // Default to 10 if no count specified.
if (typeof beforeDate === "undefined") beforeDate=''; // Default to 10 if no count specified.
if (typeof lastPermlink === "undefined") lastPermlink=''; // Default to 10 if no count specified.

steem_tags = tags;
steem_posts_count = count;
steem_username = usernames;
console.log('usernames: '+usernames+' tags: '+tags+' count: '+count+' beforeDate: '+beforeDate+' lastPermlink: '+lastPermlink);
console.log('usernames: '+usernames+' tags: '+tags+' count: '+count+' lastPermlink: '+lastPermlink);

steem.api.getDiscussionsByAuthorBeforeDate(usernames, lastPermlink, beforeDate, count, function(err, result){displaySteemPosts(err, result)});
steem.api.getDiscussionsByAuthorBeforeDate(usernames, lastPermlink, '2100-01-01T00:00:00', count, function(err, result){displaySteemPosts(err, result)});
//displaySteemPosts(['AAA']);
}

Expand Down Expand Up @@ -215,7 +217,7 @@ function getSteemProfile(username) {

//Load the showdown library (for parsing markdown)
$.getScript( "lib/showdown/showdown.min.js").done(function( script, textStatus ) {
console.log( textStatus );
//console.log( textStatus );
console.log( "showdown.min.js load was performed." );
})
.fail(function( jqxhr, settings, exception ) {
Expand All @@ -228,9 +230,9 @@ $.getScript( "lib/showdown/showdown.min.js").done(function( script, textStatus )

//Load the steem javascript API
$.getScript( "lib/steem-js/steem.min.js", function( data, textStatus, jqxhr ) {
console.log( data ); // Data returned
console.log( textStatus ); // Success
console.log( jqxhr.status ); // 200
//console.log( data ); // Data returned
//console.log( textStatus ); // Success
//console.log( jqxhr.status ); // 200
console.log( "steem.min.js load was performed." );
});

Expand Down

0 comments on commit e83b818

Please sign in to comment.