From 90f2cc2c0c85873f2590dcd5f544985e01b83b25 Mon Sep 17 00:00:00 2001 From: Aaron William Po Date: Tue, 11 Apr 2023 22:18:29 -0400 Subject: [PATCH] Begin work on tab components for beer by id page --- .../BeerById/BeerPostCommentsSection.tsx | 2 +- hooks/useMediaQuery.ts | 19 +++++++++ package-lock.json | 42 +++++++++++++++++++ package.json | 2 + pages/beers/[id]/index.tsx | 38 ++++++++++++++--- tailwind.config.js | 6 ++- 6 files changed, 102 insertions(+), 7 deletions(-) create mode 100644 hooks/useMediaQuery.ts diff --git a/components/BeerById/BeerPostCommentsSection.tsx b/components/BeerById/BeerPostCommentsSection.tsx index 8d67709..fa0bd32 100644 --- a/components/BeerById/BeerPostCommentsSection.tsx +++ b/components/BeerById/BeerPostCommentsSection.tsx @@ -46,7 +46,7 @@ const BeerPostCommentsSection: FC = ({ beerPost }) const sectionRef: MutableRefObject = useRef(null); return ( -
+
{user ? ( diff --git a/hooks/useMediaQuery.ts b/hooks/useMediaQuery.ts new file mode 100644 index 0000000..240629e --- /dev/null +++ b/hooks/useMediaQuery.ts @@ -0,0 +1,19 @@ +import { useState, useEffect } from 'react'; + +const useMediaQuery = (query: string) => { + const [matches, setMatches] = useState(false); + + useEffect(() => { + const media = window.matchMedia(query); + if (media.matches !== matches) { + setMatches(media.matches); + } + const listener = () => setMatches(media.matches); + window.addEventListener('resize', listener); + return () => window.removeEventListener('resize', listener); + }, [matches, query]); + + return matches; +}; + +export default useMediaQuery; diff --git a/package-lock.json b/package-lock.json index 479d77f..79eb09d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,6 +9,8 @@ "version": "0.1.0", "dependencies": { "@hapi/iron": "^7.0.1", + "@headlessui/react": "^1.7.13", + "@headlessui/tailwindcss": "^0.1.2", "@hookform/resolvers": "^3.0.0", "@prisma/client": "^4.12.0", "@react-email/components": "^0.0.4", @@ -649,6 +651,32 @@ "@hapi/hoek": "^11.0.2" } }, + "node_modules/@headlessui/react": { + "version": "1.7.13", + "resolved": "https://registry.npmjs.org/@headlessui/react/-/react-1.7.13.tgz", + "integrity": "sha512-9n+EQKRtD9266xIHXdY5MfiXPDfYwl7zBM7KOx2Ae3Gdgxy8QML1FkCMjq6AsOf0l6N9uvI4HcFtuFlenaldKg==", + "dependencies": { + "client-only": "^0.0.1" + }, + "engines": { + "node": ">=10" + }, + "peerDependencies": { + "react": "^16 || ^17 || ^18", + "react-dom": "^16 || ^17 || ^18" + } + }, + "node_modules/@headlessui/tailwindcss": { + "version": "0.1.2", + "resolved": "https://registry.npmjs.org/@headlessui/tailwindcss/-/tailwindcss-0.1.2.tgz", + "integrity": "sha512-AQNESz+f1grCxifrocOE6hDMDFqhqY0g3xrSGOS0ocGkmVkssaBzXaAPAPNSs/nHmr4ZUhfl5THQpYrvaouWlQ==", + "engines": { + "node": ">=10" + }, + "peerDependencies": { + "tailwindcss": "^3.0" + } + }, "node_modules/@hookform/resolvers": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/@hookform/resolvers/-/resolvers-3.0.0.tgz", @@ -10691,6 +10719,20 @@ "@hapi/hoek": "^11.0.2" } }, + "@headlessui/react": { + "version": "1.7.13", + "resolved": "https://registry.npmjs.org/@headlessui/react/-/react-1.7.13.tgz", + "integrity": "sha512-9n+EQKRtD9266xIHXdY5MfiXPDfYwl7zBM7KOx2Ae3Gdgxy8QML1FkCMjq6AsOf0l6N9uvI4HcFtuFlenaldKg==", + "requires": { + "client-only": "^0.0.1" + } + }, + "@headlessui/tailwindcss": { + "version": "0.1.2", + "resolved": "https://registry.npmjs.org/@headlessui/tailwindcss/-/tailwindcss-0.1.2.tgz", + "integrity": "sha512-AQNESz+f1grCxifrocOE6hDMDFqhqY0g3xrSGOS0ocGkmVkssaBzXaAPAPNSs/nHmr4ZUhfl5THQpYrvaouWlQ==", + "requires": {} + }, "@hookform/resolvers": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/@hookform/resolvers/-/resolvers-3.0.0.tgz", diff --git a/package.json b/package.json index 24e8223..754ac8d 100644 --- a/package.json +++ b/package.json @@ -12,6 +12,8 @@ }, "dependencies": { "@hapi/iron": "^7.0.1", + "@headlessui/react": "^1.7.13", + "@headlessui/tailwindcss": "^0.1.2", "@hookform/resolvers": "^3.0.0", "@prisma/client": "^4.12.0", "@react-email/components": "^0.0.4", diff --git a/pages/beers/[id]/index.tsx b/pages/beers/[id]/index.tsx index 0c914c2..f4d4d81 100644 --- a/pages/beers/[id]/index.tsx +++ b/pages/beers/[id]/index.tsx @@ -17,6 +17,8 @@ import { z } from 'zod'; import 'react-responsive-carousel/lib/styles/carousel.min.css'; // requires a loader import { Carousel } from 'react-responsive-carousel'; +import useMediaQuery from '@/hooks/useMediaQuery'; +import { Tab } from '@headlessui/react'; interface BeerPageProps { beerPost: z.infer; @@ -27,6 +29,8 @@ interface BeerPageProps { } const BeerByIdPage: NextPage = ({ beerPost, beerRecommendations }) => { + const isMd = useMediaQuery('(min-width: 768px)'); + return ( <> @@ -59,12 +63,36 @@ const BeerByIdPage: NextPage = ({ beerPost, beerRecommendations }
-
- -
- + + {isMd ? ( +
+
+ +
+
+ +
-
+ ) : ( + + + + Comments + + + Recommendations + + + + + + + + + + + + )}
diff --git a/tailwind.config.js b/tailwind.config.js index f26ad62..ae86c8a 100644 --- a/tailwind.config.js +++ b/tailwind.config.js @@ -48,7 +48,11 @@ module.exports = { theme: { extend: {}, }, - plugins: [require('daisyui'), require('tailwindcss-animate')], + plugins: [ + require('@headlessui/tailwindcss'), + require('daisyui'), + require('tailwindcss-animate'), + ], daisyui: { logs: false,