-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
90bb768
commit 9234505
Showing
7 changed files
with
171 additions
and
5 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,18 @@ | ||
import { BlocksRenderer } from '@headstartwp/core/react'; | ||
import React from 'react'; | ||
import { isBlockByName } from '@headstartwp/core'; | ||
import { PostList } from './Blocks/PostList'; | ||
|
||
type BlockProps = { | ||
html: string; | ||
}; | ||
|
||
const Blocks: React.FC<BlockProps> = ({ html }) => { | ||
return ( | ||
<BlocksRenderer forwardBlockAttributes html={html}> | ||
<PostList test={(node) => isBlockByName(node, 'core/query')} /> | ||
</BlocksRenderer> | ||
); | ||
}; | ||
|
||
export default Blocks; |
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,40 @@ | ||
import { BlockProps } from '@headstartwp/core/react'; | ||
import { queryPosts } from '@headstartwp/next/app'; | ||
|
||
interface PostListProps | ||
extends BlockProps<{ queryId: number; query: { perPage: number; postType: string } }> {} | ||
|
||
export const PostList: React.FC<PostListProps> = async ({ block }) => { | ||
if (!block) { | ||
return null; | ||
} | ||
|
||
const { query } = block.attributes; | ||
|
||
const { | ||
data: { posts }, | ||
} = await queryPosts({ | ||
// todo: map the rest of the query object | ||
params: { per_page: query.perPage, postType: query.postType }, | ||
// setting handle error to false will disable automatic handling of errors | ||
// i.e you have to handle the error yourself | ||
handleError: false, | ||
}); | ||
|
||
return ( | ||
<> | ||
<h2>Post List</h2> | ||
<pre> | ||
<code>{JSON.stringify({ query }, null, 2)}</code> | ||
</pre> | ||
|
||
<ul> | ||
{posts.map((post) => ( | ||
<li key={post.id}> | ||
#{post.id} -{post.title.rendered} | ||
</li> | ||
))} | ||
</ul> | ||
</> | ||
); | ||
}; |