Skip to content
Snippets Groups Projects
main.js 3.02 KiB
import Vue from 'vue'
import Root from './Root.vue'
import App from './App.vue'
import About from './components/About.vue'
import DictionaryView from './components/DictionaryView.vue'
import VueRouter from 'vue-router'
import { VuePlausible } from 'vue-plausible'
import vuetify from './plugins/vuetify'
import Vuex from 'vuex'
import i18n from './i18n'


Vue.config.productionTip = false
Vue.use(Vuex)
Vue.use(VueRouter)
Vue.use(VuePlausible, {
  domain: 'beta.ordbok.uib.no'
})

Vue.$plausible.enableAutoPageviews()

const store = new Vuex.Store({
  strict: true,
  state: {
    showSearchToolbar: null,
    showHGNO: null,
    showInflectionNo: null,
    currentLocale: null
  },
  mutations: {
    initStore(state) {
      state.showSearchToolbar = localStorage.getItem('showSearchToolbar') || false
      state.showHGNO = localStorage.getItem('showHGNO') || false
      state.showInflectionNo = localStorage.getItem('showInflectionNo') || false
      state.currentLocale = localStorage.getItem('currentLocale') || {text:"nob", value: "nob"}
    },
    changeLocale(state, locale) {
      state.currentLocale = locale
      localStorage.setItem("currentLocale", locale);
    },
    toggle(state, setting) {
      let value = !state[setting]
      state[setting] = value
      localStorage.setItem(setting, value);
    }
  },
  actions: {
    resetStore(context) {
      localStorage.removeItem("showSearchToolbar")
      localStorage.removeItem("showHGNO")
      localStorage.removeItem("showInflectionNo")
      localStorage.removeItem("currentLocale")
      context.commit("initStore")
    },
  }
})

const router = new VueRouter({
  mode: 'history',
  base: __dirname,
  routes: [
    {
      path: '/',
      component: App,
      children: [
        {
          path: 'om',
          name: 'about',
          component: About
        },
        {
          path: '',
          component: DictionaryView,
          children: [
            {
              path: ':lang(bm|nn|bm,nn)',
              children: [
                {
                  name: 'word',
                  path: 'w/:word/:pos?'
                },
                {
                  name: 'lookup',
                  path: ':id(\\d+)/:lemma?'
                },
                {
                  name: 'search',
                  path: 'search/:query/:pos?'
                }
              ]
            },
            {
              path: 'bob/*',
              redirect: to => {
                return "bm/" + to.params.pathMatch
              }
            },
            {
              path: 'nob/*',
              redirect: to => {
                console.log(to)
                return "nn/" + to.params.pathMatch
              }
            },
            {
              path: 'bob,nob/*',
              redirect: to => {
                return "bm,nn/" + to.params.pathMatch
              }
            }
          ]
        }
      ]
    }
  ]
})

new Vue({
  router,
  vuetify,
  store,

  beforeCreate() {
		this.$store.commit('initStore');
	},

  i18n,
  render: h => h(Root )
}).$mount('#app')