Skip to content

Commit

Permalink
Mentions tab
Browse files Browse the repository at this point in the history
  • Loading branch information
armandocat committed Oct 10, 2017
1 parent 2801691 commit fff357f
Show file tree
Hide file tree
Showing 5 changed files with 168 additions and 15 deletions.
1 change: 1 addition & 0 deletions chrome.ext.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ var jsToLoad = [
jsToLoad.push('src/profile_banner.js');
jsToLoad.push('src/base_tab.js');
jsToLoad.push('src/votes_tab.js');
jsToLoad.push('src/mentions_tab.js');
jsToLoad.push('src/vote_weight_slider.js');
jsToLoad.push('src/post_votes_list.js');
// jsToLoad.push('src/favorite_tags.js');
Expand Down
1 change: 1 addition & 0 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
"src/profile_banner.js",
"src/base_tab.js",
"src/votes_tab.js",
"src/mentions_tab.js",
"src/vote_weight_slider.js",
"src/post_votes_list.js",
"src/favorite_tags.js",
Expand Down
20 changes: 20 additions & 0 deletions src/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -1064,3 +1064,23 @@ table tbody tr.Trans.smi-transaction-filtered-in:nth-of-type(2n) {
color: #fff;
}


.UserProfile__tab_content_MentionsTab {
padding-bottom: 60px;
}
.UserProfile__tab_content_MentionsTab .MentionsTab {
padding-bottom: 20px;
}
.UserProfile__tab_content_MentionsTab .MentionsTabLoadMore button {
background-color: transparent;
border-radius: 6px;
border: 1px solid rgb(220, 220, 220);
display: inline-block;
cursor: pointer;
color: rgb(119, 119, 119);
font-size: 17px;
padding: 10px 24px;
text-decoration: none;
}


118 changes: 118 additions & 0 deletions src/mentions_tab.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@

(function(){

var addOrRemoveAfterSettingsChange = function() {
if(mentionsTabEnabled() === 'disabled'){
window.SteemMoreInfo.Tabs.disableTab('mentions');
}else{
window.SteemMoreInfo.Tabs.enableTab('mentions');
}
};

window.SteemMoreInfo.Utils.addSettings({
title: 'Mentions Tab',
settings: [{
title: '',
key: 'MentionsTab',
defaultValue: 'enabled',
options: [{
title: 'Disabled',
value: 'disabled'
}, {
title: 'Enabled',
value: 'enabled'
}],
description: 'Adds a tab where you can see the posts and comments where the user was mentioned',
onChange: addOrRemoveAfterSettingsChange
}]
});

var mentionsTabEnabled = function() {
var value = window.SteemMoreInfo.Utils.getSettingsValue('MentionsTab');
return value;
};



var createMentionsTab = function(mentionsTab) {
mentionsTab.html('<div class="row">\
<div class="UserProfile__tab_content UserProfile__tab_content_smi UserProfile__tab_content_MentionsTab column">\
<div class="MentionsTab" style="display: none;">\
<div id="posts_list" class="PostsList">\
<ul class="PostsList__summaries hfeed" itemscope="" itemtype="http://schema.org/blogPosts">\
</ul>\
</div>\
</div>\
<center class="MentionsTabLoading">\
<div class="LoadingIndicator circle">\
<div></div>\
</div>\
</center>\
<center class="MentionsTabLoadMore" style="display: none;">\
<button>\
Load more... \
</button>\
</center>\
</div>\
</div>');

mentionsTab.find('.MentionsTabLoadMore button').on('click', function(){
var loadMore = $(this).parent();
loadMore.hide();
mentionsTab.find('.MentionsTabLoading').show();
var from = parseInt(loadMore.data('from'), 10);
getPosts(mentionsTab, window.SteemMoreInfo.Utils.getPageAccountName(), from);
});

getPosts(mentionsTab, window.SteemMoreInfo.Utils.getPageAccountName());
};



var getPosts = function(mentionsTab, name, fromOrNull) {
fromOrNull = fromOrNull || 0;
window.SMI_AJAX({
url: 'https://webapi.steemdata.com/Comments?where={"$text":{"$search":"\\"@' + name + '\\""}}&sort=-created&page=' + (fromOrNull+1),
type: 'GET',
error: function(err){
console.log(err);
//TODO: error
},
success: function(data) {
var posts = data._items;
var postsList = mentionsTab.find('.PostsList__summaries');
if(postsList.length){
posts.forEach(function(post) {
var el = window.SteemMoreInfo.Utils.createPostSummary(post);
postsList.append(el);
});

mentionsTab.find('.MentionsTabLoading').hide();
mentionsTab.find('.MentionsTab').show();
if(data._links.next){
var from = fromOrNull + 1;
var loadMore = mentionsTab.find('.MentionsTabLoadMore');
loadMore.data('from', from);
loadMore.show();
}

}
}
});

};





window.SteemMoreInfo.Tabs.createTab({
id: 'mentions',
title: 'Mentions',
enabled: (mentionsTabEnabled() !== 'disabled'),
createTab: createMentionsTab
});



})();
43 changes: 28 additions & 15 deletions src/utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -256,16 +256,19 @@


var createPostSummary = function(post, name) {
var title = post.title;
var author = post.author;
var permlink = post.permlink;
var category = post.category;
var descr = window.SteemMoreInfo.Sanitize.postBodyShort(post.body);
var permlink = post.permlink;
var url = `/@${author}/${permlink}`;
if (category){
url = `/${category}${url}`;
var title = post.title;
var url = `@${author}/${permlink}`;
if(post.parent_author){ //comment
title = title || ('RE: ' + post.root_title);
url = `@${post.parent_author}/${post.parent_permlink}#` + url;
}

url = (category ? `/${category}/` : '/') + url;

var imgUrl;
try{
var json_metadata = JSON.parse(post.json_metadata);
Expand All @@ -275,7 +278,11 @@
}catch(err){
}


var date = moment(post.created + 'Z');
if(!date.isValid()){
date = moment(post.created);
}
var dateString = date.format('DD/MM/YYYY hh:mm A');
var dateString2 = date.fromNow();

Expand All @@ -288,9 +295,12 @@

var last_payout = post.last_payout;
var cashout_time, payoutDateString, payoutDateString2;
if(last_payout === '1970-01-01T00:00:00'){
var cashout_time = post.cashout_time;
cashout_time = moment(cashout_time + 'Z');
if(last_payout === '1970-01-01T00:00:00' || last_payout === 'Thu, 01 Jan 1970 00:00:00 GMT'){
var cashout_time = moment(post.cashout_time + 'Z');
if(!cashout_time.isValid()){
cashout_time = moment(post.cashout_time);
}

payoutDateString = cashout_time.format('DD/MM/YYYY hh:mm A');
payoutDateString2 = cashout_time.fromNow();

Expand All @@ -305,8 +315,10 @@
dollars = '' + dollars.toFixed(2);
}
}else{
dollarsAuthor = parseFloat(post.total_payout_value.replace(' SBD', ''));
dollarsCurators = parseFloat(post.curator_payout_value.replace(' SBD', ''));
var total_payout_value = typeof post.total_payout_value === 'object' ? post.total_payout_value.amount : parseFloat(post.total_payout_value.replace(' SBD', ''));
var curator_payout_value = typeof post.curator_payout_value === 'object' ? post.curator_payout_value.amount : parseFloat(post.curator_payout_value.replace(' SBD', ''));
dollarsAuthor = total_payout_value;
dollarsCurators = curator_payout_value;
dollars = dollarsAuthor + dollarsCurators;
dollars = '' + dollars.toFixed(2);
dollarsCurators = '' + dollarsCurators.toFixed(2);
Expand All @@ -317,7 +329,7 @@
var dollarsInteger = dsplit[0];
var dollarsDecimal = dsplit[1];

var isRepost = name !== author;
var isRepost = name && name !== author;

var vcard = '<span class="vcard">\
<a href="' + url + '">\
Expand All @@ -338,7 +350,7 @@
</span>';

var el = $('<li>\
<article class="PostSummary hentry with-image " itemscope="" itemtype="http://schema.org/blogPost">' +
<article class="PostSummary hentry' + (imgUrl ? ' with-image' : '') + '" itemscope="" itemtype="http://schema.org/blogPost">' +
(isRepost ? '<div class="PostSummary__reblogged_by">\
<span class="Icon reblog" style="display: inline-block; width: 1.12rem; height: 1.12rem;">\
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 512 512" style="enable-background:new 0 0 512 512;" xml:space="preserve"><path d="M448,192l-128,96v-64H128v128h248c4.4,0,8,3.6,8,8v48c0,4.4-3.6,8-8,8H72c-4.4,0-8-3.6-8-8V168c0-4.4,3.6-8,8-8h248V96 L448,192z"></path></svg>\
Expand All @@ -352,9 +364,9 @@
</div>\
<div class="PostSummary__time_author_category_small show-for-small-only">\
' + vcard + '\
</div>\
<span class="PostSummary__image" style="' + (imgUrl ? 'background-image: url(\'https://steemitimages.com/256x512/' + encodeURI(imgUrl) + '\');' : '') + '"></span>\
<div class="PostSummary__content">\
</div>' +
(imgUrl ? '<span class="PostSummary__image" style="background-image: url(\'https://steemitimages.com/256x512/' + encodeURI(imgUrl) + '\');"></span>' : '') +
'<div class="PostSummary__content">\
<div class="PostSummary__header show-for-medium">\
<h3 class="entry-title">\
<a href="' + url + '">' + title + '</a>\
Expand Down Expand Up @@ -481,6 +493,7 @@
};



var navigate = function(url) {
//hack to use react to navigate
var a = $('.smi-hack-navigate-a');
Expand Down

0 comments on commit fff357f

Please sign in to comment.