Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
joao-vasconcelos committed Dec 8, 2023
1 parent 56ba1b3 commit ca196ff
Show file tree
Hide file tree
Showing 14 changed files with 167 additions and 3 deletions.
4 changes: 4 additions & 0 deletions frontend/app/[locale]/encm/loading.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
/* * */

import Loader from '@/components/Loader/Loader';

/* * */

export default function Loading() {
return <Loader visible full />;
}
4 changes: 4 additions & 0 deletions frontend/app/[locale]/legal/conditions/loading.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
/* * */

import Loader from '@/components/Loader/Loader';

/* * */

export default function Loading() {
return <Loader visible full />;
}
4 changes: 4 additions & 0 deletions frontend/app/[locale]/legal/cookies/loading.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
/* * */

import Loader from '@/components/Loader/Loader';

/* * */

export default function Loading() {
return <Loader visible full />;
}
4 changes: 4 additions & 0 deletions frontend/app/[locale]/legal/disclaimer/loading.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
/* * */

import Loader from '@/components/Loader/Loader';

/* * */

export default function Loading() {
return <Loader visible full />;
}
4 changes: 4 additions & 0 deletions frontend/app/[locale]/legal/privacy/loading.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
/* * */

import Loader from '@/components/Loader/Loader';

/* * */

export default function Loading() {
return <Loader visible full />;
}
4 changes: 4 additions & 0 deletions frontend/app/[locale]/lines/loading.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
/* * */

import Loader from '@/components/Loader/Loader';

/* * */

export default function Loading() {
return <Loader visible full />;
}
4 changes: 4 additions & 0 deletions frontend/app/[locale]/loading.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
/* * */

import Loader from '@/components/Loader/Loader';

/* * */

export default function Loading() {
return <Loader visible full />;
}
4 changes: 4 additions & 0 deletions frontend/app/[locale]/stops/loading.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
/* * */

import Loader from '@/components/Loader/Loader';

/* * */

export default function Loading() {
return <Loader visible full />;
}
58 changes: 58 additions & 0 deletions frontend/app/[locale]/vehicles/[vehicle_id]/opengraph-image.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/* * */

import fs from 'fs';
import { ImageResponse } from 'next/og';
import OpenGraphStopsDefault from 'opengraph/OpenGraphStopsDefault';
import OpenGraphStopsDynamic from 'opengraph/OpenGraphStopsDynamic';

/* * */

export const alt = 'Mais sobre esta paragem';
export const size = { width: 1200, height: 630 };
export const contentType = 'image/png';

/* * */

export default async function Image({ params }) {
//

//
// A. Setup fonts

const customFonts = [
{ name: 'Inter', style: 'normal', weight: 500, data: fs.readFileSync(`${process.cwd()}/assets/fonts/Inter-Medium.ttf`).buffer },
{ name: 'Inter', style: 'normal', weight: 600, data: fs.readFileSync(`${process.cwd()}/assets/fonts/Inter-SemiBold.ttf`).buffer },
{ name: 'Inter', style: 'normal', weight: 700, data: fs.readFileSync(`${process.cwd()}/assets/fonts/Inter-Bold.ttf`).buffer },
];

//
// B. Fetch data

const stopData = await fetch(params.stop_id?.length && `https://api.carrismetropolitana.pt/stops/${params.stop_id}`).then((res) => res.json());

//
// C. Render default component

if (params.stop_id === 'all' || !stopData?.id) {
return new ImageResponse(<OpenGraphStopsDefault />, { ...size, fonts: customFonts });
}

// - - -

//
// D. Fetch additional data

const allLinesData = [];

for (const lineId of stopData.lines) {
const lineData = await fetch(`https://api.carrismetropolitana.pt/lines/${lineId}`).then((res) => res.json());
allLinesData.push(lineData);
}

//
// E. Render dynamic component

return new ImageResponse(<OpenGraphStopsDynamic stopData={stopData} allLinesData={allLinesData} />, { ...size, fonts: customFonts });

//
}
54 changes: 54 additions & 0 deletions frontend/app/[locale]/vehicles/[vehicle_id]/page.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/* * */

import { OneFullColumn } from '@/components/Layouts/Layouts';
import { StopsExplorerContextProvider } from '@/contexts/StopsExplorerContext';
import StopsExplorer from '@/components/StopsExplorer/StopsExplorer';

/* * */

export async function generateMetadata({ params }) {
//

// A. Fetch stop data
const stopData = await fetch(params.stop_id?.length && `https://api.carrismetropolitana.pt/stops/${params.stop_id}`).then((res) => res.json());

// B. Render the titles
if (params.stop_id === 'all' || !stopData.name) {
switch (params.locale) {
case 'pt':
return { title: 'Todas as Paragens', description: 'Conheça as paragens e horários da Carris Metropolitana' };
default:
case 'en':
return { title: 'Todas as Paragens', description: 'Conheça as paragens e horários da Carris Metropolitana' };
}
} else {
switch (params.locale) {
case 'pt':
return { title: `Horários na paragem ${stopData.name}`, description: 'Estimativas de chegada em tempo real para os autocarros da Carris Metropolitana nesta paragem.' };
default:
case 'en':
return { title: `Horários na paragem ${stopData.name}`, description: 'Estimativas de chegada em tempo real para os autocarros da Carris Metropolitana nesta paragem.' };
}
}

//
}

/* * */

export default function Page() {
//

//
// A. Render components

return (
<OneFullColumn>
<StopsExplorerContextProvider>
<StopsExplorer />
</StopsExplorerContextProvider>
</OneFullColumn>
);

//
}
9 changes: 9 additions & 0 deletions frontend/app/[locale]/vehicles/loading.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/* * */

import Loader from '@/components/Loader/Loader';

/* * */

export default function Loading() {
return <Loader visible full />;
}
11 changes: 9 additions & 2 deletions frontend/app/layout.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,36 @@
//
// ROOT LAYOUT
/* * */

import '@/styles/reset.css';
import '@/styles/defaults.css';
import '@/styles/colors.css';
import '@mantine/core/styles.css';
import '@mantine/dates/styles.css';

/* * */

import { Inter } from 'next/font/google';
import Providers from './providers';
import { ColorSchemeScript } from '@mantine/core';

/* * */

const inter = Inter({
weight: ['400', '500', '600', '700', '800'],
subsets: ['latin'],
variable: '--font-inter',
display: 'swap',
});

/* * */

export const metadata = {
metadataBase: process.env.VERCEL_URL ? new URL(`https://${process.env.VERCEL_URL}`) : new URL(`http://0.0.0.0:${process.env.PORT || 3000}`),
title: 'Carris Metropolitana',
description: 'Horários e Paragens',
};

/* * */

export default function RootLayout({ children }) {
return (
<html className={inter.variable}>
Expand Down
4 changes: 4 additions & 0 deletions frontend/app/loading.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
/* * */

import Loader from '@/components/Loader/Loader';

/* * */

export default function Loading() {
return <Loader visible full />;
}
2 changes: 1 addition & 1 deletion frontend/app/sitemap.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//
/* * */

export default async function sitemap() {
//
Expand Down

0 comments on commit ca196ff

Please sign in to comment.