-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: improve animations & Try using image component
also refactor custom cms page into several components
- Loading branch information
1 parent
e705fcd
commit 7f8884c
Showing
13 changed files
with
154 additions
and
138 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import handleExitComplete from '@util/handleExitComplete' | ||
import { AnimatePresence } from 'framer-motion' | ||
import { FC } from 'react' | ||
|
||
interface ICustomAnimatePresenceProps { | ||
layoutShift: boolean | ||
exitFirst?: boolean | ||
} | ||
|
||
const CustomAnimatePresence: FC<ICustomAnimatePresenceProps> = (props) => { | ||
const { layoutShift, exitFirst, children } = props | ||
|
||
return ( | ||
<> | ||
<AnimatePresence | ||
exitBeforeEnter={exitFirst} | ||
onExitComplete={() => handleExitComplete()} | ||
presenceAffectsLayout={layoutShift}> | ||
{children} | ||
</AnimatePresence> | ||
</> | ||
) | ||
} | ||
|
||
export default CustomAnimatePresence |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import RenderPage from '@components/HoC/RenderPage' | ||
import PageSEO from '@components/HoC/SEO/Page' | ||
import { APIRoute } from 'cms/APIRoute' | ||
import { FC } from 'react' | ||
|
||
interface ICustomPageDefaultProps { | ||
currentRoute: APIRoute | ||
} | ||
|
||
const CustomPageDefault: FC<ICustomPageDefaultProps> = (props) => { | ||
const { currentRoute } = props | ||
|
||
return ( | ||
<> | ||
<PageSEO | ||
title={currentRoute.page.title} | ||
description={currentRoute.page.description} | ||
/> | ||
<RenderPage | ||
preview={false} | ||
loading={false} | ||
pageProps={currentRoute.page} | ||
/> | ||
</> | ||
) | ||
} | ||
|
||
export default CustomPageDefault |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import RenderPage from '@components/HoC/RenderPage' | ||
import PageSEO from '@components/HoC/SEO/Page' | ||
import { MutationEvent } from '@sanity/client' | ||
import { getClient } from '@util/api' | ||
import { APIRoute } from 'cms/APIRoute' | ||
import groq from 'groq' | ||
import { useRouter } from 'next/router' | ||
import { FC, useEffect, useState } from 'react' | ||
|
||
interface ICustomPagePreviewProps { | ||
currentRoute: APIRoute | ||
} | ||
|
||
const CustomPagePreview: FC<ICustomPagePreviewProps> = (props) => { | ||
const { currentRoute } = props | ||
|
||
const router = useRouter() | ||
const [pageData, setRouteData] = useState(currentRoute) | ||
|
||
const routeId = currentRoute?._id | ||
|
||
useEffect(() => { | ||
const sub = getClient(true) | ||
.listen(groq`*[_type == "route" && _id == $routeId][0]`, { | ||
routeId | ||
}) | ||
.subscribe( | ||
(update: MutationEvent<APIRoute>) => { | ||
const pageRes = update.result | ||
|
||
if (pageRes) setRouteData(pageRes) | ||
}, | ||
(err) => console.error(err), | ||
() => {} | ||
) | ||
|
||
return () => sub.unsubscribe() | ||
}, [routeId]) | ||
|
||
return ( | ||
<> | ||
<PageSEO | ||
title={pageData?.page?.title || 'loading'} | ||
description={pageData?.page?.description || 'loading'} | ||
/> | ||
<RenderPage | ||
preview | ||
loading={router.isFallback} | ||
pageProps={pageData?.page} | ||
/> | ||
</> | ||
) | ||
} | ||
|
||
export default CustomPagePreview |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.