camdendotlol / topstersorg

Book and music charts
https://topsters.org
GNU Affero General Public License v3.0
18 stars 9 forks source link

Refactor `currentlyActive` logic #33

Closed camdendotlol closed 7 months ago

camdendotlol commented 8 months ago

Currently, every chart has a currentlyActive boolean field and the viewer searches for the first chart where currentlyActive === true when deciding which one to display. There should only ever be one currently-active chart, so this is a pretty wonky system.

The redesign adds a new uuid field to uniquely identify each chart, which can be used to restructure how charts are handled in local storage, something like below where currentlyActive is a top-level field that contains a UUID and the charts array is turned into an object where the UUIDs are keys.

Before

charts: [
  {
    uuid: 'f0a27a44-a0b5-468f-bb22-fd713a6311c8',
    currentlyActive: false,
   data: {...}
  },
  {
    uuid: 'f676798d-1d23-415b-9354-894f5b0966fc',
    currentlyActive: true,
   data: {...}
  },
]

After

currentlyActive: 'f676798d-1d23-415b-9354-894f5b0966fc'
charts: {
  f676798d-1d23-415b-9354-894f5b0966fc: {...}.
  f0a27a44-a0b5-468f-bb22-fd713a6311c8: {...}
}

This would greatly simplify a lot of the code that deals with switching between charts, identifying or setting the currently active one, etc.

camdendotlol commented 8 months ago

Just finished implementing this on the redesign branch 🥳