Skip to content

Commit

Permalink
update local table versions
Browse files Browse the repository at this point in the history
  • Loading branch information
secondl1ght committed Nov 29, 2023
1 parent b51bf31 commit 2d77cec
Show file tree
Hide file tree
Showing 5 changed files with 125 additions and 15 deletions.
27 changes: 24 additions & 3 deletions src/lib/sync/areas.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
30 changes: 27 additions & 3 deletions src/lib/sync/elements.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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!');
Expand Down Expand Up @@ -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!');
Expand Down
27 changes: 24 additions & 3 deletions src/lib/sync/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
29 changes: 26 additions & 3 deletions src/lib/sync/reports.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
27 changes: 24 additions & 3 deletions src/lib/sync/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 2d77cec

Please sign in to comment.