50 lines
1.8 KiB
TypeScript
50 lines
1.8 KiB
TypeScript
import { createInertiaApp } from '@inertiajs/vue3';
|
|
import axios from 'axios';
|
|
import { resolvePageComponent } from 'laravel-vite-plugin/inertia-helpers';
|
|
import type { DefineComponent } from 'vue';
|
|
import { createApp, h } from 'vue';
|
|
import '../css/app.css';
|
|
import { initializeTheme } from './composables/useAppearance';
|
|
import { initializePrimaryColor } from './composables/usePrimaryColor';
|
|
import { i18n, initI18n } from './i18n';
|
|
|
|
const appName = import.meta.env.VITE_APP_NAME || 'Laravel';
|
|
|
|
// Configure Axios to include CSRF token
|
|
axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';
|
|
const token = document.head.querySelector('meta[name="csrf-token"]');
|
|
if (token) {
|
|
axios.defaults.headers.common['X-CSRF-TOKEN'] = (token as HTMLMetaElement).content;
|
|
}
|
|
|
|
createInertiaApp({
|
|
title: (title) => (title ? `${title} - ${appName}` : appName),
|
|
resolve: (name) =>
|
|
resolvePageComponent(
|
|
`./pages/${name}.vue`,
|
|
import.meta.glob<DefineComponent>('./pages/**/*.vue', { eager: false }),
|
|
),
|
|
setup({ el, App, props, plugin }) {
|
|
const initialLocale = ((props as any).initialPage?.props?.locale) || 'en';
|
|
const app = createApp({ render: () => h(App, props) });
|
|
|
|
// Initialize i18n with the server-provided locale, then mount
|
|
initI18n(initialLocale).finally(() => {
|
|
app.use(plugin).use(i18n).mount(el);
|
|
});
|
|
},
|
|
progress: {
|
|
color: '#df006a',
|
|
},
|
|
});
|
|
|
|
// This will set light / dark mode on page load...
|
|
initializeTheme();
|
|
// Apply saved primary color (main accent) on page load...
|
|
initializePrimaryColor();
|
|
// Initialize casino data-theme before first paint to avoid flash
|
|
try {
|
|
const t = localStorage.getItem('casino-theme');
|
|
document.documentElement.setAttribute('data-theme', t === 'light' ? 'light' : 'dark');
|
|
} catch {}
|