Skip to content

Commit

Permalink
add func for comparing followers
Browse files Browse the repository at this point in the history
  • Loading branch information
Sambillingham committed Jan 27, 2018
1 parent 496cec0 commit b3053cd
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 24 deletions.
9 changes: 9 additions & 0 deletions css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -150,3 +150,12 @@ footer a:hover {
max-width: 20%;
}
}

.mixitup-control-active {
border-color: #007aff !important;
border-width: 2px;
}

.follower-compare .user-extra-stat{
display: none;
}
2 changes: 1 addition & 1 deletion follower-compare.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<link rel="stylesheet" href="css/main.css">
</head>

<body>
<body class="follower-compare">
<header class="jumbotron">
<div class="container">
<h1>Follower Compare</h1>
Expand Down
Binary file added img/default-user.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<link rel="stylesheet" href="css/main.css">
</head>

<body>
<body class="user-compare">
<header class="jumbotron">
<div class="container">
<h1 >Welcome To Steem Compare</h1>
Expand Down
24 changes: 20 additions & 4 deletions js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,29 @@ $(document).ready(() => {
},
animation: {
queue : true,
duration: 200,
queueLimit: 50
duration: 0,
queueLimit: 500
}
});
})

//setups
if ($('body').hasClass('user-compare')){
steemActions.getGlobalProps(STEEM_SERVER)
.then(steemActions.checkForUsersAndSearch())
}

steemActions.getGlobalProps(STEEM_SERVER)
.then(steemActions.checkForUsersAndSearch())
if ($('body').hasClass('follower-compare')){
steem.api.getFollowers('sambillingham', '', 'blog', 1000, function(err, result) {
// let followers = result.reduce( (a,b) => a + ', ' + b.follower )
let followers = result.map( (user) => user.follower )

console.log(followers)
steemActions.getGlobalProps(STEEM_SERVER)
.then( () => {
steemActions.addUsers(followers, true)
})

});

}
60 changes: 42 additions & 18 deletions js/modules/steemActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ export function checkForUsersAndSearch(){
}
}

export function addUsers(users){
export function addUsers(users, sortType){
var sort = ($('.mixitup-control-active').length) ? $('.mixitup-control-active').data('btn-sort') : false
getAccounts(users)
.then(data => proccessData(data) )
.then(data => displayAccounts(data, sort))
}

export function displayAccounts(newAccounts, sortValue ){

console.log(newAccounts)
let allAccounts = displayedAccounts.concat(newAccounts);
let allAccountsNoDup = util.removeDuplicates(allAccounts, 'name');
displayedAccounts = allAccountsNoDup
Expand All @@ -56,7 +56,7 @@ export function displayAccounts(newAccounts, sortValue ){
data-followers="${user.followerCount}"
data-accountage="${user.accountAgeMilliseconds}" >
<a href="https://steemit.com/@${user.name}" class="user-link"><img src="${user.image}" class="rounded-circle" height="80px" width="80px"></a>
<a href="https://steemit.com/@${user.name}" class="user-link"><img src="${user.image}" onerror="this.src='img/default-user.jpg'" class="rounded-circle" height="80px" width="80px"></a>
<li><a href="https://steemit.com/@${user.name}" class="user-value user-name user-link">${user.name}</a> <span class="badge badge-secondary">${user.rep}</span></li>
<li>EFFECTIVE SP: <span class="user-value">${ (user.effectiveSp).toLocaleString() }</span></li>
<li>STEEMPOWER: <span class="user-value">${user.sp} <br><span class="steam-calc">(+ ${user.delegatedSpIn} - ${user.delegatedSpOut})</span></span></li>
Expand All @@ -76,9 +76,13 @@ export function displayAccounts(newAccounts, sortValue ){
<li>Age: <span class="user-value">${ (user.accountAge) }</span></li>
<li class="user-extra-stat">Average Replies: <span class="user-value ">${ (user.averageReplies) }</span></li>
<li class="user-extra-stat">Average Votes: <span class="user-value ">${ (user.averageVotes) }</span></li>
<li class="user-extra-stat">Average Word Count: <span class="user-value ">${ (user.wordCount) }</span></li>
<li><span class="user-value">💵 $${(user.usdValue).toLocaleString()}</span></li>
<button type="button" class="btn btn-secondary btn-sm remove-user"> X Remove</button>
<button type="button" class="btn btn-secondary btn-sm remove-user user-extra-stat"> X Remove</button>
</div>`;

mixer.append(template);
Expand All @@ -93,6 +97,9 @@ export function displayAccounts(newAccounts, sortValue ){
mixer.sort(reSort)
mixer.forceRefresh();
} else {
mixer.sort('reputation:desc')
mixer.forceRefresh();

let accountsNamesForUrl = displayedAccounts.map( user => user.name )
util.setQueryUrl(accountsNamesForUrl)
}
Expand Down Expand Up @@ -121,8 +128,7 @@ export function proccessData(accounts){
let processAllData = new Promise((resolve, reject) => {

accounts.forEach( user => {
// store meta Data
let jsonData = user.json_metadata ? JSON.parse(user.json_metadata).profile : {}

// steem power calc
let vestingShares = user.vesting_shares;
let delegatedVestingShares = user.delegated_vesting_shares;
Expand All @@ -136,9 +142,25 @@ export function proccessData(accounts){
let votePower = user.voting_power += (10000 * lastVoteTime / 432000);
votePower = Math.min(votePower / 100, 100).toFixed(2);

let profileImage = 'img/default-user.jpg';

if (user.json_metadata == '' ||
user === undefined ||
user.json_metadata == 'undefined' ||
user.json_metadata === undefined ) {
user.json_metadata = { profile_image : ''}
} else {
user.json_metadata = user.json_metadata ? JSON.parse(user.json_metadata).profile : {};
}

if (user.json_metadata === undefined){
user.json_metadata = { profile_image : ''}
}
profileImage = user.json_metadata.profile_image ? 'https://steemitimages.com/2048x512/' + user.json_metadata.profile_image : '';

accountsData.push({
name: user.name,
image: jsonData.profile_image ? 'https://steemitimages.com/2048x512/' + jsonData.profile_image : '',
image: profileImage,
rep: steem.formatter.reputation(user.reputation),
effectiveSp: parseInt(steemPower + delegatedSteemPower - -outgoingSteemPower),
sp: parseInt(steemPower).toLocaleString(),
Expand Down Expand Up @@ -167,26 +189,28 @@ export function proccessData(accounts){
}
})


let usdValues = accounts.map( user => steem.formatter.estimateAccountValue(user) )

Promise.all(usdValues)
.then(data => {
for (let i = 0; i < data.length; i++) {
accountsData[i].usdValue = parseInt(data[i])
}
resolve(accountsData);
})

let extraStats = accounts.map( user => getStats(user.name))

Promise.all(extraStats)
.then(data => {
for (let i = 0; i < data.length; i++) {
accountsData[i].averageVotes = data[i].averageVotes
accountsData[i].averageReplies = data[i].averageReplies
accountsData[i].wordCount = data[i].wordCount
}
resolve(accountsData);
})
// let extraStats = accounts.map( user => getStats(user.name))
//
// Promise.all(extraStats)
// .then(data => {
// for (let i = 0; i < data.length; i++) {
// accountsData[i].averageVotes = data[i].averageVotes
// accountsData[i].averageReplies = data[i].averageReplies
// accountsData[i].wordCount = data[i].wordCount
// }
// resolve(accountsData);
// })

});

Expand Down

0 comments on commit b3053cd

Please sign in to comment.