import Head from "next/head"; import Link from "next/link"; import React, { ErrorInfo } from "react"; import { Logo2 } from "../icons"; interface MenuItem { page: string; link: string; title: string; } const menu: MenuItem[] = [ { page: "search", link: "/", title: "Search", }, { page: "tools", link: "/tools", title: "Tools", }, { page: "about", link: "/about", title: "About", }, ]; /* Utilities */ const calculateLastUpdate = () => { let today = new Date().toISOString(); let yesterdayObj = new Date(); yesterdayObj.setDate(yesterdayObj.getDate() - 1); let yesterday = yesterdayObj.toISOString(); if (today.slice(11, 16) > "02:00") { return today.slice(0, 10); } else { return yesterday.slice(0, 10); } }; // Error catcher class ErrorBoundary extends React.Component< {}, { error: any; errorInfo: any } > { // https://reactjs.org/docs/error-boundaries.html constructor(props: {}) { super(props); this.state = { error: null, errorInfo: null }; } componentDidCatch(error: Error, errorInfo: ErrorInfo) { // Catch errors in any components below and re-render with error message this.setState({ error: error, errorInfo: errorInfo, }); // You can also log error messages to an error reporting service here } render() { if (this.state.errorInfo) { // Error path return (

Something went wrong.

{ "You should angrily tweet at @NunoSempere about this. or send an email to nuno.semperelh@gmail.com" } {this.state.error && this.state.error.toString()}
{this.state.errorInfo.componentStack}
); } // Normally, just render children return this.props.children; } } interface Props { page: string; // id used for menu } /* Main */ export const Layout: React.FC = ({ page, children }) => { let lastUpdated = calculateLastUpdate(); // The correct way to do this would be by passing a prop to Layout, // and to get the last updating using server side props. return (
Metaforecast
{children}
); };