Skip to content

Commit

Permalink
Merge pull request #818 from leoendless/hotfix/history
Browse files Browse the repository at this point in the history
fix: Cache history by user
  • Loading branch information
ks-ci-bot authored Jul 20, 2020
2 parents 315800f + 87a7469 commit dd5d415
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/components/Modals/History/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ import styles from './index.scss'

export default class History extends Component {
get histories() {
return safeParseJSON(localStorage.getItem('history-cache'), [])
const caches = safeParseJSON(localStorage.getItem('history-cache'), {})
return caches[globals.user.username] || []
}

renderHistory() {
Expand Down
7 changes: 5 additions & 2 deletions src/core/global.js
Original file line number Diff line number Diff line change
Expand Up @@ -399,11 +399,14 @@ export default class GlobalValue {
}

cacheHistory(url, obj) {
let histories = safeParseJSON(localStorage.getItem('history-cache'), [])
let histories = safeParseJSON(localStorage.getItem('history-cache'), {})
histories = histories[globals.user.username] || []
histories = histories.filter(item => item.url !== url)
localStorage.setItem(
'history-cache',
JSON.stringify([{ url, ...obj }, ...histories].slice(0, 8))
JSON.stringify({
[globals.user.username]: [{ url, ...obj }, ...histories].slice(0, 8),
})
)
}
}

0 comments on commit dd5d415

Please sign in to comment.