ZachYanez / SayHey

Here is a progressive web app I built to make it easier to communicate with people who might be 6ft away. Type in a message and see it displayed across the screen in a large font. Save presets to quickly access common messages
https://sayheyapp.link
1 stars 0 forks source link

keep presets list up to date with IndexDB values #5

Closed danielrobertson closed 3 years ago

danielrobertson commented 3 years ago

@ZachYanez Here is one approach on how to keep the Presets dropdown current with IndexDB, by keeping the list current in local state, updating that list with IndexDB values on the initial render with a useEffect, and then appending values one at a time as the user adds values.

The alternative on this which I coded but opted not show is a bit trickier, which is to write new presets to IndexDB and then run a "refresh" routine to overwrite local state presets with the values that are currently in IndexDB, which is prone to infinite loops/re-renders

One other random unsolicited feedback is to get eslint/prettier plugins going on this project to keep formatting consistent. Super easy in VSCode editor, which I assume you're using

Screen Recording 2021-02-02 at 10 55 39 AM

ZachYanez commented 3 years ago

@danielrobertson That is exactly it! Holy hot dang. Yesterday I got the add to work, which is what was initially tripping me up, and then today I was going to tackle pretty much what you did in useEffect.

ZachYanez commented 3 years ago

@danielrobertson I love what you did in 31-45, that's what I kinda had in my head, but SEEING it done helps me understand the flow really well. The concept of returning and then mapping over is huge and to see it done so elegantly is great.

ZachYanez commented 3 years ago

@danielrobertson https://www.npmjs.com/package/react-indexed-db

ZachYanez commented 3 years ago

@danielrobertson Getting a weird error after I tried to merge it. I thought I merged ok, but this is popping up. Maybe we could do a virtual thing later, or if you know what to I can fix it.

Screen Shot 2021-02-02 at 12 41 35 PM

danielrobertson commented 3 years ago

@danielrobertson Getting a weird error after I tried to merge it. I thought I merged ok, but this is popping up. Maybe we could do a virtual thing later, or if you know what to I can fix it.

Screen Shot 2021-02-02 at 12 41 35 PM

@ZachYanez Oops, this is my bad because locally I had a separate file in /src with an exported array of initial values called initialPresets but then when I realized I don't have github push permission for your repo, I use the GitHub web fork functionality and decided last minute to switch the separate file into simply the INITIAL_PRESETS array that's at the top of the file. Replace initialPresets with INITIAL_PRESETS, that's all it is

ZachYanez commented 3 years ago

Ok word. I wondered if that was the fix. Appreciate it 🙌🏽