tethys.backend/resources/js/app.js

80 lines
2.5 KiB
JavaScript
Raw Normal View History

2023-03-03 15:54:28 +00:00
import '../css/app.css';
import { createApp, h } from 'vue';
import { Inertia } from '@inertiajs/inertia';
import { createInertiaApp, Link, usePage } from '@inertiajs/vue3';
2023-03-17 15:13:37 +00:00
// import DefaultLayout from '@/Layouts/Default.vue';
2023-03-03 15:54:28 +00:00
import { createPinia } from 'pinia';
2023-03-17 15:13:37 +00:00
import { StyleService } from '@/Stores/style';
import { LayoutService } from '@/Stores/layout';
2023-03-03 15:54:28 +00:00
import { MainService } from '@/Stores/main';
import { darkModeKey, styleKey } from '@/config';
const pinia = createPinia();
import { EmitterPlugin } from '@/EmitterDirective';
2023-03-03 15:54:28 +00:00
2024-03-14 19:25:27 +00:00
import { initRoutes } from '@eidellev/adonis-stardust/client/index.js';
2023-03-03 15:54:28 +00:00
initRoutes();
2023-03-17 15:13:37 +00:00
// import '@fontsource/archivo-black/index.css';
// import '@fontsource/inter/index.css';
2023-03-03 15:54:28 +00:00
createInertiaApp({
2023-03-17 15:13:37 +00:00
progress: {
// color: '#4B5563',
color: '#22C55E',
2024-03-14 19:25:27 +00:00
},
2023-03-17 15:13:37 +00:00
// Webpack
// resolve: (name) => require(`./Pages/${name}`),
// resolve: (name) => require(`./Pages/${name}.vue`),
// add default layout
2024-03-14 19:25:27 +00:00
// resolve: (name) => {
// const page = require(`./Pages/${name}.vue`).default;
// // if (!page.layout) {
// // page.layout = DefaultLayout;
// // }
// return page;
// },
resolve: async (name) => {
// Dynamically import the Vue component using import
const { default: page } = await import(`./Pages/${name}.vue`);
// const page = require(`./Pages/${name}.vue`).default;
2023-03-17 15:13:37 +00:00
// if (!page.layout) {
// page.layout = DefaultLayout;
// }
return page;
},
2024-03-14 19:25:27 +00:00
// resolve: async (name) => {
// const firstPath = `@/Pages/${name}.vue`;
// const module = await import(firstPath);
// return module.default || null;
// },
2023-03-17 15:13:37 +00:00
setup({ el, App, props, plugin }) {
createApp({ render: () => h(App, props) })
.use(plugin)
.use(pinia)
.use(EmitterPlugin)
2023-03-17 15:13:37 +00:00
// .component('inertia-link', Link)
.mount(el);
},
2023-03-03 15:54:28 +00:00
});
const styleService = StyleService(pinia);
const layoutService = LayoutService(pinia);
// const mainService = MainService(pinia);
// mainService.setUser(user);
/* App style */
styleService.setStyle(localStorage[styleKey] ?? 'basic');
/* Dark mode */
if ((!localStorage[darkModeKey] && window.matchMedia('(prefers-color-scheme: dark)').matches) || localStorage[darkModeKey] === '1') {
2023-03-17 15:13:37 +00:00
styleService.setDarkMode(true);
2023-03-03 15:54:28 +00:00
}
/* Collapse mobile aside menu on route change */
Inertia.on('navigate', (event) => {
2023-03-17 15:13:37 +00:00
layoutService.isAsideMobileExpanded = false;
layoutService.isAsideLgActive = false;
2023-03-03 15:54:28 +00:00
});