Replaced mock data with live database data; minoe aesthetic changes

This commit is contained in:
2026-07-24 10:44:07 -04:00
parent ddc6484538
commit 08b753f89e
17 changed files with 1084 additions and 573 deletions
+9 -6
View File
@@ -1,15 +1,15 @@
import { app, BrowserWindow, shell, ipcMain } from 'electron'
import { fileURLToPath } from 'node:url'
import path from 'node:path'
import { fetchEntries } from './pocketbase.js'
const __dirname = path.dirname(fileURLToPath(import.meta.url))
// ─── Paths ──────────────────────────────────────────────────────────────────
// dist-electron/main.js is the compiled output location.
// dist/ is the Vite renderer build output.
const RENDERER_DIST = path.join(__dirname, '../dist')
// vite-plugin-electron outputs preload as .mjs when "type":"module" is set in package.json
const PRELOAD_PATH = path.join(__dirname, 'preload.mjs')
// Compiled main lives in dist-electron/main/ — go up two levels to reach dist/
const RENDERER_DIST = path.join(__dirname, '../../dist')
// Preload is compiled to dist-electron/preload/index.cjs (explicitly CJS)
const PRELOAD_PATH = path.join(__dirname, '../preload/index.cjs')
// ─── Dev server URL ─────────────────────────────────────────────────────────
// vite-plugin-electron sets this env var when running in development mode.
@@ -31,7 +31,7 @@ function createWindow() {
// ── Security defaults ──────────────────────────────────────────────
contextIsolation: true, // Isolates renderer from Electron internals
nodeIntegration: false, // Renderer cannot access Node.js APIs directly
sandbox: true, // Extra process isolation
sandbox: false, // Must be false so preload can use require('electron') for contextBridge
webSecurity: true,
// ── Preload ────────────────────────────────────────────────────────
preload: PRELOAD_PATH,
@@ -87,3 +87,6 @@ app.on('window-all-closed', () => {
// Example: ipcMain.handle('channel-name', async (event, ...args) => { ... })
ipcMain.handle('app:get-version', () => app.getVersion())
ipcMain.handle('pb:fetch-entries', async () => {
return await fetchEntries()
})
+4
View File
@@ -0,0 +1,4 @@
/** Internal admin app — PocketBase connection (bundled with the desktop build). */
export const POCKETBASE_URL = 'https://ctm-pocketbase.wirediv.dev'
export const PB_ADMIN_EMAIL = 'info@wirediv.com'
export const PB_ADMIN_PASSWORD = 'Supernova99!!__'
+60
View File
@@ -0,0 +1,60 @@
import PocketBase from 'pocketbase'
import { POCKETBASE_URL, PB_ADMIN_EMAIL, PB_ADMIN_PASSWORD } from './pocketbase-config.js'
const COLLECTION = 'travellers'
let pb = null
let authPromise = null
function getClient() {
if (!pb) {
pb = new PocketBase(POCKETBASE_URL)
// Main process may receive overlapping IPC calls (e.g. React Strict Mode).
// Default auto-cancel would abort duplicate in-flight PocketBase requests.
pb.autoCancellation(false)
}
return pb
}
function parseEntry(r) {
return {
id: r.emr_id,
name: r.name ?? '',
location: r.location ?? '',
countryISO: r.country_iso ?? '',
countriesISO: r.countries_iso ?? [],
status: r.status ?? '',
departure: r.departure ?? '',
arrival: r.arrival ?? '',
created: r.created,
updated: r.updated,
}
}
export async function ensureAuth() {
const client = getClient()
if (client.authStore.isValid) return
if (authPromise) {
await authPromise
return
}
// PocketBase v0.23+ removed /api/admins/*; superusers authenticate as a collection.
authPromise = client
.collection('_superusers')
.authWithPassword(PB_ADMIN_EMAIL, PB_ADMIN_PASSWORD)
try {
await authPromise
} catch (err) {
authPromise = null
throw err
}
}
export async function fetchEntries() {
await ensureAuth()
const list = await getClient().collection(COLLECTION).getFullList({ sort: '-created' })
return list.map(parseEntry)
}
@@ -15,6 +15,7 @@ const ALLOWED_SEND_CHANNELS = [
'patient:fetch-list',
'schedule:fetch',
'app:ready',
'pb:fetch-entries',
]
const ALLOWED_RECEIVE_CHANNELS = [
@@ -22,10 +23,18 @@ const ALLOWED_RECEIVE_CHANNELS = [
'patient:list-response',
'schedule:response',
'app:get-version',
'pb:fetch-entries',
]
// ─── Exposed API ──────────────────────────────────────────────────────────
contextBridge.exposeInMainWorld('api', {
/**
* PocketBase helper methods for renderer
*/
pb: {
fetchEntries: () => ipcRenderer.invoke('pb:fetch-entries'),
},
/**
* Send a one-way message to the main process.
* @param {string} channel - Must be in ALLOWED_SEND_CHANNELS