diff options
author | Nick Coutsos <[email protected]> | 2021-11-07 11:49:33 -0500 |
---|---|---|
committer | Nick Coutsos <[email protected]> | 2021-11-07 11:49:33 -0500 |
commit | 56405d85e564f2c397dbc3424d6c40520234739d (patch) | |
tree | a5d323e7da493b6710a2fede56bb2904ac8e2e0f | |
parent | a6aeb000619896dc57b66cd6fc8c8b24439066c3 (diff) | |
download | keymap-editor-56405d85e564f2c397dbc3424d6c40520234739d.tar.gz keymap-editor-56405d85e564f2c397dbc3424d6c40520234739d.zip |
Organize github-related components
-rw-r--r-- | application/components/app.vue | 2 | ||||
-rw-r--r-- | application/components/github/api.js (renamed from application/github.js) | 2 | ||||
-rw-r--r-- | application/components/github/invalid-repo.vue (renamed from application/components/messages/invalid-repo.vue) | 0 | ||||
-rw-r--r-- | application/components/github/picker.vue (renamed from application/components/github-picker.vue) | 25 | ||||
-rw-r--r-- | application/components/github/storage.js | 18 | ||||
-rw-r--r-- | application/components/initialize.vue | 2 | ||||
-rw-r--r-- | application/components/keyboard-picker.vue | 2 | ||||
-rw-r--r-- | application/components/messages/too-many-repos.vue | 37 |
8 files changed, 35 insertions, 53 deletions
diff --git a/application/components/app.vue b/application/components/app.vue index e53345c..766f901 100644 --- a/application/components/app.vue +++ b/application/components/app.vue @@ -6,7 +6,7 @@ import KeyboardPicker from './keyboard-picker.vue' import Spinner from './spinner.vue' import * as config from '../config' -import * as github from '../github' +import * as github from './github/api' export default { components: { diff --git a/application/github.js b/application/components/github/api.js index 0d0782c..b2e29e9 100644 --- a/application/github.js +++ b/application/components/github/api.js @@ -1,4 +1,4 @@ -import * as config from './config' +import * as config from '../../config' let token export let installation diff --git a/application/components/messages/invalid-repo.vue b/application/components/github/invalid-repo.vue index eee706f..eee706f 100644 --- a/application/components/messages/invalid-repo.vue +++ b/application/components/github/invalid-repo.vue diff --git a/application/components/github-picker.vue b/application/components/github/picker.vue index e52fcce..73520a1 100644 --- a/application/components/github-picker.vue +++ b/application/components/github/picker.vue @@ -35,10 +35,11 @@ import find from 'lodash/find' import map from 'lodash/map' -import * as github from '../github' -import InvalidRepo from './messages/invalid-repo.vue' -import Selector from './selector.vue' -import Spinner from './spinner.vue' +import * as github from './api' +import * as storage from './storage' +import InvalidRepo from './invalid-repo.vue' +import Selector from '../selector.vue' +import Spinner from '../spinner.vue' export default { name: 'GithubPicker', @@ -59,7 +60,7 @@ export default { return } - const selectedRepository = JSON.parse(localStorage.getItem('selectedGithubRepository')) + const selectedRepository = storage.getPersistedRepository() if (github.repositories.length === 1) { this.repo = github.repositories[0].full_name @@ -70,15 +71,15 @@ export default { } }, watch: { - repo(current, previous) { - if (previous !== current) { - localStorage.setItem('selectedGithubRepository', JSON.stringify(current)) + repo(value) { + storage.setPersistedRepository(value) + if (value) { this.loadBranches() } }, - branch(current, previous) { - if (current && previous !== current) { - localStorage.setItem('selectedGithubBranch', JSON.stringify(current)) + branch(value) { + storage.setPersistedBranch(value) + if (value) { this.loadKeyboard() } } @@ -106,7 +107,7 @@ export default { const available = map(branches, 'name') const defaultBranch = repository.default_branch const currentBranch = this.branch - const previousBranch = JSON.parse(localStorage.getItem('selectedGithubBranch')) + const previousBranch = storage.getPersistedBranch() const onlyBranch = branches.length === 1 ? branches[0].name : null for (let branch of [onlyBranch, currentBranch, previousBranch, defaultBranch]) { diff --git a/application/components/github/storage.js b/application/components/github/storage.js new file mode 100644 index 0000000..87603a0 --- /dev/null +++ b/application/components/github/storage.js @@ -0,0 +1,18 @@ +const REPOSITORY = 'selectedGithubRepository' +const BRANCH = 'selectedGithubBranch' + +export function getPersistedRepository() { + return JSON.parse(localStorage.getItem(REPOSITORY)) +} + +export function setPersistedRepository(repository) { + localStorage.setItem(REPOSITORY, JSON.stringify(repository)) +} + +export function getPersistedBranch() { + return JSON.parse(localStorage.getItem(BRANCH)) +} + +export function setPersistedBranch(branch) { + localStorage.setItem(BRANCH, JSON.stringify(branch)) +} diff --git a/application/components/initialize.vue b/application/components/initialize.vue index c0146a4..0d5fc1f 100644 --- a/application/components/initialize.vue +++ b/application/components/initialize.vue @@ -1,7 +1,7 @@ <script> import keyBy from 'lodash/keyBy' -import * as github from '../github' +import * as github from './github/api' import { healthcheck, loadBehaviours } from '../api' import { loadKeycodes } from '../keycodes' diff --git a/application/components/keyboard-picker.vue b/application/components/keyboard-picker.vue index 12008c2..c3b6383 100644 --- a/application/components/keyboard-picker.vue +++ b/application/components/keyboard-picker.vue @@ -21,7 +21,7 @@ import * as config from '../config' import { loadLayout } from '../layout.js' import { loadKeymap } from '../keymap.js' -import GithubPicker from './github-picker.vue' +import GithubPicker from './github/picker.vue' import Selector from './selector.vue' export default { diff --git a/application/components/messages/too-many-repos.vue b/application/components/messages/too-many-repos.vue deleted file mode 100644 index 086e471..0000000 --- a/application/components/messages/too-many-repos.vue +++ /dev/null @@ -1,37 +0,0 @@ -<template> - <modal> - <div class="dialog"> - <h2>Hold up a second!</h2> - <p>The Keymap Editor app has been installed for more than one GitHub repository.</p> - <p> - I'm still working on things, including the ability to pick a specific - repo, but in the meantime you should go back to your <a :href="getInstallationUrl()">app configuration</a> - and select a single repository containing your keyboard's zmk-config. - </p> - </div> - </modal> -</template> - -<script> -import Modal from '../modal.vue' -import * as github from '../../github' - -export default { - name: 'TooManyRepos', - components: { Modal }, - methods: { - getInstallationUrl() { - return `https://github.com/settings/installations/${github.installation.id}` - } - } -} -</script> - -<style scoped> -.dialog { - background-color: white; - padding: 40px; - margin: 40px; - max-width: 500px; -} -</style>
\ No newline at end of file |