Safari only has to disgard warning once per session
This commit is contained in:
parent
9abd9f03f2
commit
296dd194a4
|
@ -3,7 +3,7 @@ import { useRouter } from "next/router";
|
||||||
import { useEffect, useMemo, useState } from "react";
|
import { useEffect, useMemo, useState } from "react";
|
||||||
import { useSwipeable } from "react-swipeable";
|
import { useSwipeable } from "react-swipeable";
|
||||||
import UAParser from "ua-parser-js";
|
import UAParser from "ua-parser-js";
|
||||||
import { useBoolean, useIsClient } from "usehooks-ts";
|
import { useIsClient } from "usehooks-ts";
|
||||||
import Script from "next/script";
|
import Script from "next/script";
|
||||||
import { layout } from "../../design.config";
|
import { layout } from "../../design.config";
|
||||||
import { Ico, Icon } from "./Ico";
|
import { Ico, Icon } from "./Ico";
|
||||||
|
@ -69,6 +69,8 @@ export const AppLayout = ({
|
||||||
preferredLanguages,
|
preferredLanguages,
|
||||||
selectedThemeMode,
|
selectedThemeMode,
|
||||||
subPanelOpen,
|
subPanelOpen,
|
||||||
|
hasDisgardedSafariWarning,
|
||||||
|
setHasDisgardedSafariWarning,
|
||||||
setConfigPanelOpen,
|
setConfigPanelOpen,
|
||||||
setCurrency,
|
setCurrency,
|
||||||
setDarkMode,
|
setDarkMode,
|
||||||
|
@ -144,7 +146,7 @@ export const AppLayout = ({
|
||||||
}, [currencyOptions, currencySelect, setCurrency]);
|
}, [currencyOptions, currencySelect, setCurrency]);
|
||||||
|
|
||||||
const isClient = useIsClient();
|
const isClient = useIsClient();
|
||||||
const { value: hasDisgardSafariWarning, setTrue: disgardSafariWarning } = useBoolean(false);
|
|
||||||
const isSafari = useMemo<boolean>(() => {
|
const isSafari = useMemo<boolean>(() => {
|
||||||
if (isClient) {
|
if (isClient) {
|
||||||
const parser = new UAParser();
|
const parser = new UAParser();
|
||||||
|
@ -309,7 +311,7 @@ export const AppLayout = ({
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<Popup state={isSafari && !hasDisgardSafariWarning} onClose={() => null}>
|
<Popup state={isSafari && !hasDisgardedSafariWarning} onClose={() => null}>
|
||||||
<h1 className="text-2xl">Hi, you are using Safari!</h1>
|
<h1 className="text-2xl">Hi, you are using Safari!</h1>
|
||||||
<p className="max-w-lg text-center">
|
<p className="max-w-lg text-center">
|
||||||
In most cases this wouldn’t be a problem but our website is—for some obscure
|
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"
|
text="Let me in regardless"
|
||||||
className="mt-8"
|
className="mt-8"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
disgardSafariWarning();
|
setHasDisgardedSafariWarning(true);
|
||||||
sendAnalytics("Safari", "Disgard warning");
|
sendAnalytics("Safari", "Disgard warning");
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import React, { ReactNode, useContext, useEffect, useLayoutEffect, useState } from "react";
|
import React, { ReactNode, useContext, useEffect, useLayoutEffect, useState } from "react";
|
||||||
import { useRouter } from "next/router";
|
import { useRouter } from "next/router";
|
||||||
import { useLocalStorage } from "usehooks-ts";
|
import { useLocalStorage, useSessionStorage } from "usehooks-ts";
|
||||||
import { isDefined, isDefinedAndNotEmpty } from "helpers/others";
|
import { isDefined, isDefinedAndNotEmpty } from "helpers/others";
|
||||||
import { LibraryItemUserStatus, RequiredNonNullable } from "types/types";
|
import { LibraryItemUserStatus, RequiredNonNullable } from "types/types";
|
||||||
import { useDarkMode } from "hooks/useDarkMode";
|
import { useDarkMode } from "hooks/useDarkMode";
|
||||||
|
@ -72,6 +72,11 @@ interface AppLayoutState {
|
||||||
langui: Langui;
|
langui: Langui;
|
||||||
languages: Languages;
|
languages: Languages;
|
||||||
currencies: Currencies;
|
currencies: Currencies;
|
||||||
|
|
||||||
|
hasDisgardedSafariWarning: boolean;
|
||||||
|
setHasDisgardedSafariWarning: React.Dispatch<
|
||||||
|
React.SetStateAction<AppLayoutState["hasDisgardedSafariWarning"]>
|
||||||
|
>;
|
||||||
}
|
}
|
||||||
|
|
||||||
const initialState: RequiredNonNullable<AppLayoutState> = {
|
const initialState: RequiredNonNullable<AppLayoutState> = {
|
||||||
|
@ -134,6 +139,9 @@ const initialState: RequiredNonNullable<AppLayoutState> = {
|
||||||
currencies: [],
|
currencies: [],
|
||||||
languages: [],
|
languages: [],
|
||||||
langui: {},
|
langui: {},
|
||||||
|
|
||||||
|
hasDisgardedSafariWarning: false,
|
||||||
|
setHasDisgardedSafariWarning: () => null,
|
||||||
};
|
};
|
||||||
|
|
||||||
const AppContext = React.createContext<AppLayoutState>(initialState);
|
const AppContext = React.createContext<AppLayoutState>(initialState);
|
||||||
|
@ -192,6 +200,11 @@ export const AppContextProvider = (props: Props): JSX.Element => {
|
||||||
initialState.libraryItemUserStatus
|
initialState.libraryItemUserStatus
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const [hasDisgardedSafariWarning, setHasDisgardedSafariWarning] = useSessionStorage(
|
||||||
|
"hasDisgardedSafariWarning",
|
||||||
|
initialState.hasDisgardedSafariWarning
|
||||||
|
);
|
||||||
|
|
||||||
const toggleSubPanelOpen = () => {
|
const toggleSubPanelOpen = () => {
|
||||||
setSubPanelOpen((current) => (isDefined(current) ? !current : current));
|
setSubPanelOpen((current) => (isDefined(current) ? !current : current));
|
||||||
};
|
};
|
||||||
|
@ -294,6 +307,7 @@ export const AppContextProvider = (props: Props): JSX.Element => {
|
||||||
screenWidth,
|
screenWidth,
|
||||||
contentPanelWidth,
|
contentPanelWidth,
|
||||||
subPanelWidth,
|
subPanelWidth,
|
||||||
|
hasDisgardedSafariWarning,
|
||||||
setSubPanelOpen,
|
setSubPanelOpen,
|
||||||
setConfigPanelOpen,
|
setConfigPanelOpen,
|
||||||
setMainPanelReduced,
|
setMainPanelReduced,
|
||||||
|
@ -318,6 +332,7 @@ export const AppContextProvider = (props: Props): JSX.Element => {
|
||||||
setScreenWidth,
|
setScreenWidth,
|
||||||
setContentPanelWidth,
|
setContentPanelWidth,
|
||||||
setSubPanelWidth,
|
setSubPanelWidth,
|
||||||
|
setHasDisgardedSafariWarning,
|
||||||
languages,
|
languages,
|
||||||
langui,
|
langui,
|
||||||
currencies,
|
currencies,
|
||||||
|
|
|
@ -13,6 +13,3 @@ export const prettyTerminalBoxedTitle = (string: string | null | undefined): str
|
||||||
│ ${string} │
|
│ ${string} │
|
||||||
╰${"─".repeat(string.length + 2)}╯`
|
╰${"─".repeat(string.length + 2)}╯`
|
||||||
: "";
|
: "";
|
||||||
|
|
||||||
export const prettyTerminalTitle = (title: string | null | undefined): string =>
|
|
||||||
`\n\n-= ${title?.toUpperCase()} =-`;
|
|
||||||
|
|
|
@ -298,7 +298,7 @@ export const getStaticProps: GetStaticProps = async (context) => {
|
||||||
language_code: context.locale ?? "en",
|
language_code: context.locale ?? "en",
|
||||||
});
|
});
|
||||||
if (!contents.contents) return { notFound: true };
|
if (!contents.contents) return { notFound: true };
|
||||||
|
|
||||||
contents.contents.data.sort((a, b) => {
|
contents.contents.data.sort((a, b) => {
|
||||||
const titleA = a.attributes?.slug ?? "";
|
const titleA = a.attributes?.slug ?? "";
|
||||||
const titleB = b.attributes?.slug ?? "";
|
const titleB = b.attributes?.slug ?? "";
|
||||||
|
|
Loading…
Reference in New Issue