Hide sharing if not logged in, or in an accessible place

The grand future will have option to login, and so on...
This commit is contained in:
David Kelly 2016-08-10 17:09:43 -07:00
parent 4273056c86
commit 47dea0ea2b
2 changed files with 27 additions and 6 deletions

View file

@ -28,16 +28,29 @@
paths.push(data); paths.push(data);
} }
function handleShareButtons(canShare) {
if (!canShare) {
// hide the share/do not share buttons
document.getElementById("sharing").innerHTML = "<p>You can share if you are logged in and in a public place";
}
}
window.onload = function () { window.onload = function () {
// Something like the following will allow testing in a browser. // Something like the following will allow testing in a browser.
//addImage({localPath: 'c:/Users/howar/OneDrive/Pictures/hifi-snap-by--on-2016-07-27_12-58-43.jpg'}); //addImage({localPath: 'c:/Users/howar/OneDrive/Pictures/hifi-snap-by--on-2016-07-27_12-58-43.jpg'});
openEventBridge(function () { openEventBridge(function () {
// Set up a handler for receiving the data, and tell the .js we are ready to receive it. // Set up a handler for receiving the data, and tell the .js we are ready to receive it.
EventBridge.scriptEventReceived.connect(function (message) { EventBridge.scriptEventReceived.connect(function (message) {
// last element of list contains a bool for whether or not we can share stuff
var canShare = message.pop().canShare;
print("canShare:"+canShare+", message:" + message.toString())
handleShareButtons(canShare);
// rest are image paths which we add
message.forEach(addImage); message.forEach(addImage);
}); });
EventBridge.emitWebEvent('ready'); EventBridge.emitWebEvent('ready');
}); });
}; };
// beware of bug: Cannot send objects at top level. (Nested in arrays is fine.) // beware of bug: Cannot send objects at top level. (Nested in arrays is fine.)
shareSelected = function() { shareSelected = function() {
@ -64,11 +77,13 @@
<div class="sub-section-header"> <div class="sub-section-header">
<label>Would you like to share?</label> <label>Would you like to share?</label>
</div> </div>
<div class="sub-section-header"> <div id="sharing">
<input type="button" id="share" value="SHARE IN FEED" onclick="shareSelected()"/> <div class="sub-section-header">
</div> <input type="button" id="share" value="SHARE IN FEED" onclick="shareSelected()"/>
<div class="sub-section-header"> </div>
<input type="button" class="red" id="close" value="DON'T SHARE" onclick="doNotShare()"/> <div class="sub-section-header">
<input type="button" class="red" id="close" value="DON'T SHARE" onclick="doNotShare()"/>
</div>
</div> </div>
</div> </div>
<div id="images" class="image-column"/> <div id="images" class="image-column"/>

View file

@ -77,6 +77,10 @@ function onClicked() {
}, SNAPSHOT_DELAY); }, SNAPSHOT_DELAY);
} }
function canShare() {
return Account.isLoggedIn() && Boolean(Window.location.placename);
}
function resetButtons(path, notify) { function resetButtons(path, notify) {
// show overlays if they were on // show overlays if they were on
if (resetOverlays) { if (resetOverlays) {
@ -90,7 +94,9 @@ function resetButtons(path, notify) {
button.writeProperty("defaultState", 1); button.writeProperty("defaultState", 1);
button.writeProperty("hoverState", 3); button.writeProperty("hoverState", 3);
Window.snapshotTaken.disconnect(resetButtons); Window.snapshotTaken.disconnect(resetButtons);
confirmShare([{localPath: path}]);
// last element in data array tells dialog whether we can share or not
confirmShare([ { localPath: path }, { canShare: canShare() } ]);
} }
button.clicked.connect(onClicked); button.clicked.connect(onClicked);