2023-06-12 21:15:23 +10:00
|
|
|
/* eslint-disable import/first */
|
2021-07-28 18:45:52 +05:30
|
|
|
import React from 'react';
|
2024-01-21 23:50:56 +11:00
|
|
|
import { createRoot } from 'react-dom/client';
|
2023-06-12 21:15:23 +10:00
|
|
|
import { enableMapSet } from 'immer';
|
|
|
|
|
import '@fontsource/inter/variable.css';
|
|
|
|
|
import 'folds/dist/style.css';
|
|
|
|
|
import { configClass, varsClass } from 'folds';
|
|
|
|
|
|
|
|
|
|
enableMapSet();
|
|
|
|
|
|
2025-08-29 15:04:52 +05:30
|
|
|
import './index.css';
|
2021-07-28 18:45:52 +05:30
|
|
|
|
2024-09-07 21:45:55 +08:00
|
|
|
import { trimTrailingSlash } from './app/utils/common';
|
2021-07-28 18:45:52 +05:30
|
|
|
import App from './app/pages/App';
|
|
|
|
|
|
2024-08-14 15:29:34 +02:00
|
|
|
// import i18n (needs to be bundled ;))
|
|
|
|
|
import './app/i18n';
|
|
|
|
|
|
2023-06-12 21:15:23 +10:00
|
|
|
document.body.classList.add(configClass, varsClass);
|
2021-07-28 18:45:52 +05:30
|
|
|
|
2024-09-07 21:45:55 +08:00
|
|
|
// Register Service Worker
|
|
|
|
|
if ('serviceWorker' in navigator) {
|
2024-09-09 18:45:20 +10:00
|
|
|
const swUrl =
|
|
|
|
|
import.meta.env.MODE === 'production'
|
|
|
|
|
? `${trimTrailingSlash(import.meta.env.BASE_URL)}/sw.js`
|
|
|
|
|
: `/dev-sw.js?dev-sw`;
|
|
|
|
|
|
|
|
|
|
navigator.serviceWorker.register(swUrl);
|
2024-09-07 21:45:55 +08:00
|
|
|
navigator.serviceWorker.addEventListener('message', (event) => {
|
|
|
|
|
if (event.data?.type === 'token' && event.data?.responseKey) {
|
|
|
|
|
// Get the token for SW.
|
2024-09-09 18:45:20 +10:00
|
|
|
const token = localStorage.getItem('cinny_access_token') ?? undefined;
|
2024-09-07 21:45:55 +08:00
|
|
|
event.source!.postMessage({
|
|
|
|
|
responseKey: event.data.responseKey,
|
|
|
|
|
token,
|
2024-09-09 18:45:20 +10:00
|
|
|
});
|
2024-09-07 21:45:55 +08:00
|
|
|
}
|
2024-09-09 18:45:20 +10:00
|
|
|
});
|
2024-09-07 21:45:55 +08:00
|
|
|
}
|
|
|
|
|
|
2024-01-21 23:50:56 +11:00
|
|
|
const mountApp = () => {
|
|
|
|
|
const rootContainer = document.getElementById('root');
|
|
|
|
|
|
|
|
|
|
if (rootContainer === null) {
|
|
|
|
|
console.error('Root container element not found!');
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const root = createRoot(rootContainer);
|
|
|
|
|
root.render(<App />);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
mountApp();
|