From e09e25a31a91e0da53183b66403c7329b3296df4 Mon Sep 17 00:00:00 2001 From: winkidney Date: Sat, 7 Dec 2019 21:48:03 +0800 Subject: [PATCH] Feature: Add support for bookmarklet url --- pinry-spa/src/components/modals.js | 9 +++- .../src/components/pin_edit/PinCreateModal.vue | 11 ++++- pinry-spa/src/router/index.js | 6 +++ pinry-spa/src/views/PinCreate.vue | 52 +++++++++++++++++++++- 4 files changed, 74 insertions(+), 4 deletions(-) diff --git a/pinry-spa/src/components/modals.js b/pinry-spa/src/components/modals.js index e858e51..6451794 100644 --- a/pinry-spa/src/components/modals.js +++ b/pinry-spa/src/components/modals.js @@ -5,13 +5,20 @@ import BoardEdit from './BoardEdit.vue'; import Add2Board from './pin_edit/Add2Board.vue'; -function openPinEdit(vm, props = null) { +function openPinEdit(vm, props = null, onCreated = null) { vm.$buefy.modal.open( { parent: vm, component: PinCreateModal, props, hasModalCard: true, + events: { + pinCreated() { + if (onCreated !== null) { + onCreated(); + } + }, + }, }, ); } diff --git a/pinry-spa/src/components/pin_edit/PinCreateModal.vue b/pinry-spa/src/components/pin_edit/PinCreateModal.vue index 7fc8c2e..85c4d26 100644 --- a/pinry-spa/src/components/pin_edit/PinCreateModal.vue +++ b/pinry-spa/src/components/pin_edit/PinCreateModal.vue @@ -92,7 +92,7 @@ import bus from '../utils/bus'; import ModelForm from '../utils/ModelForm'; function isURLBlank(url) { - return url !== null && url !== ''; + return url !== null && url === ''; } const fields = ['url', 'referer', 'description', 'tags']; @@ -100,6 +100,10 @@ const fields = ['url', 'referer', 'description', 'tags']; export default { name: 'PinCreateModal', props: { + fromUrl: { + type: Object, + default: null, + }, username: { type: String, default: null, @@ -142,6 +146,11 @@ export default { this.pinModel.form.description.value = this.existedPin.description; this.pinModel.form.tags.value = this.existedPin.tags; } + if (this.fromUrl) { + this.pinModel.form.url.value = this.fromUrl.url; + this.pinModel.form.referer.value = this.fromUrl.referer; + this.pinModel.form.description.value = this.fromUrl.description; + } }, methods: { fetchBoardList() { diff --git a/pinry-spa/src/router/index.js b/pinry-spa/src/router/index.js index f4d8a1b..6495f4e 100644 --- a/pinry-spa/src/router/index.js +++ b/pinry-spa/src/router/index.js @@ -6,6 +6,7 @@ import Pins4User from '../views/Pins4User.vue'; import Pins4Board from '../views/Pins4Board.vue'; import Pins4Id from '../views/Pins4Id.vue'; import Boards4User from '../views/Boards4User.vue'; +import PinCreate from '../views/PinCreate.vue'; Vue.use(VueRouter); @@ -40,6 +41,11 @@ const routes = [ name: 'boards4user', component: Boards4User, }, + { + path: '/pin-creation/from-url', + name: 'pin-creation-from-url', + component: PinCreate, + }, ]; const router = new VueRouter({ diff --git a/pinry-spa/src/views/PinCreate.vue b/pinry-spa/src/views/PinCreate.vue index aec66ed..3ca1a1a 100644 --- a/pinry-spa/src/views/PinCreate.vue +++ b/pinry-spa/src/views/PinCreate.vue @@ -5,10 +5,58 @@