Introduce initial version of the Lonc app with core features, styling, and configurations.
- Add base app structure, including Bootstrap setup and Alpine.js integration. - Implement authentication flow with session handling. - Integrate stock management and label creation functionalities. - Include responsive styling and theme using CSS variables and custom components. - Add API clients for Tryton-based backend. - Set up kitchen and dashboard navigation workflows. - Configure service worker for PWA support.
This commit is contained in:
Vendored
+91
@@ -0,0 +1,91 @@
|
||||
import Alpine from 'alpinejs';
|
||||
|
||||
import { logout, restoreSession, verifyConnection } from '../api/auth.js';
|
||||
import { listKitchens } from '../api/kitchens.js';
|
||||
import { APP_NAME } from './config.js';
|
||||
import { createRouter, navigate } from './router.js';
|
||||
import { createAppStore } from './store.js';
|
||||
import { appShell } from '../components/app-shell.js';
|
||||
import { registerFeatureData } from '../features/register.js';
|
||||
|
||||
async function installServiceWorker() {
|
||||
if ('serviceWorker' in navigator) {
|
||||
await navigator.serviceWorker.register('/service-worker.js');
|
||||
}
|
||||
}
|
||||
|
||||
export function bootstrapApp() {
|
||||
const store = createAppStore();
|
||||
Alpine.store('app', store);
|
||||
|
||||
registerFeatureData(Alpine, store);
|
||||
|
||||
const appRoot = document.querySelector('#app');
|
||||
appRoot.innerHTML = appShell(APP_NAME);
|
||||
Alpine.initTree(appRoot);
|
||||
|
||||
const router = createRouter({
|
||||
Alpine,
|
||||
store,
|
||||
outlet: document.querySelector('#route-view'),
|
||||
});
|
||||
|
||||
window.__loncApp = {
|
||||
navigate,
|
||||
async refreshKitchens() {
|
||||
const kitchens = await listKitchens(store);
|
||||
store.setKitchens(kitchens);
|
||||
if (!store.activeKitchen && kitchens.length) {
|
||||
store.setActiveKitchen(kitchens[0]);
|
||||
}
|
||||
return kitchens;
|
||||
},
|
||||
async restoreSession() {
|
||||
try {
|
||||
await restoreSession(store);
|
||||
if (store.isConnected) {
|
||||
await window.__loncApp.refreshKitchens();
|
||||
}
|
||||
} catch (error) {
|
||||
if (window.location.hash !== '#/login') {
|
||||
navigate('/login');
|
||||
}
|
||||
}
|
||||
},
|
||||
async verifyConnection() {
|
||||
await verifyConnection(store);
|
||||
if (store.isConnected) {
|
||||
await window.__loncApp.refreshKitchens();
|
||||
}
|
||||
return store.session;
|
||||
},
|
||||
async logout() {
|
||||
await logout(store);
|
||||
navigate('/login');
|
||||
},
|
||||
router,
|
||||
};
|
||||
|
||||
window.addEventListener('online', () => {
|
||||
store.addAlert({ type: 'success', message: 'Connection restored.' });
|
||||
});
|
||||
|
||||
window.addEventListener('offline', () => {
|
||||
store.addAlert({
|
||||
type: 'warning',
|
||||
message: 'You are offline. Cached screens stay available, but API actions may fail.',
|
||||
});
|
||||
});
|
||||
|
||||
window.__loncApp
|
||||
.restoreSession()
|
||||
.finally(() => router.start())
|
||||
.catch(() => router.start());
|
||||
|
||||
installServiceWorker().catch(() => {
|
||||
store.addAlert({
|
||||
type: 'warning',
|
||||
message: 'PWA installation support could not be initialized.',
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user