import Head from "next/head"; import Link from "next/link"; import React from "react"; // import { GiDiceEightFacesEight } from "react-icons/gi"; import { Logo2 } from "../web/icons/index.js"; /* Utilities */ const classNameSelected = (isSelected) => `no-underline py-4 px-2 ml-4 text-md font-medium cursor-pointer border-b-2 border-transparent ${ isSelected ? "text-blue-700 border-blue-700" : "text-gray-400 hover:text-blue-500 hover:border-blue-500" }`; let 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 { // https://reactjs.org/docs/error-boundaries.html constructor(props) { super(props); this.state = { error: null, errorInfo: null }; } componentDidCatch(error, 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; } } /* Main */ export default function Layout({ 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. const refreshPage = () => { // window.location.reload(true); // window.location.replace(window.location.pathname); // window.location.reload(); // https://developer.mozilla.org/en-US/docs/Web/API/Location/reload // https://developer.mozilla.org/en-US/docs/Web/API/Location/replace // https://developer.mozilla.org/en-US/docs/Web/API/Location/assign // window.location.hostname if (typeof window !== "undefined") { if (window.location != window.location.pathname) { window.location.assign(window.location.pathname); } } }; return (
Metaforecast
{children}
); }