Last active
July 17, 2023 14:07
-
-
Save bm-vs/5ee065b43ea9f2ae964ac2cbc1b266c0 to your computer and use it in GitHub Desktop.
ArticleListAll RSC
This file contains hidden or 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
'use client'; | |
// imports | |
interface Props { | |
section: ArticleListAllType; | |
articlesQuery: string; | |
isDraft: boolean; | |
} | |
export const ArticleListAllDraft: FC<Props> = ({section, articlesQuery, isDraft}) => { | |
return ( | |
<PreviewSuspense fallback={<FullPageSpinner />}> | |
<Preview section={section} articlesQuery={articlesQuery} isDraft={isDraft} /> | |
</PreviewSuspense> | |
); | |
}; | |
const Preview: FC<Props> = ({section, articlesQuery, isDraft}) => { | |
const articles = usePreview(null, articlesQuery); | |
return <ArticleListAllRender section={section} articles={articles} isDraft={isDraft} />; | |
}; |
This file contains hidden or 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
// imports | |
interface Props { | |
section: ArticleListAllType; | |
isDraft: boolean; | |
} | |
export const ArticleListAll: FC<Props> = ({section, isDraft}) => { | |
return isDraft ? ( | |
<ArticleListAllDraft section={section} articlesQuery={articlesQuery} isDraft={isDraft} /> | |
) : ( | |
<ArticleListAllServer section={section} articlesQuery={articlesQuery} isDraft={isDraft} /> | |
); | |
}; | |
/** | |
* Fetches all articles | |
*/ | |
const articlesQuery = groq` | |
*[_type == "article" && defined(slug.current) && !(_id in path('drafts.**'))]{ | |
... | |
} | |
`; |
This file contains hidden or 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
// imports | |
interface Props { | |
section: ArticleListAllType; | |
articles: ArticleType[]; | |
isDraft: boolean; | |
} | |
export const ArticleListAllRender: FC<Props> = ({section, articles, isDraft}) => { | |
const {theme, title} = section; | |
return ( | |
<div | |
className={clsx( | |
'flex', | |
'items-center', | |
'justify-center', | |
'p-5', | |
)} | |
> | |
{/* render whatever */} | |
</div> | |
); | |
}; |
This file contains hidden or 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
// imports | |
interface Props { | |
section: ArticleListAllType; | |
articlesQuery: string; | |
isDraft: boolean; | |
} | |
export const ArticleListAllServer = async ({section, articlesQuery, isDraft}: Props) => { | |
const articles = await sanityFetch(articlesQuery, z.array(articleSchema)); | |
return <ArticleListAllRender section={section} articles={articles} isDraft={isDraft} />; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment