Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/mobile/page.module.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.main {
/* .main {
display: flex;
flex-direction: column;
justify-content: center;
Expand All @@ -9,4 +9,4 @@

.message {
font-weight: 500;
}
} */
46 changes: 23 additions & 23 deletions app/mobile/page.tsx
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
"use client";
// "use client";

import React, { useEffect } from "react";
import styles from "./page.module.css";
import classnames from "classnames";
import { outfitFont } from "../styles/fonts";
// import React, { useEffect } from "react";
// import styles from "./page.module.css";
// import classnames from "classnames";
// import { outfitFont } from "../styles/fonts";

export default function Mobile() {
useEffect(() => {
// if not on mobile, redirect to the main page
if (window.innerWidth > 768) {
window.location.href = "/";
}
}, []);
return (
<div className={styles.main}>
<div className={classnames(styles.message, outfitFont.className)}>
We are sorry,
<br />
Tour of JSON Schema is not optimized for mobile devices. Please use a
desktop computer for the best experience.
</div>
</div>
);
}
// export default function Mobile() {
// useEffect(() => {
// // if not on mobile, redirect to the main page
// if (window.innerWidth > 768) {
// window.location.href = "/";
// }
// }, []);
// return (
// <div className={styles.main}>
// <div className={classnames(styles.message, outfitFont.className)}>
// We are sorry,
// <br />
// Tour of JSON Schema is not optimized for mobile devices. Please use a
// desktop computer for the best experience.
// </div>
// </div>
// );
// }
60 changes: 51 additions & 9 deletions app/providers.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,56 @@
"use client";
import { ChakraProvider } from "@chakra-ui/react";
import { theme } from "./styles/theme";
import { useEffect } from "react";
import styles from "./styles/page.module.css";
import classnames from "classnames";

import { useEffect, useState } from "react";
import { outfitFont } from "./styles/fonts";

const MOBILE_BREAKPOINT = 768;

export function Providers({ children }: { children: React.ReactNode }) {
// useEffect(() => {
// if (window.innerWidth < 768 && !window.location.href.includes("/mobile")) {
// window.location.href = "/mobile";
// }
// }, []);

return <ChakraProvider theme={theme}>{children}</ChakraProvider>;
}
// 1. Initialize state for mobile status
const [isMobile, setIsMobile] = useState(false);
const [hasChecked, setHasChecked] = useState(false);

useEffect(() => {
// 2. Function to check the screen width
const checkMobileStatus = () => {
setIsMobile(window.innerWidth <= MOBILE_BREAKPOINT);
setHasChecked(true);
};

checkMobileStatus();


window.addEventListener('resize', checkMobileStatus);

return () => {
window.removeEventListener('resize', checkMobileStatus);
};
}, []);

if (!hasChecked) {
return null;
}

if (!isMobile) {
return (
<ChakraProvider theme={theme}>
{children}
</ChakraProvider>
);
}

return (
<div className={styles.main}>
<div className={classnames(styles.message, outfitFont.className)}>
We are sorry,
<br />
Tour of JSON Schema is not optimized for mobile devices. Please use a
desktop computer for the best experience.
</div>
</div>
);
}
9 changes: 7 additions & 2 deletions app/styles/page.module.css
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
.main {
display: flex;
flex-direction: column;
height: inherit;

justify-content: center;
align-items: center;
height: 100%;
padding-inline: 12px;
}

.wrapper {
Expand Down Expand Up @@ -86,3 +87,7 @@
.footerText {
font-weight: 700;
}

.message {
font-weight: 500;
}