2025-05-15 20:07:33 +01:00
|
|
|
import '@mantine/core/styles.css';
|
2025-08-28 15:42:33 +01:00
|
|
|
import '../vite-env.d.ts';
|
2025-06-16 15:11:00 +01:00
|
|
|
import './index.css'; // Import Tailwind CSS
|
2025-05-09 20:01:09 +01:00
|
|
|
import React from 'react';
|
|
|
|
import ReactDOM from 'react-dom/client';
|
2025-08-19 13:31:09 +01:00
|
|
|
import { ColorSchemeScript } from '@mantine/core';
|
2025-05-15 20:07:33 +01:00
|
|
|
import { BrowserRouter } from 'react-router-dom';
|
2025-05-09 20:01:09 +01:00
|
|
|
import App from './App';
|
2025-05-29 17:26:32 +01:00
|
|
|
import './i18n'; // Initialize i18next
|
2025-08-29 14:01:46 +01:00
|
|
|
import posthog from 'posthog-js';
|
2025-08-28 15:42:33 +01:00
|
|
|
import { PostHogProvider } from 'posthog-js/react';
|
2025-05-09 20:01:09 +01:00
|
|
|
|
2025-08-19 13:31:09 +01:00
|
|
|
// Compute initial color scheme
|
|
|
|
function getInitialScheme(): 'light' | 'dark' {
|
|
|
|
const stored = localStorage.getItem('stirling-theme');
|
|
|
|
if (stored === 'light' || stored === 'dark') return stored;
|
|
|
|
try {
|
|
|
|
const prefersDark = window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches;
|
|
|
|
return prefersDark ? 'dark' : 'light';
|
|
|
|
} catch {
|
|
|
|
return 'light';
|
|
|
|
}
|
|
|
|
}
|
2025-05-27 19:22:26 +01:00
|
|
|
|
2025-08-29 14:01:46 +01:00
|
|
|
posthog.init(import.meta.env.VITE_PUBLIC_POSTHOG_KEY, {
|
|
|
|
api_host: import.meta.env.VITE_PUBLIC_POSTHOG_HOST,
|
|
|
|
defaults: '2025-05-24',
|
|
|
|
capture_exceptions: true, // This enables capturing exceptions using Error Tracking, set to false if you don't want this
|
|
|
|
debug: false,
|
|
|
|
opt_out_capturing_by_default: false, // We handle opt-out via cookie consent
|
|
|
|
});
|
|
|
|
|
|
|
|
function updatePosthogConsent(){
|
|
|
|
if(typeof(posthog) == "undefined") {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const optIn = (window.CookieConsent as any).acceptedCategory('analytics');
|
2025-09-04 16:12:38 +01:00
|
|
|
if (optIn) {
|
|
|
|
posthog.opt_in_capturing();
|
|
|
|
} else {
|
|
|
|
posthog.opt_out_capturing();
|
|
|
|
}
|
2025-08-29 14:01:46 +01:00
|
|
|
|
|
|
|
console.log("Updated analytics consent: ", optIn? "opted in" : "opted out");
|
|
|
|
}
|
|
|
|
|
|
|
|
window.addEventListener("cc:onConsent", updatePosthogConsent);
|
|
|
|
window.addEventListener("cc:onChange", updatePosthogConsent);
|
|
|
|
|
2025-05-28 21:43:02 +01:00
|
|
|
const container = document.getElementById('root');
|
|
|
|
if (!container) {
|
|
|
|
throw new Error("Root container missing in index.html");
|
|
|
|
}
|
2025-08-29 14:01:46 +01:00
|
|
|
|
2025-05-28 21:43:02 +01:00
|
|
|
const root = ReactDOM.createRoot(container); // Finds the root DOM element
|
2025-05-09 20:01:09 +01:00
|
|
|
root.render(
|
|
|
|
<React.StrictMode>
|
2025-08-19 13:31:09 +01:00
|
|
|
<ColorSchemeScript defaultColorScheme={getInitialScheme()} />
|
2025-08-28 15:42:33 +01:00
|
|
|
<PostHogProvider
|
2025-08-29 14:01:46 +01:00
|
|
|
client={posthog}
|
2025-08-28 15:42:33 +01:00
|
|
|
>
|
|
|
|
<BrowserRouter>
|
|
|
|
<App />
|
|
|
|
</BrowserRouter>
|
|
|
|
</PostHogProvider>
|
2025-05-09 20:01:09 +01:00
|
|
|
</React.StrictMode>
|
|
|
|
);
|