Merge pull request #3530 from FreeCodeCamp/map-share
add facebook sharing to map on completed challenges
This commit is contained in:
@ -1,3 +1,32 @@
|
|||||||
|
var mapShareKey = 'map-shares';
|
||||||
|
var lastCompleted = typeof lastCompleted !== 'undefined' ?
|
||||||
|
lastCompleted :
|
||||||
|
'';
|
||||||
|
|
||||||
|
function getMapShares() {
|
||||||
|
var alreadyShared = JSON.parse(localStorage.getItem(mapShareKey) || '[]');
|
||||||
|
if (!alreadyShared || !Array.isArray(alreadyShared)) {
|
||||||
|
localStorage.setItem(mapShareKey, JSON.stringify([]));
|
||||||
|
alreadyShared = [];
|
||||||
|
}
|
||||||
|
return alreadyShared;
|
||||||
|
}
|
||||||
|
|
||||||
|
function setMapShare(id) {
|
||||||
|
var alreadyShared = getMapShares();
|
||||||
|
var found = false;
|
||||||
|
alreadyShared.forEach(function(_id) {
|
||||||
|
if (_id === id) {
|
||||||
|
found = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (!found) {
|
||||||
|
alreadyShared.push(id);
|
||||||
|
}
|
||||||
|
localStorage.setItem(mapShareKey, JSON.stringify(alreadyShared));
|
||||||
|
return alreadyShared;
|
||||||
|
}
|
||||||
|
|
||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
|
|
||||||
var challengeName = typeof challengeName !== 'undefined' ?
|
var challengeName = typeof challengeName !== 'undefined' ?
|
||||||
@ -383,6 +412,40 @@ $(document).ready(function() {
|
|||||||
}
|
}
|
||||||
}, false);
|
}, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// map sharing
|
||||||
|
var alreadyShared = getMapShares();
|
||||||
|
|
||||||
|
if (lastCompleted && alreadyShared.indexOf(lastCompleted) === -1) {
|
||||||
|
$('div[id="' + lastCompleted + '"]')
|
||||||
|
.parent()
|
||||||
|
.parent()
|
||||||
|
.removeClass('hidden');
|
||||||
|
}
|
||||||
|
|
||||||
|
// on map view
|
||||||
|
$('.map-challenge-block-share').on('click', function(e) {
|
||||||
|
e.preventDefault();
|
||||||
|
var challengeBlockName = $(this).children().attr('id');
|
||||||
|
var challengeBlockEscapedName = challengeBlockName.replace(/\s/, '%20');
|
||||||
|
var username = typeof window.username !== 'undefined' ?
|
||||||
|
window.username :
|
||||||
|
'';
|
||||||
|
|
||||||
|
var link = 'https://www.facebook.com/dialog/feed?' +
|
||||||
|
'app_id=1644598365767721' +
|
||||||
|
'&display=page&' +
|
||||||
|
'caption=I%20just%20completed%20the%20' +
|
||||||
|
challengeBlockEscapedName +
|
||||||
|
'%20section%20on%20Free%20Code%20Camp%2E' +
|
||||||
|
'&link=http%3A%2F%2Ffreecodecamp%2Ecom%2F' +
|
||||||
|
username +
|
||||||
|
'&redirect_uri=http%3A%2F%2Ffreecodecamp%2Ecom%2Fmap';
|
||||||
|
|
||||||
|
setMapShare(challengeBlockName);
|
||||||
|
window.location.href = link;
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
function defCheck(a){
|
function defCheck(a){
|
||||||
|
@ -471,6 +471,7 @@ module.exports = function(app) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function challengeMap({ user = {} }, res, next) {
|
function challengeMap({ user = {} }, res, next) {
|
||||||
|
let lastCompleted;
|
||||||
const daysRunning = moment().diff(new Date('10/15/2014'), 'days');
|
const daysRunning = moment().diff(new Date('10/15/2014'), 'days');
|
||||||
|
|
||||||
// if user
|
// if user
|
||||||
@ -513,7 +514,13 @@ module.exports = function(app) {
|
|||||||
})
|
})
|
||||||
.filter(({ name }) => name !== 'Hikes')
|
.filter(({ name }) => name !== 'Hikes')
|
||||||
// turn stream of blocks into a stream of an array
|
// turn stream of blocks into a stream of an array
|
||||||
.toArray();
|
.toArray()
|
||||||
|
.doOnNext((blocks) => {
|
||||||
|
const lastCompletedBlock = _.findLast(blocks, (block) => {
|
||||||
|
return block.completed === 100;
|
||||||
|
});
|
||||||
|
lastCompleted = lastCompletedBlock.name;
|
||||||
|
});
|
||||||
|
|
||||||
Observable.combineLatest(
|
Observable.combineLatest(
|
||||||
camperCount$,
|
camperCount$,
|
||||||
@ -526,6 +533,7 @@ module.exports = function(app) {
|
|||||||
blocks,
|
blocks,
|
||||||
daysRunning,
|
daysRunning,
|
||||||
camperCount,
|
camperCount,
|
||||||
|
lastCompleted,
|
||||||
title: "A map of all Free Code Camp's Challenges"
|
title: "A map of all Free Code Camp's Challenges"
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
@ -131,7 +131,16 @@ block content
|
|||||||
span= challenge.title
|
span= challenge.title
|
||||||
span.sr-only= " Incomplete"
|
span.sr-only= " Incomplete"
|
||||||
|
|
||||||
//#announcementModal.modal(tabindex='-1')
|
if (challengeBlock.completed === 100)
|
||||||
|
.button-spacer
|
||||||
|
.row
|
||||||
|
.col-xs-12.col-sm-8.col-md-6.col-sm-offset-3.col-md-offset-2.hidden
|
||||||
|
a.btn.btn-lg.btn-block.signup-btn.map-challenge-block-share Section complete. Share your Portfolio with your friends.
|
||||||
|
.hidden(id="#{challengeBlock.name}")
|
||||||
|
script.
|
||||||
|
var username = !{JSON.stringify(user && user.username || '')};
|
||||||
|
var lastCompleted = !{JSON.stringify(lastCompleted || false)}
|
||||||
|
// #announcementModal.modal(tabindex='-1')
|
||||||
// .modal-dialog.animated.fadeInUp.fast-animation
|
// .modal-dialog.animated.fadeInUp.fast-animation
|
||||||
// .modal-content
|
// .modal-content
|
||||||
// .modal-header.challenge-list-header Add us to your LinkedIn profile
|
// .modal-header.challenge-list-header Add us to your LinkedIn profile
|
||||||
|
@ -94,10 +94,6 @@ block content
|
|||||||
.row
|
.row
|
||||||
if (user)
|
if (user)
|
||||||
#submit-challenge.animated.fadeIn.btn.btn-lg.btn-primary.btn-block Submit and go to my next challenge (ctrl + enter)
|
#submit-challenge.animated.fadeIn.btn.btn-lg.btn-primary.btn-block Submit and go to my next challenge (ctrl + enter)
|
||||||
if (user.progressTimestamps.length > 2)
|
|
||||||
a.btn.btn-lg.btn-block.btn-twitter(target="_blank", href="https://twitter.com/intent/tweet?text=I%20just%20#{verb}%20%40FreeCodeCamp%20#{name}&url=http%3A%2F%2Ffreecodecamp.com/challenges/#{dashedName}&hashtags=LearnToCode, JavaScript")
|
|
||||||
i.fa.fa-twitter  
|
|
||||||
= phrase
|
|
||||||
else
|
else
|
||||||
a.animated.fadeIn.btn.btn-lg.btn-primary.btn-block(href='/challenges/next-challenge?id=' + challengeId) Go to my next challenge
|
a.animated.fadeIn.btn.btn-lg.btn-primary.btn-block(href='/challenges/next-challenge?id=' + challengeId) Go to my next challenge
|
||||||
include ../partials/challenge-modals
|
include ../partials/challenge-modals
|
||||||
|
@ -69,12 +69,6 @@ block content
|
|||||||
a.btn.btn-lg.btn-primary.btn-block#next-courseware-button(name='_csrf', value=_csrf) I've completed this challenge (ctrl + enter)
|
a.btn.btn-lg.btn-primary.btn-block#next-courseware-button(name='_csrf', value=_csrf) I've completed this challenge (ctrl + enter)
|
||||||
script.
|
script.
|
||||||
$('#complete-courseware-editorless-dialog').bind('keypress', modalControlEnterHandler);
|
$('#complete-courseware-editorless-dialog').bind('keypress', modalControlEnterHandler);
|
||||||
|
|
||||||
if (user.progressTimestamps.length > 2)
|
|
||||||
.button-spacer
|
|
||||||
a.btn.btn-lg.btn-block.btn-twitter(href="https://twitter.com/intent/tweet?text=I%20just%20#{verb}%20%40FreeCodeCamp%20#{name}&url=http%3A%2F%2Ffreecodecamp.com/challenges/#{dashedName}&hashtags=LearnToCode, JavaScript" target="_blank")
|
|
||||||
i.fa.fa-twitter  
|
|
||||||
= phrase
|
|
||||||
else
|
else
|
||||||
a.animated.fadeIn.btn.btn-lg.btn-primary.btn-block(href='/challenges/next-challenge?id=' + challengeId) I've completed this challenge (ctrl + enter)
|
a.animated.fadeIn.btn.btn-lg.btn-primary.btn-block(href='/challenges/next-challenge?id=' + challengeId) I've completed this challenge (ctrl + enter)
|
||||||
script.
|
script.
|
||||||
|
Reference in New Issue
Block a user