Add hashtags API parameter and localStorage

(closes #2834)
This commit is contained in:
Bryan Housel
2017-08-16 10:47:17 -04:00
parent 4cf357f61a
commit a42aa789e9
3 changed files with 46 additions and 29 deletions
+7 -1
View File
@@ -37,7 +37,9 @@ export function behaviorHash(context) {
var center = map.center(),
zoom = map.zoom(),
precision = Math.max(0, Math.ceil(Math.log(zoom) / Math.LN2)),
q = _.omit(utilStringQs(window.location.hash.substring(1)), ['comment', 'walkthrough']),
q = _.omit(utilStringQs(window.location.hash.substring(1)),
['comment', 'hashtags', 'walkthrough']
),
newParams = {};
delete q.id;
@@ -99,6 +101,10 @@ export function behaviorHash(context) {
context.storage('commentDate', Date.now());
}
if (q.hashtags) {
context.storage('hashtags', q.hashtags);
}
if (q.walkthrough === 'true') {
hash.startWalkthrough = true;
}
+10 -4
View File
@@ -34,12 +34,14 @@ export function uiCommit(context) {
var comment = context.storage('comment') || '',
commentDate = +context.storage('commentDate') || 0,
hashtags = context.storage('hashtags'),
currDate = Date.now(),
cutoff = 2 * 86400 * 1000; // 2 days
// expire the stored comment if it is too old - #3947
// expire stored comment and hashtags after cutoff datetime - #3947
if (commentDate > currDate || currDate - commentDate > cutoff) {
comment = '';
hashtags = undefined;
}
var tags;
@@ -49,6 +51,7 @@ export function uiCommit(context) {
comment: comment,
created_by: ('iD ' + context.version).substr(0, 255),
imagery_used: context.history().imageryUsed().join(';').substr(0, 255),
hashtags: hashtags,
host: detected.host.substr(0, 255),
locale: detected.locale.substr(0, 255)
};
@@ -311,9 +314,12 @@ export function uiCommit(context) {
});
if (!onInput) {
var hashtags = findHashtags(tags);
if (hashtags.length) {
tags.hashtags = hashtags.join(';').substr(0, 255);
var arr = findHashtags(tags);
if (arr.length) {
tags.hashtags = arr.join(';').substr(0, 255);
context.storage('hashtags', tags.hashtags);
} else {
context.storage('hashtags', null);
}
}