Skip to content

Commit

Permalink
generating random temporary id
Browse files Browse the repository at this point in the history
relates to #163
  • Loading branch information
pbywater committed Aug 2, 2017
1 parent a686aa7 commit 50f93e2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
8 changes: 5 additions & 3 deletions src/client/d3/d3.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
const { initTagMenu, showDeleteButton, hoveringOnDelete, hideDeleteButton, initSubmitMemory, tagSorting, constructTagList, showHeading, storePendingActions, removeMemoryFromStoredData, removeMemoriesDeletedOffline, updateOfflineLikes, hoveringOnDeleteSafari, deletePendingMemories, addMemoryToStoredData } = require('../helpers/helpers.js');
const { animationDuration, width, height, jsonUrl, svg, fdGrp, nodeGrp, linkGrp } = require('./setup.js');
const { sortWithMax, binByTag, centralMaxNodesByTag, memoryNodesAndLinks } = require('../node_transformations');
const { sortWithMax, binByTag, centralMaxNodesByTag, memoryNodesAndLinks, getRandomInt } = require('../node_transformations');
const { appendPopUp, randomPopUp } = require('./modals.js');
const { newUserIntro } = require('./newUserIntro.js');

const url = location.hostname ? '/memories' : jsonUrl;

function onlineLogic() {
d3.json(url, (err, data) => {
console.log('data is ', data);
if (data.length > 0) {
const dataToSave = JSON.stringify(data);
localStorage.setItem('data', dataToSave);
Expand Down Expand Up @@ -235,8 +236,9 @@ function render(updatedData) {
const heading = splitData[0].split('=')[1];
const text = splitData[1].split('=')[1];
const tag = splitData[2].split('=')[1];
storePendingActions('textToAdd', { memories: [{ id: 100, heading, text, tag }] }, { id: 100, heading, text, tag });
const offlineData = addMemoryToStoredData(100, heading, text, tag);
const id = getRandomInt(10000, 999999);
storePendingActions('textToAdd', { memories: [{ id, heading, text, tag }] }, { id, heading, text, tag });
const offlineData = addMemoryToStoredData(id, heading, text, tag);
setTimeout(() => {
render(formatData(offlineData));
}, animationDuration);
Expand Down
4 changes: 2 additions & 2 deletions src/client/helpers/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,9 +262,10 @@ return offlineData;
}

function addMemoryToStoredData(id, heading, text, tag) {
// Unsure whether this is working in the formatData function correctly
const offlineData = JSON.parse(localStorage.getItem('data'));
console.log(offlineData);
const toAdd = {heading, id, likes: 0, media_type: "text_only", memory_text: text, tag};
const toAdd = {heading, id, likes: 0, media_type: "text_only", memory_text: text, tag, visits:0, memory_asset_url:''};
offlineData.push(toAdd);
console.log(offlineData);
const offlineDataAfterAdding = JSON.stringify(offlineData);
Expand Down Expand Up @@ -318,7 +319,6 @@ function updateOfflineLikes(cb) {
}

module.exports = {
getRandomInt,
initTagMenu,
initSubmitMemory,
showDeleteButton,
Expand Down

0 comments on commit 50f93e2

Please sign in to comment.