Files
hobbypj-contents/ui/app.js
T
Bkk1234 f9dffbd132 chore: replace footer columns with a single copyright line
- footer is now '© hobbypj 2026' centred on one row; brand/note/contact columns removed
- site-level contact_email retired end to end (schema, payload, server validation,
  admin field, footer link logic); project-level contact_email untouched
- content-only change: service worker version unchanged (network-first)
2026-11-19 11:24:59 +07:00

88 lines
2.7 KiB
JavaScript

/* app.js — จุดเริ่มของแอป: โหลดข้อมูล → ผูก router → เรนเดอร์หน้า */
import { hydrateIcons, toast } from "./ui.js";
import { loadProjects, normalizeData } from "./data.js";
import { defineRoutes, markActiveNav, onRouteChange, startRouter } from "./router.js";
import { countUpInside, initMotion, initReveal } from "./motion.js";
import { homeView } from "./views/home.js";
import { adminView } from "./views/admin.js";
import "./pwa.js";
const main = document.getElementById("main");
const state = {
data: normalizeData({}),
source: "empty",
};
const ctx = {
get data() {
return state.data;
},
get source() {
return state.source;
},
setData(data) {
state.data = normalizeData(data);
state.source = "server";
},
async reload() {
const result = await loadProjects();
state.data = result.data;
state.source = result.source;
return result;
},
};
let activeView = null;
const TITLES = {
"/": "โปรเจคอดิเรกของเรา",
"/admin": "จัดการข้อมูล · โปรเจคอดิเรก",
};
function renderRoute({ path, view }) {
if (activeView && typeof activeView.destroy === "function") activeView.destroy();
main.replaceChildren();
activeView = view(ctx);
activeView.mount(main);
markActiveNav(path);
document.title = TITLES[path] || TITLES["/"];
window.scrollTo({ top: 0, behavior: "auto" });
main.focus({ preventScroll: true });
initReveal(main);
countUpInside(main);
}
function skeleton() {
main.innerHTML = `
<div class="wrap">
<div class="hero" style="min-height:280px"></div>
<div class="loading" aria-hidden="true">
<div class="skeleton"></div><div class="skeleton"></div><div class="skeleton"></div>
</div>
<p class="visually-hidden" role="status">กำลังโหลดรายชื่อโปรเจค</p>
</div>`;
}
async function boot() {
hydrateIcons();
initMotion();
skeleton();
const result = await loadProjects();
state.data = result.data;
state.source = result.source;
defineRoutes({ "/": homeView, "/admin": adminView }, "/");
onRouteChange(renderRoute);
startRouter();
if (result.source === "cache") {
toast("เปิดแบบออฟไลน์ — แสดงข้อมูลที่บันทึกไว้ในเครื่อง");
} else if (result.source === "empty") {
toast("อ่านข้อมูลโปรเจคไม่ได้ — เข้าไปเพิ่มรายการได้ที่หน้า “จัดการข้อมูล”", "error");
}
}
boot();