Skip to content

Commit

Permalink
Improve saving only last 500 map titles
Browse files Browse the repository at this point in the history
  • Loading branch information
micrology committed Nov 28, 2024
1 parent bb36971 commit c3c8919
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion js/prsm.js
Original file line number Diff line number Diff line change
Expand Up @@ -2783,14 +2783,20 @@ export function setMapTitle(title) {
}
/**
* Add this title to the local record of maps used
* The list is stored as an object so that it is easy to add [room, title] pairs
* and easy to modify the title of an existing room
* @param {String} title
*/

const TITLELISTLEN = 500
function titleDropDown(title) {
let recentMaps = localStorage.getItem('recents')
if (recentMaps) recentMaps = JSON.parse(recentMaps)
else recentMaps = {}
if (title !== 'Untitled map') {
recentMaps[room] = title
// save only the most recent entries
recentMaps = Object.fromEntries(Object.entries(recentMaps).slice(-TITLELISTLEN))
localStorage.setItem('recents', JSON.stringify(recentMaps))
}
// if there is more than 1, append a down arrow after the map title as a cue to there being a list
Expand All @@ -2809,7 +2815,7 @@ function createTitleDropDown() {
// list is with New Map and then the most recent at the top
if (recentMaps) {
makeTitleDropDownEntry('*New map*', '*new*', false)
let props = Object.keys(recentMaps).reverse().slice(0, 500)
let props = Object.keys(recentMaps).reverse()
props.forEach((prop) => {
makeTitleDropDownEntry(recentMaps[prop], prop)
})
Expand Down

0 comments on commit c3c8919

Please sign in to comment.