Last active
June 7, 2019 11:42
-
-
Save manuelgeek/1552cd39e9c36a03947f483be6893c34 to your computer and use it in GitHub Desktop.
my app.js
This file contains hidden or 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
/** | |
* First we will load all of this project's JavaScript dependencies which | |
* includes Vue and other libraries. It is a great starting point when | |
* building robust, powerful web applications using Vue and Laravel. | |
*/ | |
import {initialize} from "./helpers/general"; | |
require('./bootstrap'); | |
import Vue from 'vue'; | |
import Vuex from 'vuex'; | |
import StoreData from './store'; | |
import Toaster from 'v-toaster'; | |
import VueSweetalert2 from 'vue-sweetalert2'; | |
// You need a specific loader for CSS files like https://github.com/webpack/css-loader | |
import 'v-toaster/dist/v-toaster.css' | |
import VueIziToast from 'vue-izitoast'; | |
import 'izitoast/dist/css/iziToast.css'; | |
Vue.use(VueIziToast, { | |
position: 'topRight', | |
timeout: 5000, | |
closeOnEscape: true}); | |
import VueCroppie from 'vue-croppie'; | |
import 'croppie/croppie.css' // import the croppie css manually | |
Vue.use(VueCroppie); | |
// optional set default imeout, the default is 10000 (10 seconds). | |
Vue.use(VueSweetalert2); | |
Vue.use(Toaster, {timeout: 5000}); | |
import BootstrapVue from 'bootstrap-vue' | |
Vue.use(BootstrapVue); | |
import 'bootstrap-vue/dist/bootstrap-vue.css' | |
import 'bootstrap-vue/dist/bootstrap-vue.css' | |
import VueImg from 'v-img'; | |
const vueImgConfig = { | |
// Use `alt` attribute as gallery slide title | |
altAsTitle: false, | |
// Display 'download' button near 'close' that opens source image in new tab | |
sourceButton: false, | |
// Event listener to open gallery will be applied to <img> element | |
openOn: 'click', | |
// Show thumbnails for all groups with more than 1 image | |
thumbnails: false, | |
} | |
Vue.use(VueImg, vueImgConfig); | |
import VoerroTagsInput from '@voerro/vue-tagsinput'; | |
Vue.component('tags-input', VoerroTagsInput); | |
import vueNumeralFilterInstaller from 'vue-numeral-filter'; | |
Vue.use(vueNumeralFilterInstaller, { locale: 'en-gb' }); | |
Vue.use(Vuex); | |
Vue.config.productionTip = true; | |
Vue.config.devtools = true; | |
const store = new Vuex.Store(StoreData); | |
initialize(store); | |
/** | |
* The following block of code may be used to automatically register your | |
* Vue components. It will recursively scan this directory for the Vue | |
* components and automatically register them with their "basename". | |
* | |
* Eg. ./components/ExampleComponent.vue -> <example-component></example-component> | |
*/ | |
// const files = require.context('./', true, /\.vue$/i); | |
// files.keys().map(key => Vue.component(key.split('/').pop().split('.')[0], files(key).default)); | |
Vue.component('ViewAvatar', require('./components/account/ViewAvatar').default); | |
Vue.component('EditAvatarImage', require('./components/account/EditAvatarImage').default); | |
Vue.component('UpdateCoverPhoto', require('./components/account/UpdateCoverPhoto').default); | |
Vue.component('ViewCoverPhoto', require('./components/account/ViewCoverPhoto').default); | |
Vue.component('AllPosts', require('./components/posts/AllPosts').default); | |
Vue.component('Create', require('./components/posts/Create').default); | |
Vue.component('FavsLinks', require('./components/posts/FavsLinks').default); | |
Vue.component('Comments', require('./components/posts/Comments').default); | |
Vue.component('ViewImages', require('./components/posts/ViewImages').default); | |
Vue.component('ChannelPosts', require('./components/channels/ChannelPosts').default); | |
Vue.component('PayForm', require('./components/channels/premium/PayForm').default); | |
/** | |
* Next, we will create a fresh Vue application instance and attach it to | |
* the page. Then, you may begin adding components to this application | |
* or customize the JavaScript scaffolding to fit your unique needs. | |
*/ | |
const app = new Vue({ | |
el: '#app', | |
store, | |
created () { | |
this.checkAuth() | |
console.log(this.checkAuth()) | |
this.requestNotifications(); | |
this.postCreated(); | |
}, | |
methods : { | |
postCreated(){ | |
Echo.private('post') | |
.listen('PostCreated', (resp) => { | |
if (! ('Notification' in window)) { | |
alert('Web Notification is not supported'); | |
return; | |
} | |
Notification.requestPermission( permission => { | |
let notification = new Notification('New post from '+resp.user.name, { | |
body: resp.post.body.length > 200 ? resp.post.body.substring(0, 200) + '...' : resp.post.body, // content for the alert | |
icon: resp.user.avatar // optional image url | |
}); | |
// link to page on clicking the notification | |
notification.onclick = () => { | |
window.open(resp.url); | |
}; | |
}); | |
}); | |
}, | |
requestNotifications() | |
{ | |
Notification.requestPermission().then(function(result) { | |
if (result === 'denied') { | |
console.log('Permission wasn\'t granted. Allow a retry.'); | |
return; | |
} | |
if (result === 'default') { | |
console.log('The permission request was dismissed.'); | |
return; | |
} | |
// Do something with the granted permission. | |
}); | |
}, | |
checkAuth(){ | |
axios.get('/check/web/auth') | |
.then( response => { | |
return response.data.status; | |
}) | |
} | |
}, | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
i am trying to get the auth status from checkAuth and , if false, the postCreated() should run. and i also want to pass the status to the other Vue components. Any ideas?