Skip to content

Commit

Permalink
Update page state handler
Browse files Browse the repository at this point in the history
  • Loading branch information
hopsoft committed May 17, 2024
1 parent eff4d85 commit 5c24a5a
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 18 deletions.
2 changes: 1 addition & 1 deletion app/assets/builds/@turbo-boost/commands.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions app/assets/builds/@turbo-boost/commands.js.map

Large diffs are not rendered by default.

14 changes: 6 additions & 8 deletions app/javascript/state/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,26 @@ import storage from './storage'
import { dispatch, stateEvents } from '../events'

const key = 'TurboBoost::State'
const stub = { page: {}, signed: null, unsigned: {} }
const stub = { pages: {}, signed: null, unsigned: {} }

let signed = null // signed state <string>
let unsigned = {} // unsigned state (optimistic) <object>

const restore = () => {
const saved = { ...stub, ...storage.find(key) }
const path = window.location.pathname
saved.page[path] = saved.page[path] || {}
page.restoreState(saved.page[path])
saved.pages[location.pathname] = saved.pages[location.pathname] || {}
page.restoreState(saved.pages[location.pathname])
}

const save = () => {
const saved = { ...stub, ...storage.find(key) }
const fresh = {
signed: signed || saved.signed,
unsigned: { ...saved.unsigned, ...unsigned },
page: { ...saved.page }
pages: { ...saved.pages }
}

const path = window.location.pathname
fresh.page[path] = { ...fresh.page[path], ...page.buildState() }
fresh.pages[location.pathname] = { ...fresh.pages[location.pathname], ...page.buildState() }
storage.save(key, fresh)
}

Expand All @@ -43,7 +41,7 @@ addEventListener('DOMContentLoaded', restore)
addEventListener('turbo:morph', restore)
addEventListener('turbo:render', restore)
addEventListener('turbo:before-fetch-request', save)
window.addEventListener('beforeunload', save)
addEventListener('beforeunload', save)

export default {
initialize,
Expand Down
9 changes: 4 additions & 5 deletions bin/docker/run/local
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,10 @@ fi
# Dependencies
# ============================================================================================================
npm install
rm /mnt/external/.playwright
if [ ! -f "/mnt/external/.playwright" ]; then
yes | npx playwright@latest install chromium --with-deps
touch /mnt/external/.playwright
fi
# if [ ! -f "/mnt/external/.playwright" ]; then
yes | npx playwright@latest install chromium --with-deps
# touch /mnt/external/.playwright
# fi
bundle install


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export default class extends Controller {

get defaultMode() {
let mode = 'light'
if (window.matchMedia('(prefers-color-scheme: dark)').matches) mode = 'dark'
if (matchMedia('(prefers-color-scheme: dark)').matches) mode = 'dark'
return mode
}
}

0 comments on commit 5c24a5a

Please sign in to comment.