Skip to content

Commit

Permalink
feat: very basic support for opening notebooks by url (resolve #9)
Browse files Browse the repository at this point in the history
  • Loading branch information
muety committed Dec 1, 2020
1 parent ed2622e commit 968bfd1
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 26 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mininote",
"version": "0.6.3",
"version": "0.7.0",
"description": "A simple Mardown note-taking editor",
"main": "index.js",
"scripts": {
Expand Down
4 changes: 1 addition & 3 deletions webapp/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mininote-frontend",
"version": "0.6.3",
"version": "0.7.0",
"private": true,
"description": "A simple Mardown note-taking editor.",
"author": "Ferdinand Mütsch <[email protected]>",
Expand All @@ -18,13 +18,11 @@
"marked": "^1.2.2",
"tailwindcss": "^1.9.6",
"vue": "^3.0.0",
"vue-router": "^4.0.0-0",
"vuex": "^4.0.0-0"
},
"devDependencies": {
"@vue/cli-plugin-babel": "~4.5.0",
"@vue/cli-plugin-eslint": "~4.5.0",
"@vue/cli-plugin-router": "~4.5.0",
"@vue/cli-plugin-unit-jest": "~4.5.0",
"@vue/cli-plugin-vuex": "~4.5.0",
"@vue/cli-service": "~4.5.0",
Expand Down
23 changes: 21 additions & 2 deletions webapp/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,14 @@
import NotebooksPicker from './components/NotebooksPicker.vue'
import ControlBar from './components/ControlBar.vue'
const notebookHashRe = /^#\/notebook\/([a-z0-9_\-]+)$/g
function parseNotebookUrl() {
// attempt to parse a requested notebook name from the url's hash
const match = [...location.hash.matchAll(notebookHashRe)]
return match && match.length && match[0].length == 2 ? match[0][1] : null
}
export default {
components: {
NotesEditor,
Expand All @@ -94,16 +102,20 @@
return false
},
},
mounted() {
async mounted() {
window.addEventListener('beforeunload', this.didIntentToLeave)
this.listNotebooks()
await this.listNotebooks()
this.tryOpenFromUrl()
},
methods: {
...mapActions([actions.LIST_NOTEBOOKS]),
...mapMutations([
mutations.SELECT_NOTE,
mutations.SET_LOAD_NOTEBOOK,
mutations.ADD_CHANGE,
mutations.RESET,
]),
onNoteSelected: function (noteId) {
this.selectNote(noteId)
Expand Down Expand Up @@ -142,6 +154,13 @@
event.returnValue = ''
}
},
tryOpenFromUrl: function () {
const initialNotebookId = parseNotebookUrl()
const initialNotebook = this.notebooks.some(n => n.id === initialNotebookId)
if (initialNotebook) {
this.onNotebookSelected(initialNotebookId)
}
}
},
}
</script>
Expand Down
1 change: 1 addition & 0 deletions webapp/src/components/ControlBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@
.then(() => {
vm.state.opening = false
vm.state.loaded = true
this.selectFirst()
this.inputs.newName = this.inputs.name
Expand Down
2 changes: 0 additions & 2 deletions webapp/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,5 @@ import './assets/css/style.css'

import App from './App.vue'
import { useStore } from './store'
// https:/muety/mininote/issues/9
// import { useRouter } from './router'

createApp(App).use(useStore()).mount('#app')
12 changes: 0 additions & 12 deletions webapp/src/router/index.js

This file was deleted.

6 changes: 6 additions & 0 deletions webapp/src/store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ function selectFirst(state) {
state.selectedNoteId = id
}

function updateUrl(state) {
location.hash = state.notebook.id ? `#/notebook/${state.notebook.id}` : ''
}

/// STORE ///
const store = new Vuex.Store({
state: JSON.parse(JSON.stringify(emptyState)),
Expand All @@ -100,6 +104,7 @@ const store = new Vuex.Store({
setNotebook(state, { id, password }) {
state.notebook.id = id
state.notebook.password = password
updateUrl(state)
},
setNotes(state, notes) {
state.notebook.notes = notes
Expand Down Expand Up @@ -190,6 +195,7 @@ const store = new Vuex.Store({
for (let prop in emptyState) {
state[prop] = JSON.parse(JSON.stringify(emptyState[prop]))
}
updateUrl(state)
},
},
actions: {
Expand Down
7 changes: 1 addition & 6 deletions webapp/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1662,7 +1662,7 @@
webpack "^4.0.0"
yorkie "^2.0.0"

"@vue/cli-plugin-router@^4.5.8", "@vue/cli-plugin-router@~4.5.0":
"@vue/cli-plugin-router@^4.5.8":
version "4.5.8"
resolved "https://registry.yarnpkg.com/@vue/cli-plugin-router/-/cli-plugin-router-4.5.8.tgz#db70a69df4edc90690765f8c25749a68b20dd850"
integrity sha512-tJwVLdX4jj0Ia/1hsBejRbo4gs0hb2z1z5ert+4Ve5RNdpOKUG69OaPQgXPqvuYSQh9MW7bqG0iJmYtVD+KBNw==
Expand Down Expand Up @@ -10899,11 +10899,6 @@ vue-loader@^15.9.2:
vue-hot-reload-api "^2.3.0"
vue-style-loader "^4.1.0"

vue-router@^4.0.0-0:
version "4.0.0-rc.1"
resolved "https://registry.yarnpkg.com/vue-router/-/vue-router-4.0.0-rc.1.tgz#42f41315849163a1243886c9aa6d7c14f24fd003"
integrity sha512-N3SSOIiRFo1/D6EkHGuahUSuyDvFhKizN5zVXkALX7wv0hYYndV49KwzRF5lKsAIt+OlDl7y+sNmwNewb7a4iw==

vue-style-loader@^4.1.0, vue-style-loader@^4.1.2:
version "4.1.2"
resolved "https://registry.yarnpkg.com/vue-style-loader/-/vue-style-loader-4.1.2.tgz#dedf349806f25ceb4e64f3ad7c0a44fba735fcf8"
Expand Down

0 comments on commit 968bfd1

Please sign in to comment.