Skip to content

Commit

Permalink
Fetch and display steemask trending and hot discussions
Browse files Browse the repository at this point in the history
  • Loading branch information
profchydon committed May 31, 2018
1 parent eb9f537 commit 573bfc2
Show file tree
Hide file tree
Showing 4 changed files with 263 additions and 78 deletions.
1 change: 0 additions & 1 deletion public/css/style.css
Expand Up @@ -117,7 +117,6 @@ textarea.form-control {

.content-right {
border-top: 10px solid #337ab7 !important;
border-bottom: 10px solid #337ab7 !important;
}

h2.quest-h2 {
Expand Down
330 changes: 257 additions & 73 deletions public/js/main.js
@@ -1,76 +1,260 @@
$(document).ready(function () {

var url = 'https://api.steemjs.com/get_discussions_by_created?query={"tag":"steemjet", "limit": "100"}';

jQuery.ajax({
type: "GET",
url: url,

success: function (response) {

var post = response;

$.each(post,function(key,value){

var body = jQuery.trim(value.body).substring(0, 600);
var img = "https://steemitimages.com/u/"+value.author+"/avatar";
var pending_payout = parseFloat(value.pending_payout_value);
var paid_out = parseFloat(value.total_payout_value) + parseFloat(value.curator_payout_value);
if (pending_payout != 0.00) {
var payout = pending_payout;
}else {
var payout = paid_out;
}
var tags = JSON.parse(value.json_metadata);

// Instantiate a new showdown converter object
var converter = new showdown.Converter();

// Set options
converter.setOption('metadata', 'true');
converter.setOption('backslashEscapesHTMLTags', 'true');
converter.setOption('requireSpaceBeforeHeadingText', 'true');
converter.setOption('simpleLineBreaks', 'true');
converter.setOption('disableForced4SpacesIndentedSublists', 'true');
converter.setOption('smartIndentationFix', 'true');
converter.setOption('literalMidWordAsterisks', 'true');
converter.setOption('literalMidWordUnderscores', 'true');
converter.setOption('excludeTrailingPunctuationFromURLs', 'true');
converter.setOption('simplifiedAutoLink', 'true');
converter.setOption('parseImgDimensions', 'true');
converter.setOption('omitExtraWLInCodeBlocks', 'true');
converter.setOption('noHeaderId', 'true');
converter.setOption('customizedHeaderId', 'true');
converter.setOption('ghCompatibleHeaderId', 'true');
converter.setOption('prefixHeaderId', 'true');
converter.setOption('rawPrefixHeaderId', 'true');
converter.setOption('rawHeaderId', 'true');
converter.setOption('headerLevelStart', 'true');
converter.setOption('excludeTrailingPunctuationFromURLs', 'true');
converter.setOption('strikethrough', 'true');
converter.setOption('tables', 'true');
converter.setOption('tablesHeaderId', 'true');

//converts markdown to html
body = converter.makeHtml(body);

body = body.replace(/(<([^>]+)>)/ig,"").replace(/<a(\s[^>]*)?>.*?<\/a>/ig,"").replace(/(?:https?|ftp):\/\/[\n\S]+/g,"").substr(0, 600) + '...';

// console.log(tags);

var mainpost = '<article class="question question-type-normal"><div class="span-top"></div><div class="span-inner"><h2 class="quest-h2"><a href="" class="question-a">'+value.title+'</a></h2><div class="question-inner"><div class="clearfix"></div><p class="question-desc">'+body+'...'+'</p><div class=""><img src="'+img+'" alt="profile-img" class="profile-img-dashboard img-responsive"><h4 class="username-dashboard">'+value.author+'</h4><h5 class="time-dashboard"> </h5><h5 class="comment-count"><i class="fa fa-comment" aria-hidden="true"></i>'+value.children+'</h5><h5 class="upvote-count"><i class="fa fa-heart" aria-hidden="true"></i>'+value.net_votes+'</h5><h5 class="payout-dashboard">$'+payout+'</h5></div></div></div></article>';

$('.loader').hide();

$('#holder-inner').append(mainpost);

})

},
error: function (xhr) {
//on error show error message
console.log(xhr);
},

});
function fetchFeeds() {
var query = { limit: 100, tag: "steemask",};

steem.api.getDiscussionsByCreated(query, function (err, result) {

var post = result;

$.each(post,function(key,value){

var body = jQuery.trim(value.body).substring(0, 600);
var img = "https://steemitimages.com/u/"+value.author+"/avatar";
var pending_payout = parseFloat(value.pending_payout_value);
var paid_out = parseFloat(value.total_payout_value) + parseFloat(value.curator_payout_value);
if (pending_payout != 0.00) {
var payout = pending_payout;
}else {
var payout = paid_out;
}
var tags = JSON.parse(value.json_metadata);

tags = tags.tags;

// Instantiate a new showdown converter object
var converter = new showdown.Converter();

// Set options
converter.setOption('metadata', 'true');
converter.setOption('backslashEscapesHTMLTags', 'true');
converter.setOption('requireSpaceBeforeHeadingText', 'true');
converter.setOption('simpleLineBreaks', 'true');
converter.setOption('disableForced4SpacesIndentedSublists', 'true');
converter.setOption('smartIndentationFix', 'true');
converter.setOption('literalMidWordAsterisks', 'true');
converter.setOption('literalMidWordUnderscores', 'true');
converter.setOption('excludeTrailingPunctuationFromURLs', 'true');
converter.setOption('simplifiedAutoLink', 'true');
converter.setOption('parseImgDimensions', 'true');
converter.setOption('omitExtraWLInCodeBlocks', 'true');
converter.setOption('noHeaderId', 'true');
converter.setOption('customizedHeaderId', 'true');
converter.setOption('ghCompatibleHeaderId', 'true');
converter.setOption('prefixHeaderId', 'true');
converter.setOption('rawPrefixHeaderId', 'true');
converter.setOption('rawHeaderId', 'true');
converter.setOption('headerLevelStart', 'true');
converter.setOption('excludeTrailingPunctuationFromURLs', 'true');
converter.setOption('strikethrough', 'true');
converter.setOption('tables', 'true');
converter.setOption('tablesHeaderId', 'true');

//converts markdown to html
body = converter.makeHtml(body);

body = body.replace(/(<([^>]+)>)/ig,"").replace(/<a(\s[^>]*)?>.*?<\/a>/ig,"").replace(/(?:https?|ftp):\/\/[\n\S]+/g,"").substr(0, 600) + '...';

// console.log(tags);

var mainpost = '<article class="question question-type-normal"><div class="span-top"></div><div class="span-inner"><h2 class="quest-h2"><a href="" class="question-a">'+value.title+'</a></h2><div class="question-inner"><div class="clearfix"></div><p class="question-desc">'+body+'...'+'</p><div class=""><img src="'+img+'" alt="profile-img" class="profile-img-dashboard img-responsive"><h4 class="username-dashboard">'+value.author+'</h4><h5 class="time-dashboard"> </h5><h5 class="comment-count"><i class="fa fa-comment" aria-hidden="true"></i>'+value.children+'</h5><h5 class="upvote-count"><i class="fa fa-heart" aria-hidden="true"></i>'+value.net_votes+'</h5><h5 class="payout-dashboard">$'+payout+'</h5><div class="tags-block pull-right"><a href="/{{ $tag }}" class="tags">'+tags+'</a></div></div></div></div></article>';

$('.loader').hide();

$('#holder-inner').append(mainpost);

})

});
}

fetchFeeds();

$('#trending').click(function () {

// Hide present feed
$('#holder-inner').hide();
$('#holder-inner-trending').hide();
$('#holder-inner-hot').hide();

// Show animation while fetching data
$('.loader').show();

// Instantiate query parameters
var query = { limit: 100, tag: "steemask",};

//
steem.api.getDiscussionsByTrending(query, function (err, result) {

// Assign result to a variable
var post = result;

// Loop through result for proccess data
$.each(post,function(key,value){

// Lets trim body content to display a reduced amount of data on homepage
var body = jQuery.trim(value.body).substring(0, 600);

// Fetch User profile picture
var img = "https://steemitimages.com/u/"+value.author+"/avatar";

// Convert Post pending payout to float data type
var pending_payout = parseFloat(value.pending_payout_value);

// If post is already paid out, calculate the amount that was paid out and convert to float
var paid_out = parseFloat(value.total_payout_value) + parseFloat(value.curator_payout_value);

//
if (pending_payout != 0.00) {
var payout = pending_payout;
}else {
var payout = paid_out;
}

var tags = JSON.parse(value.json_metadata);

tags = tags.tags;

// Instantiate a new showdown converter object
var converter = new showdown.Converter();

// Set options
converter.setOption('metadata', 'true');
converter.setOption('backslashEscapesHTMLTags', 'true');
converter.setOption('requireSpaceBeforeHeadingText', 'true');
converter.setOption('simpleLineBreaks', 'true');
converter.setOption('disableForced4SpacesIndentedSublists', 'true');
converter.setOption('smartIndentationFix', 'true');
converter.setOption('literalMidWordAsterisks', 'true');
converter.setOption('literalMidWordUnderscores', 'true');
converter.setOption('excludeTrailingPunctuationFromURLs', 'true');
converter.setOption('simplifiedAutoLink', 'true');
converter.setOption('parseImgDimensions', 'true');
converter.setOption('omitExtraWLInCodeBlocks', 'true');
converter.setOption('noHeaderId', 'true');
converter.setOption('customizedHeaderId', 'true');
converter.setOption('ghCompatibleHeaderId', 'true');
converter.setOption('prefixHeaderId', 'true');
converter.setOption('rawPrefixHeaderId', 'true');
converter.setOption('rawHeaderId', 'true');
converter.setOption('headerLevelStart', 'true');
converter.setOption('excludeTrailingPunctuationFromURLs', 'true');
converter.setOption('strikethrough', 'true');
converter.setOption('tables', 'true');
converter.setOption('tablesHeaderId', 'true');

//converts markdown to html
body = converter.makeHtml(body);

body = body.replace(/(<([^>]+)>)/ig,"").replace(/<a(\s[^>]*)?>.*?<\/a>/ig,"").replace(/(?:https?|ftp):\/\/[\n\S]+/g,"").substr(0, 600) + '...';

// console.log(tags);

var mainpost = '<article class="question question-type-normal"><div class="span-top"></div><div class="span-inner"><h2 class="quest-h2"><a href="" class="question-a">'+value.title+'</a></h2><div class="question-inner"><div class="clearfix"></div><p class="question-desc">'+body+'...'+'</p><div class=""><img src="'+img+'" alt="profile-img" class="profile-img-dashboard img-responsive"><h4 class="username-dashboard">'+value.author+'</h4><h5 class="time-dashboard"> </h5><h5 class="comment-count"><i class="fa fa-comment" aria-hidden="true"></i>'+value.children+'</h5><h5 class="upvote-count"><i class="fa fa-heart" aria-hidden="true"></i>'+value.net_votes+'</h5><h5 class="payout-dashboard">$'+payout+'</h5><div class="tags-block pull-right"><a href="/{{ $tag }}" class="tags">'+tags+'</a></div></div></div></div></article>';

$('.loader').hide();

$('#holder-inner-trending').append(mainpost);
$('#holder-inner-trending').show();

})

});

})

$('#hot').click(function () {

// Hide present feed
$('#holder-inner').hide();
$('#holder-inner-trending').hide();
$('#holder-inner-hot').hide();

// Show animation while fetching data
$('.loader').show();

// Instantiate query parameters
var query = { limit: 100, tag: "steemask",};

//
steem.api.getDiscussionsByHot(query, function (err, result) {

// Assign result to a variable
var post = result;

// Loop through result for proccess data
$.each(post,function(key,value){

// Lets trim body content to display a reduced amount of data on homepage
var body = jQuery.trim(value.body).substring(0, 600);

// Fetch User profile picture
var img = "https://steemitimages.com/u/"+value.author+"/avatar";

// Convert Post pending payout to float data type
var pending_payout = parseFloat(value.pending_payout_value);

// If post is already paid out, calculate the amount that was paid out and convert to float
var paid_out = parseFloat(value.total_payout_value) + parseFloat(value.curator_payout_value);

//
if (pending_payout != 0.00) {
var payout = pending_payout;
}else {
var payout = paid_out;
}

var tags = JSON.parse(value.json_metadata);

tags = tags.tags;

// Instantiate a new showdown converter object
var converter = new showdown.Converter();

// Set options
converter.setOption('metadata', 'true');
converter.setOption('backslashEscapesHTMLTags', 'true');
converter.setOption('requireSpaceBeforeHeadingText', 'true');
converter.setOption('simpleLineBreaks', 'true');
converter.setOption('disableForced4SpacesIndentedSublists', 'true');
converter.setOption('smartIndentationFix', 'true');
converter.setOption('literalMidWordAsterisks', 'true');
converter.setOption('literalMidWordUnderscores', 'true');
converter.setOption('excludeTrailingPunctuationFromURLs', 'true');
converter.setOption('simplifiedAutoLink', 'true');
converter.setOption('parseImgDimensions', 'true');
converter.setOption('omitExtraWLInCodeBlocks', 'true');
converter.setOption('noHeaderId', 'true');
converter.setOption('customizedHeaderId', 'true');
converter.setOption('ghCompatibleHeaderId', 'true');
converter.setOption('prefixHeaderId', 'true');
converter.setOption('rawPrefixHeaderId', 'true');
converter.setOption('rawHeaderId', 'true');
converter.setOption('headerLevelStart', 'true');
converter.setOption('excludeTrailingPunctuationFromURLs', 'true');
converter.setOption('strikethrough', 'true');
converter.setOption('tables', 'true');
converter.setOption('tablesHeaderId', 'true');

//converts markdown to html
body = converter.makeHtml(body);

body = body.replace(/(<([^>]+)>)/ig,"").replace(/<a(\s[^>]*)?>.*?<\/a>/ig,"").replace(/(?:https?|ftp):\/\/[\n\S]+/g,"").substr(0, 600) + '...';

// console.log(tags);

var mainpost = '<article class="question question-type-normal"><div class="span-top"></div><div class="span-inner"><h2 class="quest-h2"><a href="" class="question-a">'+value.title+'</a></h2><div class="question-inner"><div class="clearfix"></div><p class="question-desc">'+body+'...'+'</p><div class=""><img src="'+img+'" alt="profile-img" class="profile-img-dashboard img-responsive"><h4 class="username-dashboard">'+value.author+'</h4><h5 class="time-dashboard"> </h5><h5 class="comment-count"><i class="fa fa-comment" aria-hidden="true"></i>'+value.children+'</h5><h5 class="upvote-count"><i class="fa fa-heart" aria-hidden="true"></i>'+value.net_votes+'</h5><h5 class="payout-dashboard">$'+payout+'</h5><div class="tags-block pull-right"><a href="/{{ $tag }}" class="tags">'+tags+'</a></div></div></div></div></article>';

$('.loader').hide();

$('#holder-inner-hot').append(mainpost);

$('#holder-inner-hot').show();

})

});

})

})
2 changes: 2 additions & 0 deletions resources/views/layout/display.blade.php
Expand Up @@ -7,5 +7,7 @@

<!-- Append feeds here -->
<div class="" id="holder-inner"></div>
<div class="" id="holder-inner-trending"></div>
<div class="" id="holder-inner-hot"></div>

</section>
8 changes: 4 additions & 4 deletions resources/views/layout/nav.blade.php
Expand Up @@ -73,16 +73,16 @@

<ul style="margin-right: 0px;" class="nav navbar-nav">

<li> <a href="http://signup.steemit.com" class="signup-a">Trending</a> </li>
<li> <a href="http://signup.steemit.com" class="signup-a">New</a> </li>
<li> <a href="http://signup.steemit.com" class="signup-a">Category</a> </li>
<li> <a href="#trending" class="signup-a" id="trending">Trending</a> </li>
<li> <a href="#new" class="signup-a" id="new">New</a> </li>
<li> <a href="#hot" class="signup-a" id="hot">Hot</a> </li>
<li> <a href="http://signup.steemit.com" class="signup-a">Unaswered</a> </li>

</ul>

<ul style="margin-right: 0px;" class="nav navbar-nav navbar-right">

<li> <a href="http://signup.steemit.com" class="signup-a">Marketplace</a> </li>
<li> <a href="/market" class="signup-a">Marketplace</a> </li>

@if (isset($_SESSION['username']))

Expand Down

0 comments on commit 573bfc2

Please sign in to comment.