-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat add a prewiev button + fix readme
- Loading branch information
Floren henri
committed
Jan 28, 2023
1 parent
a4ea74a
commit f095e7a
Showing
4 changed files
with
168 additions
and
64 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
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,45 @@ | ||
import React from 'react'; | ||
import qs from 'qs'; | ||
import { fetchCMS } from '@lib/cms'; | ||
import dynamic from 'next/dynamic'; | ||
|
||
const Reader = dynamic(() => import('@components/Story/Reader'), { | ||
ssr: false, | ||
}); | ||
export default function OneStory(props: any) { | ||
const { story } = props; | ||
return <Reader story={story} />; | ||
} | ||
|
||
export async function getServerSideProps({ query }) { | ||
try { | ||
const cmsQuery = qs.stringify( | ||
{ | ||
filters: { | ||
slug: { | ||
$eq: query.slug, | ||
}, | ||
}, | ||
populate: ['cover', 'first_page', 'nodes', 'pages.answers'], | ||
}, | ||
{ | ||
encodeValuesOnly: true, | ||
}, | ||
); | ||
const [story] = await fetchCMS( | ||
`/api/stories?${cmsQuery}&publicationState=preview`, | ||
); | ||
|
||
return { | ||
props: { | ||
story: story.attributes, | ||
}, | ||
}; | ||
} catch (error) { | ||
return { | ||
props: { | ||
story: {}, | ||
}, | ||
}; | ||
} | ||
} |