vikunja-frontend/src/main.ts

140 lines
3.2 KiB
TypeScript
Raw Normal View History

import {createApp, configureCompat} from 'vue'
configureCompat({
COMPONENT_V_MODEL: false,
COMPONENT_ASYNC: false,
RENDER_FUNCTION: false,
WATCH_ARRAY: false, // TODO: check this again; this might lead to some problemes
TRANSITION_GROUP_ROOT: false,
})
2018-08-28 22:50:22 +02:00
import App from './App.vue'
import router from './router'
2018-08-28 22:50:22 +02:00
import {error, success} from './message'
declare global {
interface Window {
API_URL: string;
SENTRY_ENABLED: boolean;
SENTRY_DSN: string;
}
}
import {formatDate, formatDateShort, formatDateLong, formatDateSince} from '@/helpers/time/formatDate'
// @ts-ignore
import {VERSION} from './version.json'
2021-04-22 14:26:48 +02:00
// Notifications
import Notifications from '@kyvg/vue3-notification'
// PWA
import './registerServiceWorker'
// Vuex
import {store} from './store'
// i18n
2021-08-20 15:38:16 +02:00
import {i18n} from './i18n'
console.info(`Vikunja frontend version ${VERSION}`)
// Check if we have an api url in local storage and use it if that's the case
const apiUrlFromStorage = localStorage.getItem('API_URL')
if (apiUrlFromStorage !== null) {
window.API_URL = apiUrlFromStorage
}
// Make sure the api url does not contain a / at the end
if (window.API_URL.substr(window.API_URL.length - 1, window.API_URL.length) === '/') {
window.API_URL = window.API_URL.substr(0, window.API_URL.length - 1)
}
const app = createApp(App)
2018-08-28 22:50:22 +02:00
app.use(Notifications)
2018-09-08 21:43:16 +02:00
// directives
import focus from '@/directives/focus'
import { VTooltip } from 'v-tooltip'
import 'v-tooltip/dist/v-tooltip.css'
import shortcut from '@/directives/shortcut'
import cypress from '@/directives/cypress'
app.directive('focus', focus)
app.directive('tooltip', VTooltip)
app.directive('shortcut', shortcut)
app.directive('cy', cypress)
2021-04-22 14:26:48 +02:00
// global components
import FontAwesomeIcon from './icons'
import Button from '@/components/input/button.vue'
import Modal from '@/components/modal/modal.vue'
import Card from '@/components/misc/card.vue'
app.component('icon', FontAwesomeIcon)
app.component('x-button', Button)
app.component('modal', Modal)
app.component('card', Card)
// Mixins
import {getNamespaceTitle} from './helpers/getNamespaceTitle'
import {getListTitle} from './helpers/getListTitle'
import {colorIsDark} from './helpers/color/colorIsDark'
import {setTitle} from './helpers/setTitle'
app.mixin({
methods: {
2021-08-20 15:38:16 +02:00
formatDateSince,
format: formatDate,
2021-08-20 15:38:16 +02:00
formatDate: formatDateLong,
formatDateShort: formatDateShort,
getNamespaceTitle,
getListTitle,
colorIsDark,
setTitle,
},
})
app.config.errorHandler = (err, vm, info) => {
2021-09-11 17:53:03 +02:00
// if (import.meta.env.PROD) {
// error(err)
2021-09-11 17:53:03 +02:00
// } else {
// console.error(err, vm, info)
error(err)
2021-09-11 17:53:03 +02:00
// }
}
if (import.meta.env.DEV) {
app.config.warnHandler = (msg, vm, info) => {
error(msg)
}
// https://stackoverflow.com/a/52076738/15522256
window.addEventListener('error', (err) => {
error(err)
throw err
})
window.addEventListener('unhandledrejection', (err) => {
// event.promise contains the promise object
// event.reason contains the reason for the rejection
error(err)
throw err
})
}
app.config.globalProperties.$message = {
error,
success,
}
if (window.SENTRY_ENABLED) {
import('./sentry').then(sentry => sentry.default(app, router))
}
app.use(router)
app.use(store)
app.use(i18n)
app.mount('#app')