Adding in functionality for Wordpress Menus, and logic to switch to Sheet when menu is too big
This commit is contained in:
@@ -15,13 +15,9 @@ import { useMediaQuery } from "react-responsive";
|
|||||||
|
|
||||||
import { Skeleton } from "../ui/skeleton";
|
import { Skeleton } from "../ui/skeleton";
|
||||||
import { Sheet, SheetContent, SheetHeader, SheetTrigger } from "../ui/sheet";
|
import { Sheet, SheetContent, SheetHeader, SheetTrigger } from "../ui/sheet";
|
||||||
import { useGetPagesQuery } from "@/services/pages";
|
|
||||||
import { cn } from "@/utils/utils";
|
import { cn } from "@/utils/utils";
|
||||||
import { Button } from "../ui/button";
|
import { Button } from "../ui/button";
|
||||||
|
import { useGetMenuQuery } from "@/services/navigation";
|
||||||
const styles = {
|
|
||||||
fontFamily: "'Ubuntu', sans-serif",
|
|
||||||
};
|
|
||||||
|
|
||||||
const ListItem = React.forwardRef<
|
const ListItem = React.forwardRef<
|
||||||
React.ElementRef<"a">,
|
React.ElementRef<"a">,
|
||||||
@@ -58,7 +54,7 @@ const Navigation = (props: any): JSX.Element => {
|
|||||||
setColorChange(false);
|
setColorChange(false);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
const { data: pages, isSuccess, isLoading } = useGetPagesQuery();
|
const { data: menu, isSuccess, isLoading } = useGetMenuQuery("primary-menu");
|
||||||
const isTabletOrMobile = useMediaQuery({ query: "(max-width: 1224px)" });
|
const isTabletOrMobile = useMediaQuery({ query: "(max-width: 1224px)" });
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
window.addEventListener("scroll", changeNavbarColor);
|
window.addEventListener("scroll", changeNavbarColor);
|
||||||
@@ -86,7 +82,7 @@ const Navigation = (props: any): JSX.Element => {
|
|||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</Link>
|
</Link>
|
||||||
{isTabletOrMobile ? (
|
{isTabletOrMobile || menu?.items.length >= 4 ? (
|
||||||
<Sheet>
|
<Sheet>
|
||||||
<SheetTrigger asChild>
|
<SheetTrigger asChild>
|
||||||
<Button className="bg-gray-700">
|
<Button className="bg-gray-700">
|
||||||
@@ -121,12 +117,15 @@ const Navigation = (props: any): JSX.Element => {
|
|||||||
>
|
>
|
||||||
Home
|
Home
|
||||||
</Link>
|
</Link>
|
||||||
<Link
|
{menu.items?.map((link: any) => (
|
||||||
href="/about"
|
<Link
|
||||||
className="p-2"
|
key={link.ID}
|
||||||
>
|
href={`/${link.slug}`}
|
||||||
About
|
className="p-2"
|
||||||
</Link>
|
>
|
||||||
|
{link.title}
|
||||||
|
</Link>
|
||||||
|
))}
|
||||||
<Link
|
<Link
|
||||||
href="/portfolio"
|
href="/portfolio"
|
||||||
className="p-2"
|
className="p-2"
|
||||||
@@ -152,14 +151,20 @@ const Navigation = (props: any): JSX.Element => {
|
|||||||
Home
|
Home
|
||||||
</Button>
|
</Button>
|
||||||
</Link>
|
</Link>
|
||||||
<Link href="/about">
|
{menu?.items.map((link: any) => (
|
||||||
<Button
|
<Link
|
||||||
variant={"ghost"}
|
key={link.ID}
|
||||||
size={"lg"}
|
href={`/${link.slug}`}
|
||||||
|
className="w-full"
|
||||||
>
|
>
|
||||||
About
|
<Button
|
||||||
</Button>
|
size={"lg"}
|
||||||
</Link>
|
variant={"ghost"}
|
||||||
|
>
|
||||||
|
{link.title}
|
||||||
|
</Button>
|
||||||
|
</Link>
|
||||||
|
))}
|
||||||
<Link href="/portfolio">
|
<Link href="/portfolio">
|
||||||
<Button
|
<Button
|
||||||
variant={"ghost"}
|
variant={"ghost"}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
/* Core */
|
/* Core */
|
||||||
|
import { menusApi } from '@/services/navigation'
|
||||||
import { pagesApi } from '@/services/pages'
|
import { pagesApi } from '@/services/pages'
|
||||||
import { portfolioApi } from '@/services/portfolio'
|
import { portfolioApi } from '@/services/portfolio'
|
||||||
import { postsApi } from '@/services/posts'
|
import { postsApi } from '@/services/posts'
|
||||||
@@ -7,6 +8,7 @@ const middleware = [
|
|||||||
postsApi.middleware,
|
postsApi.middleware,
|
||||||
pagesApi.middleware,
|
pagesApi.middleware,
|
||||||
portfolioApi.middleware,
|
portfolioApi.middleware,
|
||||||
|
menusApi.middleware,
|
||||||
]
|
]
|
||||||
|
|
||||||
export { middleware }
|
export { middleware }
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { menusApi } from "@/services/navigation";
|
||||||
import { pagesApi } from "@/services/pages";
|
import { pagesApi } from "@/services/pages";
|
||||||
import { portfolioApi } from "@/services/portfolio";
|
import { portfolioApi } from "@/services/portfolio";
|
||||||
import { postsApi } from "@/services/posts";
|
import { postsApi } from "@/services/posts";
|
||||||
@@ -6,4 +7,5 @@ export const reducer = {
|
|||||||
[postsApi.reducerPath]: postsApi.reducer,
|
[postsApi.reducerPath]: postsApi.reducer,
|
||||||
[pagesApi.reducerPath]: pagesApi.reducer,
|
[pagesApi.reducerPath]: pagesApi.reducer,
|
||||||
[portfolioApi.reducerPath]: portfolioApi.reducer,
|
[portfolioApi.reducerPath]: portfolioApi.reducer,
|
||||||
|
[menusApi.reducerPath]: menusApi.reducer,
|
||||||
};
|
};
|
||||||
@@ -33,10 +33,14 @@ export const getStaticProps = wrapper.getStaticProps(
|
|||||||
);
|
);
|
||||||
|
|
||||||
const Page = ({ page }: any) => {
|
const Page = ({ page }: any) => {
|
||||||
|
console.log(page);
|
||||||
return (
|
return (
|
||||||
<Internal>
|
<Internal>
|
||||||
<div className="container my-32">
|
<div className="container my-24 md:my-36 page-content">
|
||||||
{parser(page.content.rendered, { trim: true })}
|
<h1 className="text-4xl md:text-[64px] text-primary md:mb-6 font-sans font-bold">
|
||||||
|
{page.title.rendered}
|
||||||
|
</h1>
|
||||||
|
<div className="">{parser(page.content.rendered, { trim: true })}</div>
|
||||||
</div>
|
</div>
|
||||||
</Internal>
|
</Internal>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import { getPost, getPosts, getRunningQueriesThunk } from "@/services/posts";
|
|||||||
import { wrapper, reduxStore } from "@/lib/redux";
|
import { wrapper, reduxStore } from "@/lib/redux";
|
||||||
import Internal from "@/components/common/Internal";
|
import Internal from "@/components/common/Internal";
|
||||||
import ScrollDown from "@/components/common/scrollDown";
|
import ScrollDown from "@/components/common/scrollDown";
|
||||||
import { revalidatePath } from "next/cache";
|
|
||||||
|
|
||||||
export const getStaticPaths = async () => {
|
export const getStaticPaths = async () => {
|
||||||
const store = reduxStore();
|
const store = reduxStore();
|
||||||
|
|||||||
@@ -0,0 +1,24 @@
|
|||||||
|
import { WORDPRESS_BASE_API_MENUS } from '@/utils/common-utils';
|
||||||
|
import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react';
|
||||||
|
import { HYDRATE } from 'next-redux-wrapper';
|
||||||
|
|
||||||
|
export const menusApi: any = createApi({
|
||||||
|
reducerPath: 'menus',
|
||||||
|
baseQuery: fetchBaseQuery({ baseUrl: WORDPRESS_BASE_API_MENUS }),
|
||||||
|
extractRehydrationInfo(action, { reducerPath }) {
|
||||||
|
if(action.type === HYDRATE) {
|
||||||
|
return action.payload[reducerPath]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
tagTypes: ['Menus'],
|
||||||
|
endpoints: (builder) => ({
|
||||||
|
getMenu: builder.query({
|
||||||
|
query: (slug: string) => `/${slug}`,
|
||||||
|
providesTags: ['Menus'],
|
||||||
|
}),
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
export const { useGetMenuQuery, util: { getRunningQueriesThunk } } = menusApi;
|
||||||
|
|
||||||
|
export const { getMenu } = menusApi.endpoints;
|
||||||
@@ -60,6 +60,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
@layer utilities {
|
@layer utilities {
|
||||||
|
/* Post Content */
|
||||||
.post-content h2.wp-block-heading {
|
.post-content h2.wp-block-heading {
|
||||||
@apply text-4xl font-bold mb-4 text-primary;
|
@apply text-4xl font-bold mb-4 text-primary;
|
||||||
}
|
}
|
||||||
@@ -69,8 +70,13 @@
|
|||||||
.post-content img, video {
|
.post-content img, video {
|
||||||
@apply block w-full mb-10;
|
@apply block w-full mb-10;
|
||||||
}
|
}
|
||||||
|
/* END Post Content */
|
||||||
|
|
||||||
.post-content p {
|
.post-content p,
|
||||||
|
.page-content p {
|
||||||
@apply mb-4 text-lg text-foreground leading-8;
|
@apply mb-4 text-lg text-foreground leading-8;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Page Content */
|
||||||
|
/* END Page Content */
|
||||||
}
|
}
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
export const WORDPRESS_BASE_API = 'https://wordpress-1110286-3894329.cloudwaysapps.com/wp-json/wp/v2';
|
export const WORDPRESS_BASE_API = 'https://wordpress-1110286-3894329.cloudwaysapps.com/wp-json/wp/v2';
|
||||||
|
export const WORDPRESS_BASE_API_MENUS = 'https://wordpress-1110286-3894329.cloudwaysapps.com/wp-json/menus/v1/menus';
|
||||||
export const WORDPRESS_POSTS_FIELD_FILTERS = '?_fields=id,slug,title,_links,featured_media';
|
export const WORDPRESS_POSTS_FIELD_FILTERS = '?_fields=id,slug,title,_links,featured_media';
|
||||||
export const WORDPRESS_POST_FIELD_FILTERS = '?_fields=id,slug,title,content,date,modified';
|
export const WORDPRESS_POST_FIELD_FILTERS = '?_fields=id,slug,title,content,date,modified';
|
||||||
Reference in New Issue
Block a user