mirror of
https://github.com/pinry/pinry.git
synced 2026-03-05 03:31:09 +01:00
Feature: Add global event bus to trigger pin-refresh
+ Any other good idea to do this?
This commit is contained in:
committed by
Isaac Bythewood
parent
0006aad6f7
commit
b3a065a4fb
@@ -70,6 +70,7 @@ import PinPreview from './PinPreview.vue';
|
||||
import loadingSpinner from './loadingSpinner.vue';
|
||||
import noMore from './noMore.vue';
|
||||
import scroll from './utils/scroll';
|
||||
import bus from './utils/bus';
|
||||
|
||||
function createImageItem(pin) {
|
||||
const image = {};
|
||||
@@ -92,6 +93,18 @@ function createImageItem(pin) {
|
||||
return image;
|
||||
}
|
||||
|
||||
function initialData() {
|
||||
return {
|
||||
blocks: [],
|
||||
blocksMap: {},
|
||||
status: {
|
||||
loading: false,
|
||||
hasNext: true,
|
||||
offset: 0,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export default {
|
||||
name: 'pins',
|
||||
components: {
|
||||
@@ -99,15 +112,7 @@ export default {
|
||||
noMore,
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
blocks: [],
|
||||
blocksMap: {},
|
||||
status: {
|
||||
loading: false,
|
||||
hasNext: true,
|
||||
offset: 0,
|
||||
},
|
||||
};
|
||||
return initialData();
|
||||
},
|
||||
props: {
|
||||
pinFilters: {
|
||||
@@ -173,6 +178,19 @@ export default {
|
||||
}
|
||||
return true;
|
||||
},
|
||||
initialize() {
|
||||
this.fetchMore(true);
|
||||
},
|
||||
reset() {
|
||||
const data = initialData();
|
||||
Object.entries(data).forEach(
|
||||
(kv) => {
|
||||
const [key, value] = kv;
|
||||
this[key] = value;
|
||||
},
|
||||
);
|
||||
this.initialize();
|
||||
},
|
||||
fetchMore(created) {
|
||||
if (!this.shouldFetchMore(created)) {
|
||||
return;
|
||||
@@ -208,8 +226,9 @@ export default {
|
||||
},
|
||||
},
|
||||
created() {
|
||||
bus.bus.$on(bus.events.refreshPin, this.reset);
|
||||
this.registerScrollEvent();
|
||||
this.fetchMore(true);
|
||||
this.initialize();
|
||||
},
|
||||
};
|
||||
</script>
|
||||
|
||||
@@ -75,6 +75,7 @@
|
||||
<script>
|
||||
import API from '../api';
|
||||
import FileUpload from './FileUpload.vue';
|
||||
import bus from '../utils/bus';
|
||||
|
||||
function isURLBlank(url) {
|
||||
return url !== null && url !== '';
|
||||
@@ -131,6 +132,7 @@ export default {
|
||||
}
|
||||
promise.then(
|
||||
(resp) => {
|
||||
bus.bus.$emit(bus.events.refreshPin);
|
||||
self.$emit('pinCreated', resp);
|
||||
self.$parent.close();
|
||||
},
|
||||
|
||||
10
pinry-spa/src/components/utils/bus.js
Normal file
10
pinry-spa/src/components/utils/bus.js
Normal file
@@ -0,0 +1,10 @@
|
||||
import Vue from 'vue';
|
||||
|
||||
const eventBus = new Vue();
|
||||
|
||||
export default {
|
||||
bus: eventBus,
|
||||
events: {
|
||||
refreshPin: 'refreshPin',
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user