From 2c567dd96712a887b42cf4df3bdaa9f5f2b51a43 Mon Sep 17 00:00:00 2001 From: Bobby <30593201+luciferreeves@users.noreply.github.com> Date: Wed, 11 Feb 2026 12:48:01 +0530 Subject: Refactor homepage and error templates, add service worker and manifest for PWA support --- router/base.go | 2 +- scripts/reset.db.sh | 0 static/js/app.js | 23 +++++++++++++++++++++++ static/js/worker.js | 22 ++++++++++++++++++++++ static/manifest.json | 24 ++++++++++++++++++++++++ templates/error.django | 11 +---------- templates/layouts/base.django | 20 +++++++++++++------- templates/pages/home.django | 13 ------------- templates/pages/main.django | 5 +++++ 9 files changed, 89 insertions(+), 31 deletions(-) mode change 100644 => 100755 scripts/reset.db.sh create mode 100644 static/js/app.js create mode 100644 static/js/worker.js create mode 100644 static/manifest.json delete mode 100644 templates/pages/home.django create mode 100644 templates/pages/main.django diff --git a/router/base.go b/router/base.go index b178d50..aaeaad3 100644 --- a/router/base.go +++ b/router/base.go @@ -12,6 +12,6 @@ func init() { urls.SetNamespace("") urls.Path(types.GET, "/", func(c *fiber.Ctx) error { - return shortcuts.Render(c, "pages/home", nil) + return shortcuts.Render(c, "pages/main", fiber.Map{}) }, "home") } diff --git a/scripts/reset.db.sh b/scripts/reset.db.sh old mode 100644 new mode 100755 diff --git a/static/js/app.js b/static/js/app.js new file mode 100644 index 0000000..f1ec61e --- /dev/null +++ b/static/js/app.js @@ -0,0 +1,23 @@ +if ('serviceWorker' in navigator) { + window.addEventListener('load', () => { + navigator.serviceWorker.register('/worker.js') + .then(registration => { + console.log('ServiceWorker registered:', registration); + }) + .catch(error => { + console.log('ServiceWorker registration failed:', error); + }); + }); +} + +let deferredPrompt; +window.addEventListener('beforeinstallprompt', (e) => { + e.preventDefault(); + deferredPrompt = e; +}); + +document.body.addEventListener('htmx:afterSwap', (event) => { + event.detail.elt.querySelectorAll('.animate-slide-up').forEach((el, i) => { + el.style.animationDelay = `${i * 0.1}s`; + }); +}); \ No newline at end of file diff --git a/static/js/worker.js b/static/js/worker.js new file mode 100644 index 0000000..84d94df --- /dev/null +++ b/static/js/worker.js @@ -0,0 +1,22 @@ +const CACHE_NAME = 'cafe'; +const urlsToCache = [ + '/', + '/static/css/style.css', + '/static/js/htmx.min.js', + '/static/js/app.js', + '/static/manifest.json' +]; + +self.addEventListener('install', (event) => { + event.waitUntil( + caches.open(CACHE_NAME) + .then((cache) => cache.addAll(urlsToCache)) + ); +}); + +self.addEventListener('fetch', (event) => { + event.respondWith( + caches.match(event.request) + .then((response) => response || fetch(event.request)) + ); +}); \ No newline at end of file diff --git a/static/manifest.json b/static/manifest.json new file mode 100644 index 0000000..1bca313 --- /dev/null +++ b/static/manifest.json @@ -0,0 +1,24 @@ +{ + "name": "Shifoo's Cafe", + "short_name": "Cafe", + "description": "A cozy place for close friends!", + "start_url": "/", + "display": "standalone", + "background_color": "#0a0a0f", + "theme_color": "#1a1a2e", + "orientation": "portrait-primary", + "icons": [ + { + "src": "/static/icons/icon-192.png", + "sizes": "192x192", + "type": "image/png", + "purpose": "any maskable" + }, + { + "src": "/static/icons/icon-512.png", + "sizes": "512x512", + "type": "image/png", + "purpose": "any maskable" + } + ] +} \ No newline at end of file diff --git a/templates/error.django b/templates/error.django index 18c86be..ae0b9b7 100644 --- a/templates/error.django +++ b/templates/error.django @@ -3,14 +3,5 @@ {% block title %}{{ ErrorTitle }}{% endblock %} {% block content %} -
-
-

Error

-

{{ ErrorTitle }}

-

{{ ErrorMessage }}

- - Go Home - -
-
+ There was this error {{ ErrorTitle }}: {{ ErrorMessage }} {% endblock %} \ No newline at end of file diff --git a/templates/layouts/base.django b/templates/layouts/base.django index be07b4a..5390e4b 100644 --- a/templates/layouts/base.django +++ b/templates/layouts/base.django @@ -3,17 +3,23 @@ - {% block title %}Shifoo's Cafe{% endblock %} + + {% block title %}{{ Title }}{% endblock %} + + + + + {% block head %}{% endblock %} - - {% block body %} -
- {% block content %}{% endblock %} -
- {% endblock %} + +
+ {% block content %}{% endblock %} +
+ + {% block scripts %}{% endblock %} \ No newline at end of file diff --git a/templates/pages/home.django b/templates/pages/home.django deleted file mode 100644 index 7ceeae7..0000000 --- a/templates/pages/home.django +++ /dev/null @@ -1,13 +0,0 @@ -{% extends "layouts/base.django" %} - -{% block title %}{{ Title }}{% endblock %} - -{% block content %} -
-
-

{{ AppName }}

-

{{ AppDescription }}

-

Request: {{ Request.Method }} {{ Request.Path }}

-
-
-{% endblock %} \ No newline at end of file diff --git a/templates/pages/main.django b/templates/pages/main.django new file mode 100644 index 0000000..429ffbf --- /dev/null +++ b/templates/pages/main.django @@ -0,0 +1,5 @@ +{% extends "layouts/base.django" %} + +{% block content %} +This will be cafe. +{% endblock %} \ No newline at end of file -- cgit v1.2.3