Skip to content

Commit

Permalink
add setting for auto-save-local-storage
Browse files Browse the repository at this point in the history
  • Loading branch information
time9683 committed Nov 6, 2023
1 parent dc3f5f4 commit a90def8
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
12 changes: 12 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,18 @@
</label>
</div>
</div>
<div class="settings-item">
<strong>
<span class="settings-type">Features › autosave localstorage
<div>
<label class="checkbox">
<input name="saveLocalstorage" type="checkbox" />
<span
>Automatically save URL to local storage for fast content loading</span
>
</label>
</div>
</div>
</div>
</form>
</div>
Expand Down
1 change: 1 addition & 0 deletions src/constants/initial-settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export const DEFAULT_INITIAL_SETTINGS = {
wordWrap: 'on',
zipFileName: 'codi.link',
zipInSingleFile: false,
saveLocalstorage: true,
layout: {
gutters: DEFAULT_LAYOUT,
style: DEFAULT_GRID_TEMPLATE,
Expand Down
8 changes: 5 additions & 3 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { BUTTON_ACTIONS } from './constants/button-actions.js'
import './components/layout-preview/layout-preview.js'
import './components/codi-editor/codi-editor.js'

const { layout: currentLayout, sidebar, theme } = getState()
const { layout: currentLayout, sidebar, theme, saveLocalstorage } = getState()

setGridLayout(currentLayout)
setSidebar(sidebar)
Expand All @@ -33,7 +33,7 @@ const editorElements = $$('codi-editor')

let { pathname } = window.location

if (pathname === '/') {
if (pathname === '/' && saveLocalstorage === true) {
const hashedCode = window.localStorage.getItem('hashedCode') ?? ''
window.history.replaceState(null, null, `/${hashedCode}`)
pathname = window.location.pathname
Expand Down Expand Up @@ -106,7 +106,9 @@ function update ({ notReload } = {}) {
updateCss()

debouncedUpdateHash(values)
saveCode(values)
if (saveLocalstorage) {
saveCode(values)
}
updateButtonAvailabilityIfContent(values)
}

Expand Down

0 comments on commit a90def8

Please sign in to comment.