-
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from voraciousdev/support-user-settings
Add settings menu
- Loading branch information
Showing
9 changed files
with
152 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<template> | ||
<div class="container context mt-3 mt-md-5"> | ||
<div> | ||
<h3 class="card-title">Settings</h3> | ||
<h6 class="card-subtitle text-muted font-weight-normal mb-3">Make yourself comfortable</h6> | ||
<section> | ||
<h4 class="font-weight-normal">Editor</h4> | ||
<hr> | ||
<div class="form-group"> | ||
<label for="config-tab-size">Tab length</label> | ||
<input v-model="tabSize" type="number" min="2" id="config-tab-size" class="form-control"> | ||
<small class="text-muted">Number of spaces per tab (minimum: 2)</small> | ||
</div> | ||
</section> | ||
</div> | ||
</div> | ||
</template> | ||
|
||
<script> | ||
import { | ||
SET_EDITOR_TAB_SIZE, | ||
} from '@/store/modules/settings'; | ||
export default { | ||
name: 'TheSettings', | ||
data() { | ||
return { | ||
// nothing yet | ||
}; | ||
}, | ||
computed: { | ||
tabSize: { | ||
get() { | ||
return this.$store.state.settings.editor.tabSize; | ||
}, | ||
set(value) { | ||
this.$store.dispatch(SET_EDITOR_TAB_SIZE, parseInt(value) || 2); | ||
}, | ||
}, | ||
}, | ||
}; | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
export const LOAD_SETTINGS = 'LOAD_SETTINGS'; | ||
export const SET_EDITOR_TAB_SIZE = 'SET_EDITOR_TAB_SIZE'; | ||
|
||
export default { | ||
state: () => ({ | ||
editor: { | ||
tabSize: 2, | ||
}, | ||
}), | ||
getters: { | ||
// nothing yet | ||
}, | ||
mutations: { | ||
[LOAD_SETTINGS] (state, settings) { | ||
// shallow merge | ||
Object.assign(state, settings); | ||
}, | ||
[SET_EDITOR_TAB_SIZE] (state, tabSize) { | ||
state.editor.tabSize = tabSize; | ||
}, | ||
}, | ||
actions: { | ||
async [LOAD_SETTINGS] (context, settings) { | ||
context.commit(LOAD_SETTINGS, settings); | ||
}, | ||
async [SET_EDITOR_TAB_SIZE] (context, tabSize) { | ||
context.commit(SET_EDITOR_TAB_SIZE, tabSize); | ||
}, | ||
}, | ||
}; |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import localforage from 'localforage'; | ||
|
||
import { | ||
LOAD_SETTINGS, | ||
SET_EDITOR_TAB_SIZE, | ||
} from '@/store/modules/settings'; | ||
|
||
const CACHE_KEY = 'main'; | ||
const cache = localforage.createInstance({ | ||
name: 'settings', | ||
}); | ||
|
||
export default (store) => { | ||
cache.getItem(CACHE_KEY).then((settings) => { | ||
if (settings) { | ||
store.dispatch(LOAD_SETTINGS, settings); | ||
} | ||
}); | ||
|
||
store.subscribe(({ type, _payload }, state) => { | ||
switch (type) { | ||
case SET_EDITOR_TAB_SIZE: | ||
cache.setItem(CACHE_KEY, state.settings); | ||
|
||
break; | ||
default: | ||
break; | ||
} | ||
}); | ||
}; |