Skip to content

Commit

Permalink
prep for new frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
Ratismal committed Jun 29, 2018
1 parent 90480d9 commit 60e4bda
Show file tree
Hide file tree
Showing 25 changed files with 2,481 additions and 23 deletions.
6 changes: 4 additions & 2 deletions .eslintrc.json
Expand Up @@ -6,6 +6,9 @@
"jest": false,
"jquery": false
},
"extends": [
"plugin:vue/essential"
],
"parserOptions": {
"ecmaVersion": 8,
"sourceType": "module",
Expand All @@ -30,8 +33,7 @@
"superInFunctions": true,
"templateStrings": true,
"unicodeCodePointEscapes": true,
"globalReturn": true,
"experimentalObjectRestSpread": true
"globalReturn": true
}
},
"plugins": [],
Expand Down
107 changes: 107 additions & 0 deletions .nuxt/App.js
@@ -0,0 +1,107 @@
import Vue from 'vue'
import NuxtLoading from './components/nuxt-loading.vue'

import '../src/frontend/assets/css/main.css'


let layouts = {

"_default": () => import('../src/frontend/layouts/default.vue' /* webpackChunkName: "layouts/default" */).then(m => m.default || m)

}

let resolvedLayouts = {}

export default {
head: {"title":"blargbot","meta":[{"charset":"utf-8"},{"name":"viewport","content":"width=device-width, initial-scale=1"},{"hid":"description","name":"description","content":"A multipurpose discord bot, designed to be customized."}],"link":[{"rel":"icon","type":"image\u002Fx-icon","href":"\u002Ffavicon.ico"}],"script":[{"src":"https:\u002F\u002Fcdnjs.cloudflare.com\u002Fajax\u002Flibs\u002Fmoment.js\u002F2.22.2\u002Fmoment.min.js","body":true}],"style":[]},
render(h, props) {
const loadingEl = h('nuxt-loading', { ref: 'loading' })
const layoutEl = h(this.layout || 'nuxt')
const templateEl = h('div', {
domProps: {
id: '__layout'
},
key: this.layoutName
}, [ layoutEl ])

const transitionEl = h('transition', {
props: {
name: 'layout',
mode: 'out-in'
}
}, [ templateEl ])

return h('div',{
domProps: {
id: '__nuxt'
}
}, [
loadingEl,
transitionEl
])
},
data: () => ({
layout: null,
layoutName: ''
}),
beforeCreate () {
Vue.util.defineReactive(this, 'nuxt', this.$options.nuxt)
},
created () {
// Add this.$nuxt in child instances
Vue.prototype.$nuxt = this
// add to window so we can listen when ready
if (typeof window !== 'undefined') {
window.$nuxt = this
}
// Add $nuxt.error()
this.error = this.nuxt.error
},

mounted () {
this.$loading = this.$refs.loading
},
watch: {
'nuxt.err': 'errorChanged'
},

methods: {

errorChanged () {
if (this.nuxt.err && this.$loading) {
if (this.$loading.fail) this.$loading.fail()
if (this.$loading.finish) this.$loading.finish()
}
},

setLayout (layout) {
if (!layout || !resolvedLayouts['_' + layout]) layout = 'default'
this.layoutName = layout
let _layout = '_' + layout
this.layout = resolvedLayouts[_layout]
return this.layout
},
loadLayout (layout) {
if (!layout || !(layouts['_' + layout] || resolvedLayouts['_' + layout])) layout = 'default'
let _layout = '_' + layout
if (resolvedLayouts[_layout]) {
return Promise.resolve(resolvedLayouts[_layout])
}
return layouts[_layout]()
.then((Component) => {
resolvedLayouts[_layout] = Component
delete layouts[_layout]
return resolvedLayouts[_layout]
})
.catch((e) => {
if (this.$nuxt) {
return this.$nuxt.error({ statusCode: 500, message: e.message })
}
})
}
},
components: {
NuxtLoading
}
}

157 changes: 157 additions & 0 deletions .nuxt/axios.js
@@ -0,0 +1,157 @@
import Axios from 'axios'


// Axios.prototype cannot be modified
const axiosExtra = {
setHeader (name, value, scopes = 'common') {
for (let scope of Array.isArray(scopes) ? scopes : [ scopes ]) {
if (!value) {
delete this.defaults.headers[scope][name];
return
}
this.defaults.headers[scope][name] = value
}
},
setToken (token, type, scopes = 'common') {
const value = !token ? null : (type ? type + ' ' : '') + token
this.setHeader('Authorization', value, scopes)
},
onRequest(fn) {
this.interceptors.request.use(config => fn(config) || config)
},
onResponse(fn) {
this.interceptors.response.use(response => fn(response) || response)
},
onRequestError(fn) {
this.interceptors.request.use(undefined, error => fn(error) || Promise.reject(error))
},
onResponseError(fn) {
this.interceptors.response.use(undefined, error => fn(error) || Promise.reject(error))
},
onError(fn) {
this.onRequestError(fn)
this.onResponseError(fn)
}
}

// Request helpers ($get, $post, ...)
for (let method of ['request', 'delete', 'get', 'head', 'options', 'post', 'put', 'patch']) {
axiosExtra['$' + method] = function () { return this[method].apply(this, arguments).then(res => res && res.data) }
}

const extendAxiosInstance = axios => {
for (let key in axiosExtra) {
axios[key] = axiosExtra[key].bind(axios)
}
}






const setupProgress = (axios, ctx) => {
if (process.server) {
return
}

// A noop loading inteterface for when $nuxt is not yet ready
const noopLoading = {
finish: () => { },
start: () => { },
fail: () => { },
set: () => { }
}

const $loading = () => (window.$nuxt && window.$nuxt.$loading && window.$nuxt.$loading.set) ? window.$nuxt.$loading : noopLoading

let currentRequests = 0

axios.onRequest(config => {
if (config && config.progress === false) {
return
}

currentRequests++
})

axios.onResponse(response => {
if (response && response.config && response.config.progress === false) {
return
}

currentRequests--
if (currentRequests <= 0) {
currentRequests = 0
$loading().finish()
}
})

axios.onError(error => {
if (error && error.config && error.config.progress === false) {
return
}

currentRequests--
$loading().fail()
$loading().finish()
})

const onProgress = e => {
if (!currentRequests) {
return
}
const progress = ((e.loaded * 100) / (e.total * currentRequests))
$loading().set(Math.min(100, progress))
}

axios.defaults.onUploadProgress = onProgress
axios.defaults.onDownloadProgress = onProgress
}

export default (ctx, inject) => {
const axiosOptions = {
// baseURL
baseURL : process.browser
? '/api'
: (process.env._AXIOS_BASE_URL_ || 'http://localhost:8102/api'),

// Create fresh objects for all default header scopes
// Axios creates only one which is shared across SSR requests!
// https://github.com/mzabriskie/axios/blob/master/lib/defaults.js
headers: {
common : {
'Accept': 'application/json, text/plain, */*'
},
delete: {},
get: {},
head: {},
post: {},
put: {},
patch: {}
}
}


// Proxy SSR request headers headers
axiosOptions.headers.common = (ctx.req && ctx.req.headers) ? Object.assign({}, ctx.req.headers) : {}
delete axiosOptions.headers.common['accept']
delete axiosOptions.headers.common['host']


// Create new axios instance
const axios = Axios.create(axiosOptions)

// Extend axios proto
extendAxiosInstance(axios)

// Setup interceptors


setupProgress(axios, ctx)


// Inject axios to the context as $axios
ctx.$axios = axios
inject('axios', axios)
}

0 comments on commit 60e4bda

Please sign in to comment.