refactor to utils + bug-fixes
This commit is contained in:
25
src/utils/LocalStorage.js
Normal file
25
src/utils/LocalStorage.js
Normal file
@@ -0,0 +1,25 @@
|
||||
export const SaveLastVisitedToLocalStorage = (data) => {
|
||||
let a = JSON.parse(localStorage.getItem('recent-visited')) || [];
|
||||
|
||||
if (a.length === 0) {
|
||||
a.push(data);
|
||||
} else if (a.length === 9) {
|
||||
if (a.find(p => p.steamid64 === data.steamid64)) {
|
||||
a.shift()
|
||||
a.splice(a.findIndex(i => i.steamid64 === data.steamid64), 1)
|
||||
a.push(data)
|
||||
} else if (!a.find(p => p.steamid64 === data.steamid64)) {
|
||||
a.shift()
|
||||
a.push(data)
|
||||
}
|
||||
} else if (a.length > 0 && a.length < 9) {
|
||||
if (a.find(p => p.steamid64 === data.steamid64)) {
|
||||
a.splice(a.findIndex(i => i.steamid64 === data.steamid64), 1)
|
||||
a.push(data)
|
||||
} else if (!a.find(p => p.steamid64 === data.steamid64)) {
|
||||
a.push(data)
|
||||
}
|
||||
}
|
||||
|
||||
localStorage.setItem('recent-visited', JSON.stringify(a));
|
||||
}
|
Reference in New Issue
Block a user