drfeely.com/website/app/(pages)/articles/(content)/layout.tsx

54 lines
1.8 KiB
TypeScript
Raw Normal View History

2023-08-29 04:50:52 +00:00
"use client";
2023-08-30 22:56:17 +00:00
import GenericButton from "@/components/GenericButton";
2023-08-29 04:50:52 +00:00
import { ArrowLongLeftIcon, ArrowSmallUpIcon } from "@heroicons/react/24/solid";
2023-08-26 02:18:11 +00:00
import Link from "next/link";
2023-08-29 04:50:52 +00:00
import { ReactNode, useEffect, useState } from "react";
2023-08-26 02:18:11 +00:00
interface Props {
children: ReactNode;
}
const ArticlesLayout = ({ children }: Props) => {
2023-08-29 04:50:52 +00:00
const [isTopOfPage, setIsTopOfPage] = useState(true);
useEffect(() => {
const handleScroll = () => {
if (window.scrollY <= 500) {
setIsTopOfPage(true);
} else {
setIsTopOfPage(false);
}
};
window.addEventListener("scroll", handleScroll);
return () => window.removeEventListener("scroll", handleScroll);
}, []);
2023-08-26 02:18:11 +00:00
return (
<div className="mx-auto mt-20 w-11/12 md:w-2/5">
<Link href="/articles" className="my-5 block font-bold">
<ArrowLongLeftIcon className="inline w-[24px] "></ArrowLongLeftIcon>{" "}
2023-08-30 22:56:17 +00:00
View all Articles
2023-08-26 02:18:11 +00:00
</Link>
{children}
<Link href="/articles" className="my-5 block font-bold">
<ArrowLongLeftIcon className="inline w-[24px] "></ArrowLongLeftIcon>{" "}
2023-08-30 22:56:17 +00:00
View all Articles
2023-08-26 02:18:11 +00:00
</Link>
2023-08-30 22:56:17 +00:00
{/* For some reason if I use a <Link> here it doesn't scroll all the way to the top of the page. */}
2023-08-29 04:50:52 +00:00
{isTopOfPage ? (
<></>
) : (
2023-08-31 03:18:58 +00:00
<button
onClick={() => window.scrollTo(0, 0)}
className="fixed bottom-0 right-0 m-3 mb-5 mr-5 flex flex-col items-center rounded-lg bg-primary-100 p-3 align-middle drop-shadow-md transition-all duration-300 hover:drop-shadow-xl md:right-1/4 md:mr-[-4rem]"
2023-08-29 04:50:52 +00:00
>
<ArrowSmallUpIcon className="w-[24px]"></ArrowSmallUpIcon>
<div className="text-sm italic">To Top</div>
2023-08-31 03:18:58 +00:00
</button>
2023-08-29 04:50:52 +00:00
)}
2023-08-26 02:18:11 +00:00
</div>
);
};
export default ArticlesLayout;