From 9b7ff6e2953102bd1c5a7e56e01f2757961df1f8 Mon Sep 17 00:00:00 2001 From: mathis Date: Wed, 26 Aug 2026 20:48:16 +0200 Subject: [PATCH] =?UTF-8?q?RELEASE=20V0.0.1.2=20:=20Insertion=20des=20donn?= =?UTF-8?q?=C3=A9es=20de=20la=20BDD=20+=20Suppression=20des=20donn=C3=A9es?= =?UTF-8?q?=20mock=C3=A9es?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/icon.svg | 24 + public/manifest.json | 36 + public/sw.js | 48 + src/app/[region]/page.tsx | 89 +- src/app/globals.css | 24 + src/app/layout.tsx | 61 +- src/app/page.tsx | 29 +- src/components/RegionContent.tsx | 1818 ++++++++++++++++++------------ 8 files changed, 1372 insertions(+), 757 deletions(-) create mode 100644 public/icon.svg create mode 100644 public/manifest.json create mode 100644 public/sw.js diff --git a/public/icon.svg b/public/icon.svg new file mode 100644 index 0000000..63f049f --- /dev/null +++ b/public/icon.svg @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + SNCF + + + + + + + + FERROVIA RÉGIONS + diff --git a/public/manifest.json b/public/manifest.json new file mode 100644 index 0000000..a2cdb76 --- /dev/null +++ b/public/manifest.json @@ -0,0 +1,36 @@ +{ + "name": "FERROVIA - Sites TER Régionaux", + "short_name": "FERROVIA", + "description": "Consultez les horaires, l'info trafic et achetez vos billets TER dans toutes les régions de France.", + "start_url": "/", + "id": "/", + "display": "standalone", + "background_color": "#ffffff", + "theme_color": "#0066a4", + "orientation": "portrait-primary", + "icons": [ + { + "src": "/icon.svg", + "sizes": "any", + "type": "image/svg+xml", + "purpose": "any maskable" + }, + { + "src": "/icon.svg", + "sizes": "192x192", + "type": "image/svg+xml" + }, + { + "src": "/icon.svg", + "sizes": "512x512", + "type": "image/svg+xml" + } + ], + "categories": [ + "travel", + "transportation" + ], + "lang": "fr-FR", + "dir": "ltr", + "prefer_related_applications": false +} diff --git a/public/sw.js b/public/sw.js new file mode 100644 index 0000000..c4fca01 --- /dev/null +++ b/public/sw.js @@ -0,0 +1,48 @@ +const CACHE_NAME = 'ferrovia-pwa-v2'; + +self.addEventListener('install', (event) => { + self.skipWaiting(); +}); + +self.addEventListener('activate', (event) => { + event.waitUntil( + caches.keys().then((keys) => { + return Promise.all( + keys.map((key) => { + if (key !== CACHE_NAME) { + return caches.delete(key); + } + }) + ); + }).then(() => self.clients.claim()) + ); +}); + +// Network-First strategy: Always try network first to guarantee live updates +self.addEventListener('fetch', (event) => { + if (event.request.method !== 'GET') return; + + const url = new URL(event.request.url); + + // Do not cache API or Supabase requests + if (url.pathname.startsWith('/api') || url.hostname.includes('supabase')) { + return; + } + + event.respondWith( + fetch(event.request) + .then((networkResponse) => { + if (networkResponse && networkResponse.status === 200 && networkResponse.type === 'basic') { + const responseToCache = networkResponse.clone(); + caches.open(CACHE_NAME).then((cache) => { + cache.put(event.request, responseToCache); + }); + } + return networkResponse; + }) + .catch(() => { + return caches.match(event.request); + }) + ); +}); + diff --git a/src/app/[region]/page.tsx b/src/app/[region]/page.tsx index 00d6c9d..12cc023 100644 --- a/src/app/[region]/page.tsx +++ b/src/app/[region]/page.tsx @@ -1,6 +1,6 @@ import React from 'react'; import { supabase } from '@/lib/supabase'; -import RegionContent from '@/components/RegionContent'; +import RegionContent, { InfoTraficItem, ActualiteItem, HoraireItem } from '@/components/RegionContent'; interface RegionData { nom_site: string; @@ -8,12 +8,8 @@ interface RegionData { description_site: string; } -interface GeneralParams { - region: string; - regions: Record; -} - -export const revalidate = 60; // Revalidate every 60s +export const dynamic = 'force-dynamic'; +export const revalidate = 0; export default async function RegionPage({ params, @@ -22,7 +18,8 @@ export default async function RegionPage({ }) { const { region } = await params; - const { data, error } = await supabase + // 1. Fetch general settings + const { data } = await supabase .from('parametres') .select('valeur') .eq('cle', 'general') @@ -69,5 +66,79 @@ export default async function RegionPage({ }; } - return ; + // 2. Fetch info trafic from Supabase table "info_trafic" + let infoTraficList: InfoTraficItem[] = []; + try { + const { data: trafficData } = await supabase + .from('info_trafic') + .select('*') + .eq('actif', true) + .is('deleted_at', null) + .order('created_at', { ascending: false }); + if (trafficData) { + infoTraficList = trafficData as InfoTraficItem[]; + } + } catch (e) { + console.error('Error fetching info_trafic:', e); + } + + // 3. Fetch actualites from Supabase table "actualites" + let actualitesList: ActualiteItem[] = []; + try { + const { data: actusData } = await supabase + .from('actualites') + .select('*') + .eq('actif', true) + .is('deleted_at', null) + .order('date_publication', { ascending: false }) + .order('created_at', { ascending: false }); + if (actusData) { + actualitesList = actusData as ActualiteItem[]; + } + } catch (e) { + console.error('Error fetching actualites:', e); + } + + // 4. Fetch gares and horaires from Supabase table "horaires" + let horairesList: HoraireItem[] = []; + try { + const { data: garesData } = await supabase + .from('gares') + .select('id, nom'); + + const garesMap: Record = {}; + if (garesData) { + garesData.forEach((g: any) => { + garesMap[g.id] = g.nom; + }); + } + + const { data: rawHoraires } = await supabase + .from('horaires') + .select('*') + .eq('actif', true) + .is('deleted_at', null) + .order('heure_depart', { ascending: true }); + + if (rawHoraires) { + horairesList = rawHoraires.map((h: any) => ({ + ...h, + gare_depart_nom: garesMap[h.gare_depart_id] || '', + gare_arrivee_nom: garesMap[h.gare_arrivee_id] || '', + })) as HoraireItem[]; + } + } catch (e) { + console.error('Error fetching horaires:', e); + } + + return ( + + ); } + diff --git a/src/app/globals.css b/src/app/globals.css index d12fb83..8198a49 100644 --- a/src/app/globals.css +++ b/src/app/globals.css @@ -145,3 +145,27 @@ body { -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; } + +@keyframes fadeIn { + from { opacity: 0; } + to { opacity: 1; } +} + +@keyframes slideInLeftDrawer { + from { + transform: translateX(-100%); + } + to { + transform: translateX(0); + } +} + +.animate-fadeIn { + animation: fadeIn 0.2s ease-out forwards; +} + +.animate-slideInLeftDrawer { + animation: slideInLeftDrawer 0.28s cubic-bezier(0.16, 1, 0.3, 1) forwards; +} + + diff --git a/src/app/layout.tsx b/src/app/layout.tsx index 5ef6b63..ac41148 100644 --- a/src/app/layout.tsx +++ b/src/app/layout.tsx @@ -1,6 +1,7 @@ -import type { Metadata } from "next"; +import type { Metadata, Viewport } from "next"; import { Geist, Geist_Mono } from "next/font/google"; import "./globals.css"; + const geistSans = Geist({ variable: "--font-geist-sans", subsets: ["latin"], @@ -12,20 +13,60 @@ const geistMono = Geist_Mono({ }); export const metadata: Metadata = { - title: "Create Next App", - description: "Generated by create next app", + title: "FERROVIA - Sites TER Régionaux", + description: "Consultez les horaires, l'info trafic et achetez vos billets TER dans toutes les régions de France.", + manifest: "/manifest.json", + appleWebApp: { + capable: true, + statusBarStyle: "default", + title: "FERROVIA", + }, + icons: { + icon: "/icon.svg", + apple: "/icon.svg", + }, }; -export default function RootLayout({ children }: { children: React.ReactNode }) -{ - return ( +export const viewport: Viewport = { + themeColor: "#0066a4", + width: "device-width", + initialScale: 1, + maximumScale: 1, + userScalable: false, + viewportFit: "cover", +}; + +export default function RootLayout({ children }: { children: React.ReactNode }) { + return ( - {children} - - + + + + + + + + + + {children} +