-
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
d696703
commit ca94535
Showing
16 changed files
with
144 additions
and
18 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,6 @@ | ||
--- | ||
"@headstartwp/core": minor | ||
"@headstartwp/next": minor | ||
--- | ||
|
||
Introduce `blockContext` prop to BlocksRenderer and `handleError` in query functions |
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
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,44 @@ | ||
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; | ||
|
||
try { | ||
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> | ||
</> | ||
); | ||
} catch (e) { | ||
return 'no posts found'; | ||
} | ||
}; |