Skip to content

Commit

Permalink
Tz fix (#106)
Browse files Browse the repository at this point in the history
* Fix ClientOnly

* Remove console.log in StackLayerPriorities

* Force locale & timzone to avoid react hydration problems
  • Loading branch information
qgerome authored Jun 27, 2022
1 parent 89adda2 commit 458b056
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/components/ClientOnly.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const ClientOnly = (props: ClientOnlyProps) => {
return null;
}

return null;
return props.children;
};

export default ClientOnly;
2 changes: 0 additions & 2 deletions src/features/dataset/StackLayerPriorities.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ const StackLayerPriorities = (props: StackLayerPrioritiesProps) => {
[layers]
);

console.log(disabled);

useEffect(() => {
const layersIds = layers.map((l) => l.id);
// Check that all items in the value are present in the layers
Expand Down
50 changes: 50 additions & 0 deletions src/libs/cookie.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
export type SetCookieOptions = {
expires?: string | number | Date;
path?: string;
[key: string]: any;
};

export function setCookie(
name: string,
value: any,
options: SetCookieOptions = {}
) {
options = {
path: "/",
// add other defaults here if necessary
...options,
};

if (options.expires instanceof Date) {
options.expires = options.expires.toUTCString();
}

let updatedCookie =
encodeURIComponent(name) + "=" + encodeURIComponent(value);

for (let optionKey in options) {
updatedCookie += "; " + optionKey;
let optionValue = options[optionKey];
updatedCookie += "=" + optionValue;
}

document.cookie = updatedCookie;
}

export function deleteCookie(name: string) {
setCookie(name, "", {
"max-age": -1,
});
}

export function getCookie(name: string, cookie?: string) {
cookie = cookie ?? document.cookie;
let matches = cookie.match(
new RegExp(
"(?:^|; )" +
name.replace(/([\.$?*|{}\(\)\[\]\\\/\+^])/g, "\\$1") +
"=([^;]*)"
)
);
return matches ? decodeURIComponent(matches[1]) : undefined;
}
8 changes: 6 additions & 2 deletions src/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@ import AlertManager from "components/AlertManager";
import Layout from "components/layouts/Layout";
import { useApollo } from "libs/apollo";
import { AppPropsWithLayout } from "libs/types";
import { Settings } from "luxon";
import { appWithTranslation } from "next-i18next";
import Head from "next/head";
import NavigationProgress from "nextjs-progressbar";
import "../styles/globals.css";

function App({ Component, pageProps }: AppPropsWithLayout) {
Settings.defaultLocale = "en";
Settings.defaultZone = "Europe/Brussels";

function CustomApp({ Component, pageProps }: AppPropsWithLayout) {
const apolloClient = useApollo(pageProps);

const getLayout =
Expand All @@ -32,4 +36,4 @@ function App({ Component, pageProps }: AppPropsWithLayout) {
);
}

export default appWithTranslation(App);
export default appWithTranslation(CustomApp);

0 comments on commit 458b056

Please sign in to comment.