checking for db error also bringing in article tweaks due to lazy usage of -a in git commit
This commit is contained in:
parent
b730ba14ed
commit
7c64767b52
2 changed files with 13 additions and 2 deletions
|
@ -21,13 +21,15 @@ So I thought it'd be interesting to explore these tradeoffs and throw my own hat
|
|||
|
||||
## The Obvious Way
|
||||
|
||||
[demo]()
|
||||
[demo](/static/demos/light-dark-demo-1)
|
||||
|
||||
The obvious way to attempt a toggle between light and dark mode is
|
||||
|
||||
## A Suboptimal Solution
|
||||
|
||||
A trick from from [](https://www.joshwcomeau.com/react/dark-mode/)
|
||||
|
||||
[demo]()
|
||||
[demo](/static/demos/light-dark-demo-2)
|
||||
|
||||
|
||||
## An Ideal Stateless Toggle
|
||||
|
|
|
@ -22,6 +22,15 @@ self.addEventListener("fetch", event =>{
|
|||
async function handle_redirect(req){
|
||||
const go_back_to = req.headers.get('Referer') || '/';;
|
||||
const db_req = self.indexedDB.open("light-dark-store");
|
||||
|
||||
db_req.onerror = (event) => {
|
||||
console.error("Database error:", event);
|
||||
resolve(new Response("Database error", {
|
||||
status: 302,
|
||||
headers: { 'Location': go_back_to }
|
||||
}));
|
||||
};
|
||||
|
||||
const up_promise = new Promise((res)=>{
|
||||
db_req.onupgradeneeded = (event) => {
|
||||
const db = event.target.result;
|
||||
|
|
Loading…
Reference in a new issue