From 296dd194a45aa10888627b11836734a8c1e1082b Mon Sep 17 00:00:00 2001 From: DrMint Date: Mon, 5 Sep 2022 17:29:44 +0200 Subject: [PATCH] Safari only has to disgard warning once per session --- src/components/AppLayout.tsx | 10 ++++++---- src/contexts/AppLayoutContext.tsx | 17 ++++++++++++++++- src/helpers/terminal.ts | 3 --- src/pages/contents/all.tsx | 2 +- 4 files changed, 23 insertions(+), 9 deletions(-) diff --git a/src/components/AppLayout.tsx b/src/components/AppLayout.tsx index 4718840..a95fc69 100644 --- a/src/components/AppLayout.tsx +++ b/src/components/AppLayout.tsx @@ -3,7 +3,7 @@ import { useRouter } from "next/router"; import { useEffect, useMemo, useState } from "react"; import { useSwipeable } from "react-swipeable"; import UAParser from "ua-parser-js"; -import { useBoolean, useIsClient } from "usehooks-ts"; +import { useIsClient } from "usehooks-ts"; import Script from "next/script"; import { layout } from "../../design.config"; import { Ico, Icon } from "./Ico"; @@ -69,6 +69,8 @@ export const AppLayout = ({ preferredLanguages, selectedThemeMode, subPanelOpen, + hasDisgardedSafariWarning, + setHasDisgardedSafariWarning, setConfigPanelOpen, setCurrency, setDarkMode, @@ -144,7 +146,7 @@ export const AppLayout = ({ }, [currencyOptions, currencySelect, setCurrency]); const isClient = useIsClient(); - const { value: hasDisgardSafariWarning, setTrue: disgardSafariWarning } = useBoolean(false); + const isSafari = useMemo(() => { if (isClient) { const parser = new UAParser(); @@ -309,7 +311,7 @@ export const AppLayout = ({ )} - null}> + null}>

Hi, you are using Safari!

In most cases this wouldn’t be a problem but our website is—for some obscure @@ -324,7 +326,7 @@ export const AppLayout = ({ text="Let me in regardless" className="mt-8" onClick={() => { - disgardSafariWarning(); + setHasDisgardedSafariWarning(true); sendAnalytics("Safari", "Disgard warning"); }} /> diff --git a/src/contexts/AppLayoutContext.tsx b/src/contexts/AppLayoutContext.tsx index a2c8265..be02a89 100644 --- a/src/contexts/AppLayoutContext.tsx +++ b/src/contexts/AppLayoutContext.tsx @@ -1,6 +1,6 @@ import React, { ReactNode, useContext, useEffect, useLayoutEffect, useState } from "react"; import { useRouter } from "next/router"; -import { useLocalStorage } from "usehooks-ts"; +import { useLocalStorage, useSessionStorage } from "usehooks-ts"; import { isDefined, isDefinedAndNotEmpty } from "helpers/others"; import { LibraryItemUserStatus, RequiredNonNullable } from "types/types"; import { useDarkMode } from "hooks/useDarkMode"; @@ -72,6 +72,11 @@ interface AppLayoutState { langui: Langui; languages: Languages; currencies: Currencies; + + hasDisgardedSafariWarning: boolean; + setHasDisgardedSafariWarning: React.Dispatch< + React.SetStateAction + >; } const initialState: RequiredNonNullable = { @@ -134,6 +139,9 @@ const initialState: RequiredNonNullable = { currencies: [], languages: [], langui: {}, + + hasDisgardedSafariWarning: false, + setHasDisgardedSafariWarning: () => null, }; const AppContext = React.createContext(initialState); @@ -192,6 +200,11 @@ export const AppContextProvider = (props: Props): JSX.Element => { initialState.libraryItemUserStatus ); + const [hasDisgardedSafariWarning, setHasDisgardedSafariWarning] = useSessionStorage( + "hasDisgardedSafariWarning", + initialState.hasDisgardedSafariWarning + ); + const toggleSubPanelOpen = () => { setSubPanelOpen((current) => (isDefined(current) ? !current : current)); }; @@ -294,6 +307,7 @@ export const AppContextProvider = (props: Props): JSX.Element => { screenWidth, contentPanelWidth, subPanelWidth, + hasDisgardedSafariWarning, setSubPanelOpen, setConfigPanelOpen, setMainPanelReduced, @@ -318,6 +332,7 @@ export const AppContextProvider = (props: Props): JSX.Element => { setScreenWidth, setContentPanelWidth, setSubPanelWidth, + setHasDisgardedSafariWarning, languages, langui, currencies, diff --git a/src/helpers/terminal.ts b/src/helpers/terminal.ts index 76f4ac1..04937c7 100644 --- a/src/helpers/terminal.ts +++ b/src/helpers/terminal.ts @@ -13,6 +13,3 @@ export const prettyTerminalBoxedTitle = (string: string | null | undefined): str │ ${string} │ ╰${"─".repeat(string.length + 2)}╯` : ""; - -export const prettyTerminalTitle = (title: string | null | undefined): string => - `\n\n-= ${title?.toUpperCase()} =-`; diff --git a/src/pages/contents/all.tsx b/src/pages/contents/all.tsx index 2d8d3a0..b54e3c4 100644 --- a/src/pages/contents/all.tsx +++ b/src/pages/contents/all.tsx @@ -298,7 +298,7 @@ export const getStaticProps: GetStaticProps = async (context) => { language_code: context.locale ?? "en", }); if (!contents.contents) return { notFound: true }; - + contents.contents.data.sort((a, b) => { const titleA = a.attributes?.slug ?? ""; const titleB = b.attributes?.slug ?? "";