Store location last seen date to check for New label

Stores the last location's page seeing date in localStorage to hide the Location's new label in list, on top of the date limit
This commit is contained in:
2022-09-14 11:32:58 +02:00
parent 683edc05fc
commit f38a8fcdc7
4 changed files with 43 additions and 10 deletions

View File

@@ -2,4 +2,23 @@ import { writable, type Writable } from 'svelte/store'
export const pageLoading: Writable<boolean> = writable(false)
export const previousPage: Writable<string> = writable('')
export const smoothScroll: Writable<any> = writable(null)
export const smoothScroll: Writable<any> = writable(null)
/**
* New locations tracking
*/
export const seenLocations: Writable<string> = writable('{}')
// Define local storage from store
if (typeof localStorage !== 'undefined') {
const seen = localStorage.getItem('seenLocations')
if (seen) {
const parsedValue = JSON.parse(seen)
seenLocations.set(JSON.stringify(parsedValue))
}
seenLocations.subscribe(value => {
const parsedValue = JSON.parse(value)
localStorage.setItem('seenLocations', JSON.stringify(parsedValue))
})
}

View File

@@ -18,9 +18,10 @@ export const cartId: Writable<string> = writable(null)
// Write to localStorage when changing cartId
if (typeof localStorage !== 'undefined') {
if (localStorage.getItem('cartId')) {
// console.log('existant', localStorage.getItem('cartId'))
cartId.set(localStorage.getItem('cartId'))
const cartId = localStorage.getItem('cartId')
if (cartId) {
cartId.set(cartId)
// console.log('existing cart:', cartId)
}
cartId.subscribe(value => localStorage.setItem('cartId', value))
}