Skip to content

Commit

Permalink
Merge pull request #222 from time9683/feature/settings-autosave-local…
Browse files Browse the repository at this point in the history
…storage

Add option to enable or disable autosave in localstorage
  • Loading branch information
midudev authored Nov 27, 2023
2 parents dc3f5f4 + a90def8 commit 8419704
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

1 comment on commit 8419704

@vercel
Copy link

@vercel vercel bot commented on 8419704 Nov 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.