update
This commit is contained in:
parent
5f3954ed66
commit
e3bc669118
7 changed files with 46 additions and 17 deletions
|
|
@ -15,13 +15,13 @@ import std;
|
|||
using namespace Crafter::CppDOMBindings;
|
||||
|
||||
export namespace Catcrafts {
|
||||
std::vector<HtmlElementView>* blogButtons = new std::vector<HtmlElementView>();
|
||||
std::vector<HtmlElementView> blogButtons;
|
||||
|
||||
void RenderBlog() {
|
||||
delete blogButtons;
|
||||
blogButtons = new std::vector<HtmlElementView>();
|
||||
blogButtons.clear();
|
||||
std::string html = "";
|
||||
for(const BlogPost& post : *posts) {
|
||||
for(const BlogPost& post : posts) {
|
||||
std::cout << "test" << std::endl;
|
||||
// For preview, we'll limit the content to first 200 characters
|
||||
std::string previewContent = post.content;
|
||||
if(previewContent.length() > 200) {
|
||||
|
|
@ -47,11 +47,11 @@ export namespace Catcrafts {
|
|||
</div>
|
||||
</div>)", post.slug, post.name, post.date, previewContent);
|
||||
}
|
||||
main->SetInnerHTML(html);
|
||||
main.SetInnerHTML(std::format(R"(<div class="blog-posts">{}</div>)", html));
|
||||
|
||||
for(const BlogPost& post : *posts) {
|
||||
for(const BlogPost& post : posts) {
|
||||
// Add click listener to the entire post card
|
||||
HtmlElementView& cardView = blogButtons->emplace_back(std::format("blog-post-{}", post.slug));
|
||||
HtmlElementView& cardView = blogButtons.emplace_back(std::format("blog-post-{}", post.slug));
|
||||
cardView.AddClickListener([slug = post.slug](Crafter::MouseEvent e) {
|
||||
PushState("{}", "", std::format("/blog/{}", slug));
|
||||
RenderRoot(std::format("/blog/{}", slug));
|
||||
|
|
@ -62,9 +62,9 @@ export namespace Catcrafts {
|
|||
|
||||
void RenderBlogPost(const std::string_view slug) {
|
||||
std::cout << "render "<< std::endl;
|
||||
for(const BlogPost& post : *posts) {
|
||||
for(const BlogPost& post : posts) {
|
||||
if(post.slug == slug) {
|
||||
main->SetInnerHTML(std::format(R"(
|
||||
main.SetInnerHTML(std::format(R"(
|
||||
<div class="blog-post-page">
|
||||
<div class="post-header">
|
||||
<h1 class="post-title">{}</h1>
|
||||
|
|
@ -78,6 +78,6 @@ export namespace Catcrafts {
|
|||
}
|
||||
}
|
||||
|
||||
main->SetInnerHTML("<h1>Post Not Found</h1><p>The requested blog post could not be found.</p>");
|
||||
main.SetInnerHTML("<h1>Post Not Found</h1><p>The requested blog post could not be found.</p>");
|
||||
}
|
||||
}
|
||||
|
|
@ -29,7 +29,7 @@ namespace Catcrafts {
|
|||
std::cout << postSlug << std::endl;
|
||||
RenderBlogPost(postSlug);
|
||||
} else {
|
||||
main->SetInnerHTML("<h1>Post Not Found</h1><p>The requested blog post could not be found.</p>");
|
||||
main.SetInnerHTML("<h1>Post Not Found</h1><p>The requested blog post could not be found.</p>");
|
||||
}
|
||||
} else {
|
||||
RenderBlog(); //default route
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue