diff --git a/src/lib/sync/areas.js b/src/lib/sync/areas.js index 4a3f16aa..5d8c365d 100644 --- a/src/lib/sync/areas.js +++ b/src/lib/sync/areas.js @@ -8,9 +8,30 @@ axiosRetry(axios, { retries: 3 }); const limit = 500; export const areasSync = async () => { - // get areas from local + // clear v1 table if present await localforage .getItem('areas') + .then(function (value) { + if (value) { + localforage + .removeItem('areas') + .then(function () { + console.log('Key is cleared!'); + }) + .catch(function (err) { + areaError.set('Could not clear areas locally, please try again or contact BTC Map.'); + console.log(err); + }); + } + }) + .catch(function (err) { + areaError.set('Could not check areas locally, please try again or contact BTC Map.'); + console.log(err); + }); + + // get areas from local + await localforage + .getItem('areas_v2') .then(async function (value) { // get areas from API if initial sync if (!value) { @@ -48,7 +69,7 @@ export const areasSync = async () => { // set response to local localforage - .setItem('areas', areasData) + .setItem('areas_v2', areasData) // eslint-disable-next-line no-unused-vars .then(function (value) { // set response to store @@ -123,7 +144,7 @@ export const areasSync = async () => { // set updated areas locally localforage - .setItem('areas', areasData) + .setItem('areas_v2', areasData) // eslint-disable-next-line no-unused-vars .then(function (value) { // set updated areas to store diff --git a/src/lib/sync/elements.js b/src/lib/sync/elements.js index b0471b9e..afef88d8 100644 --- a/src/lib/sync/elements.js +++ b/src/lib/sync/elements.js @@ -10,9 +10,33 @@ const limit = 5000; export const elementsSync = async () => { mapLoading.set('Checking local cache...'); - // get elements from local + + // clear v1 table if present await localforage .getItem('elements') + .then(function (value) { + if (value) { + localforage + .removeItem('elements') + .then(function () { + console.log('Key is cleared!'); + }) + .catch(function (err) { + elementError.set( + 'Could not clear elements locally, please try again or contact BTC Map.' + ); + console.log(err); + }); + } + }) + .catch(function (err) { + elementError.set('Could not check elements locally, please try again or contact BTC Map.'); + console.log(err); + }); + + // get elements from local + await localforage + .getItem('elements_v2') .then(async function (value) { // get elements from API if initial sync if (!value) { @@ -58,7 +82,7 @@ export const elementsSync = async () => { mapLoading.set('Storing data...'); // set response to local localforage - .setItem('elements', elementsData) + .setItem('elements_v2', elementsData) // eslint-disable-next-line no-unused-vars .then(function (value) { mapLoading.set('Initial sync complete!'); @@ -144,7 +168,7 @@ export const elementsSync = async () => { mapLoading.set('Storing data...'); localforage - .setItem('elements', elementsData) + .setItem('elements_v2', elementsData) // eslint-disable-next-line no-unused-vars .then(function (value) { mapLoading.set('Map loading complete!'); diff --git a/src/lib/sync/events.js b/src/lib/sync/events.js index 4130c563..6bbf0beb 100644 --- a/src/lib/sync/events.js +++ b/src/lib/sync/events.js @@ -8,9 +8,30 @@ axiosRetry(axios, { retries: 3 }); const limit = 50000; export const eventsSync = async () => { - // get events from local + // clear v1 table if present await localforage .getItem('events') + .then(function (value) { + if (value) { + localforage + .removeItem('events') + .then(function () { + console.log('Key is cleared!'); + }) + .catch(function (err) { + eventError.set('Could not clear events locally, please try again or contact BTC Map.'); + console.log(err); + }); + } + }) + .catch(function (err) { + eventError.set('Could not check events locally, please try again or contact BTC Map.'); + console.log(err); + }); + + // get events from local + await localforage + .getItem('events_v2') .then(async function (value) { // get events from API if initial sync if (!value) { @@ -48,7 +69,7 @@ export const eventsSync = async () => { // set response to local localforage - .setItem('events', eventsData) + .setItem('events_v2', eventsData) // eslint-disable-next-line no-unused-vars .then(function (value) { // set response to store @@ -127,7 +148,7 @@ export const eventsSync = async () => { // set updated events locally localforage - .setItem('events', eventsData) + .setItem('events_v2', eventsData) // eslint-disable-next-line no-unused-vars .then(function (value) { // set updated events to store diff --git a/src/lib/sync/reports.js b/src/lib/sync/reports.js index 0568a5e8..a58b432e 100644 --- a/src/lib/sync/reports.js +++ b/src/lib/sync/reports.js @@ -8,9 +8,32 @@ axiosRetry(axios, { retries: 3 }); const limit = 20000; export const reportsSync = async () => { - // get reports from local + // clear v1 table if present await localforage .getItem('reports') + .then(function (value) { + if (value) { + localforage + .removeItem('reports') + .then(function () { + console.log('Key is cleared!'); + }) + .catch(function (err) { + reportError.set( + 'Could not clear reports locally, please try again or contact BTC Map.' + ); + console.log(err); + }); + } + }) + .catch(function (err) { + reportError.set('Could not check reports locally, please try again or contact BTC Map.'); + console.log(err); + }); + + // get reports from local + await localforage + .getItem('reports_v2') .then(async function (value) { // get reports from API if initial sync if (!value) { @@ -50,7 +73,7 @@ export const reportsSync = async () => { // set response to local localforage - .setItem('reports', reportsData) + .setItem('reports_v2', reportsData) // eslint-disable-next-line no-unused-vars .then(function (value) { // set response to store @@ -129,7 +152,7 @@ export const reportsSync = async () => { // set updated reports locally localforage - .setItem('reports', reportsData) + .setItem('reports_v2', reportsData) // eslint-disable-next-line no-unused-vars .then(function (value) { // set updated reports to store diff --git a/src/lib/sync/users.js b/src/lib/sync/users.js index e78d2d6a..1ef6aa6f 100644 --- a/src/lib/sync/users.js +++ b/src/lib/sync/users.js @@ -29,9 +29,30 @@ export const usersSync = async () => { console.log(err); }); - // get users from local + // clear v2 table if present await localforage .getItem('users_v2') + .then(function (value) { + if (value) { + localforage + .removeItem('users_v2') + .then(function () { + console.log('Key is cleared!'); + }) + .catch(function (err) { + userError.set('Could not clear users locally, please try again or contact BTC Map.'); + console.log(err); + }); + } + }) + .catch(function (err) { + userError.set('Could not check users locally, please try again or contact BTC Map.'); + console.log(err); + }); + + // get users from local + await localforage + .getItem('users_v3') .then(async function (value) { // get users from API if initial sync if (!value) { @@ -69,7 +90,7 @@ export const usersSync = async () => { // set response to local localforage - .setItem('users_v2', usersData) + .setItem('users_v3', usersData) // eslint-disable-next-line no-unused-vars .then(function (value) { // set response to store @@ -144,7 +165,7 @@ export const usersSync = async () => { // set updated users locally localforage - .setItem('users_v2', usersData) + .setItem('users_v3', usersData) // eslint-disable-next-line no-unused-vars .then(function (value) { // set updated users to store