[{"data":1,"prerenderedAt":8234},["ShallowReactive",2],{"series-\u002Fseries\u002Fempower-and-dynamize-our-vitepress-blog-with-a-laravel-api\u002Fsimplifying-comment-querying-and-editing-with-pinia-colada":3,"series-context-\u002Fseries\u002Fempower-and-dynamize-our-vitepress-blog-with-a-laravel-api":8019},{"id":4,"title":5,"body":6,"contentId":8006,"date":8007,"description":8008,"extension":8009,"github":8010,"meetTheInstructor":8010,"meta":8011,"navigation":22,"part":214,"path":8012,"rawbody":8013,"robots":8010,"schemaOrg":8010,"seo":8014,"seriesSlug":8015,"sitemap":8016,"stem":8017,"subtitle":8010,"topics":8010,"__hash__":8018},"series\u002Fseries\u002Fempower-and-dynamize-our-vitepress-blog-with-a-laravel-api\u002Fsimplifying-comment-querying-and-editing-with-pinia-colada.md","Simplifying Comment Querying and Editing with Pinia Colada",{"type":7,"value":8,"toc":7998},"minimark",[9,13,16,19,33,38,46,73,80,364,367,399,418,425,428,502,506,513,665,675,678,685,697,726,742,754,809,814,835,909,911,916,922,944,949,1534,1541,1955,1961,2431,2441,2603,2606,2609,2613,2620,2627,2630,2842,2845,3162,3165,3168,3173,3176,3238,3243,3246,4027,4034,4548,4555,4564,4656,4660,4663,4670,4673,4680,4683,4720,4723,4733,4803,4806,4946,4953,4959,5067,5157,5240,5245,5253,5348,5355,5613,5616,5622,5628,5917,5923,7228,7242,7252,7256,7263,7717,7720,7723,7729,7963,7967,7970,7973,7976,7988,7991,7994],[10,11,12],"p",{},"With authentication and the API connection in place, we can now bring the comment system to the frontend.",[10,14,15],{},"The backend already knows how to list, create, update, and delete comments. Our task is to expose those operations through a clear set of API functions, Pinia Colada queries and mutations, and small Vue components.",[10,17,18],{},"There are several moving parts, but each one follows patterns introduced earlier in the series. By the end of this article, the blog will be able to display, create, edit, and delete comments.",[20,21,23,24,23,29],"video",{"autoPlay":22,"loop":22,"muted":22,"playsInline":22},true,"\n  ",[25,26],"source",{"src":27,"type":28},"https:\u002F\u002Fimages.soubiran.dev\u002Fseries\u002Fempower-and-dynamize-our-vitepress-blog-with-a-laravel-api\u002Fsimplifying-comment-querying-and-editing-with-pinia-colada\u002Fdemo.mp4","video\u002Fmp4",[30,31,32],"figcaption",{},"\n    Here is the finished comment system we will build in this article.\n  ",[34,35,37],"h2",{"id":36},"the-basics","The basics",[10,39,40,41,45],{},"The comment system is a new frontend feature, so we will create a folder in ",[42,43,44],"code",{},".vitepress\u002Ftheme"," for its components, queries, mutations, and API calls.",[47,48,54],"pre",{"className":49,"code":50,"filename":51,"language":52,"meta":53,"style":53},"language-bash shiki shiki-themes github-light github-light github-dark","mkdir -p .vitepress\u002Ftheme\u002Fcomments\n","terminal","bash","",[42,55,56],{"__ignoreMap":53},[57,58,61,65,69],"span",{"class":59,"line":60},"line",1,[57,62,64],{"class":63},"snPdu","mkdir",[57,66,68],{"class":67},"sBjJW"," -p",[57,70,72],{"class":71},"sIIMD"," .vitepress\u002Ftheme\u002Fcomments\n",[10,74,75,76,79],{},"As with the user feature, put the API calls in an ",[42,77,78],{},"api.ts"," file:",[47,81,86],{"className":82,"code":83,"filename":84,"language":85,"meta":53,"style":53},"language-ts shiki shiki-themes github-light github-light github-dark","export function fetchComments(postId: number) {\n  return api(`api\u002Fposts\u002F${postId}\u002Fcomments`)\n}\n\nexport function postComment(postId: number, content: string) {\n  return api(`api\u002Fposts\u002F${postId}\u002Fcomments`, {\n    method: 'POST',\n    body: { content },\n  })\n}\n\nexport function putComment(commentId: number, content: string) {\n  return api(`api\u002Fcomments\u002F${commentId}`, {\n    method: 'PUT',\n    body: { content },\n  })\n}\nexport function deleteComment(commentId: number) {\n  return api(`api\u002Fcomments\u002F${commentId}`, {\n    method: 'DELETE',\n  })\n}\n",".vitepress\u002Ftheme\u002Fcomments\u002Fapi.ts","ts",[42,87,88,117,139,145,151,182,200,212,218,224,229,234,263,282,292,297,302,307,327,344,354,359],{"__ignoreMap":53},[57,89,90,94,97,100,104,108,111,114],{"class":59,"line":60},[57,91,93],{"class":92},"s8jYJ","export",[57,95,96],{"class":92}," function",[57,98,99],{"class":63}," fetchComments",[57,101,103],{"class":102},"sxrX7","(",[57,105,107],{"class":106},"sP4rz","postId",[57,109,110],{"class":92},":",[57,112,113],{"class":67}," number",[57,115,116],{"class":102},") {\n",[57,118,120,123,126,128,131,133,136],{"class":59,"line":119},2,[57,121,122],{"class":92},"  return",[57,124,125],{"class":63}," api",[57,127,103],{"class":102},[57,129,130],{"class":71},"`api\u002Fposts\u002F${",[57,132,107],{"class":102},[57,134,135],{"class":71},"}\u002Fcomments`",[57,137,138],{"class":102},")\n",[57,140,142],{"class":59,"line":141},3,[57,143,144],{"class":102},"}\n",[57,146,148],{"class":59,"line":147},4,[57,149,150],{"emptyLinePlaceholder":22},"\n",[57,152,154,156,158,161,163,165,167,169,172,175,177,180],{"class":59,"line":153},5,[57,155,93],{"class":92},[57,157,96],{"class":92},[57,159,160],{"class":63}," postComment",[57,162,103],{"class":102},[57,164,107],{"class":106},[57,166,110],{"class":92},[57,168,113],{"class":67},[57,170,171],{"class":102},", ",[57,173,174],{"class":106},"content",[57,176,110],{"class":92},[57,178,179],{"class":67}," string",[57,181,116],{"class":102},[57,183,185,187,189,191,193,195,197],{"class":59,"line":184},6,[57,186,122],{"class":92},[57,188,125],{"class":63},[57,190,103],{"class":102},[57,192,130],{"class":71},[57,194,107],{"class":102},[57,196,135],{"class":71},[57,198,199],{"class":102},", {\n",[57,201,203,206,209],{"class":59,"line":202},7,[57,204,205],{"class":102},"    method: ",[57,207,208],{"class":71},"'POST'",[57,210,211],{"class":102},",\n",[57,213,215],{"class":59,"line":214},8,[57,216,217],{"class":102},"    body: { content },\n",[57,219,221],{"class":59,"line":220},9,[57,222,223],{"class":102},"  })\n",[57,225,227],{"class":59,"line":226},10,[57,228,144],{"class":102},[57,230,232],{"class":59,"line":231},11,[57,233,150],{"emptyLinePlaceholder":22},[57,235,237,239,241,244,246,249,251,253,255,257,259,261],{"class":59,"line":236},12,[57,238,93],{"class":92},[57,240,96],{"class":92},[57,242,243],{"class":63}," putComment",[57,245,103],{"class":102},[57,247,248],{"class":106},"commentId",[57,250,110],{"class":92},[57,252,113],{"class":67},[57,254,171],{"class":102},[57,256,174],{"class":106},[57,258,110],{"class":92},[57,260,179],{"class":67},[57,262,116],{"class":102},[57,264,266,268,270,272,275,277,280],{"class":59,"line":265},13,[57,267,122],{"class":92},[57,269,125],{"class":63},[57,271,103],{"class":102},[57,273,274],{"class":71},"`api\u002Fcomments\u002F${",[57,276,248],{"class":102},[57,278,279],{"class":71},"}`",[57,281,199],{"class":102},[57,283,285,287,290],{"class":59,"line":284},14,[57,286,205],{"class":102},[57,288,289],{"class":71},"'PUT'",[57,291,211],{"class":102},[57,293,295],{"class":59,"line":294},15,[57,296,217],{"class":102},[57,298,300],{"class":59,"line":299},16,[57,301,223],{"class":102},[57,303,305],{"class":59,"line":304},17,[57,306,144],{"class":102},[57,308,310,312,314,317,319,321,323,325],{"class":59,"line":309},18,[57,311,93],{"class":92},[57,313,96],{"class":92},[57,315,316],{"class":63}," deleteComment",[57,318,103],{"class":102},[57,320,248],{"class":106},[57,322,110],{"class":92},[57,324,113],{"class":67},[57,326,116],{"class":102},[57,328,330,332,334,336,338,340,342],{"class":59,"line":329},19,[57,331,122],{"class":92},[57,333,125],{"class":63},[57,335,103],{"class":102},[57,337,274],{"class":71},[57,339,248],{"class":102},[57,341,279],{"class":71},[57,343,199],{"class":102},[57,345,347,349,352],{"class":59,"line":346},20,[57,348,205],{"class":102},[57,350,351],{"class":71},"'DELETE'",[57,353,211],{"class":102},[57,355,357],{"class":59,"line":356},21,[57,358,223],{"class":102},[57,360,362],{"class":59,"line":361},22,[57,363,144],{"class":102},[10,365,366],{},"These four functions map to the four Laravel endpoints:",[47,368,373],{"className":369,"code":370,"filename":371,"language":372,"meta":53,"style":53},"language-php shiki shiki-themes github-light github-light github-dark","Route::get('\u002Fposts\u002F{post}\u002Fcomments', [PostCommentController::class, 'index']);\nRoute::post('\u002Fposts\u002F{post}\u002Fcomments', [PostCommentController::class, 'store']);\n\nRoute::put('\u002Fcomments\u002F{comment}', [CommentController::class, 'update']);\nRoute::delete('\u002Fcomments\u002F{comment}', [CommentController::class, 'destroy']);\n","routes\u002Fapi.php","php",[42,374,375,380,385,389,394],{"__ignoreMap":53},[57,376,377],{"class":59,"line":60},[57,378,379],{},"Route::get('\u002Fposts\u002F{post}\u002Fcomments', [PostCommentController::class, 'index']);\n",[57,381,382],{"class":59,"line":119},[57,383,384],{},"Route::post('\u002Fposts\u002F{post}\u002Fcomments', [PostCommentController::class, 'store']);\n",[57,386,387],{"class":59,"line":141},[57,388,150],{"emptyLinePlaceholder":22},[57,390,391],{"class":59,"line":147},[57,392,393],{},"Route::put('\u002Fcomments\u002F{comment}', [CommentController::class, 'update']);\n",[57,395,396],{"class":59,"line":153},[57,397,398],{},"Route::delete('\u002Fcomments\u002F{comment}', [CommentController::class, 'destroy']);\n",[10,400,401,402,405,406,409,410,413,414,417],{},"The first function retrieves a post's comments with ",[42,403,404],{},"GET",", the second creates a comment with ",[42,407,408],{},"POST",", the third updates a comment with ",[42,411,412],{},"PUT",", and the last deletes one with ",[42,415,416],{},"DELETE",".",[10,419,420,421,424],{},"As explained in the previous article, query functions start with ",[42,422,423],{},"fetch",", while mutation functions start with the HTTP verb. This naming convention makes their purpose clear.",[10,426,427],{},"Define the comment type next. It mirrors the resource returned by the Laravel API.",[47,429,432],{"className":82,"code":430,"filename":431,"language":85,"meta":53,"style":53},"import type { User } from '@\u002Fuser\u002Ftypes\u002Fuser'\n\nexport interface Comment {\n  id: number\n  content: string\n  author: User\n}\n",".vitepress\u002Ftheme\u002Fcomments\u002Ftypes\u002Fcomment.ts",[42,433,434,451,455,468,478,488,498],{"__ignoreMap":53},[57,435,436,439,442,445,448],{"class":59,"line":60},[57,437,438],{"class":92},"import",[57,440,441],{"class":92}," type",[57,443,444],{"class":102}," { User } ",[57,446,447],{"class":92},"from",[57,449,450],{"class":71}," '@\u002Fuser\u002Ftypes\u002Fuser'\n",[57,452,453],{"class":59,"line":119},[57,454,150],{"emptyLinePlaceholder":22},[57,456,457,459,462,465],{"class":59,"line":141},[57,458,93],{"class":92},[57,460,461],{"class":92}," interface",[57,463,464],{"class":63}," Comment",[57,466,467],{"class":102}," {\n",[57,469,470,473,475],{"class":59,"line":147},[57,471,472],{"class":106},"  id",[57,474,110],{"class":92},[57,476,477],{"class":67}," number\n",[57,479,480,483,485],{"class":59,"line":153},[57,481,482],{"class":106},"  content",[57,484,110],{"class":92},[57,486,487],{"class":67}," string\n",[57,489,490,493,495],{"class":59,"line":184},[57,491,492],{"class":106},"  author",[57,494,110],{"class":92},[57,496,497],{"class":63}," User\n",[57,499,500],{"class":59,"line":202},[57,501,144],{"class":102},[34,503,505],{"id":504},"showing-comments","Showing comments",[10,507,508,509,512],{},"With the API functions and type in place, create a query that retrieves the comments for the current post. We will use it in ",[42,510,511],{},"BlogShow.vue"," to display them.",[47,514,517],{"className":82,"code":515,"filename":516,"language":85,"meta":53,"style":53},"export const useComments = defineQuery(() => {\n  const { frontmatter } = useData()\n\n  return useQuery\u003CComment[]>({\n    key: () => ['comments', frontmatter.value.id],\n    query: () =>\n      fetchComments(frontmatter.value.id).then(response => response.data),\n    enabled: typeof document !== 'undefined',\n  })\n})\n",".vitepress\u002Ftheme\u002Fcomments\u002Fqueries.ts",[42,518,519,543,566,570,586,605,615,637,656,660],{"__ignoreMap":53},[57,520,521,523,526,529,532,535,538,541],{"class":59,"line":60},[57,522,93],{"class":92},[57,524,525],{"class":92}," const",[57,527,528],{"class":67}," useComments",[57,530,531],{"class":92}," =",[57,533,534],{"class":63}," defineQuery",[57,536,537],{"class":102},"(() ",[57,539,540],{"class":92},"=>",[57,542,467],{"class":102},[57,544,545,548,551,554,557,560,563],{"class":59,"line":119},[57,546,547],{"class":92},"  const",[57,549,550],{"class":102}," { ",[57,552,553],{"class":67},"frontmatter",[57,555,556],{"class":102}," } ",[57,558,559],{"class":92},"=",[57,561,562],{"class":63}," useData",[57,564,565],{"class":102},"()\n",[57,567,568],{"class":59,"line":141},[57,569,150],{"emptyLinePlaceholder":22},[57,571,572,574,577,580,583],{"class":59,"line":147},[57,573,122],{"class":92},[57,575,576],{"class":63}," useQuery",[57,578,579],{"class":102},"\u003C",[57,581,582],{"class":63},"Comment",[57,584,585],{"class":102},"[]>({\n",[57,587,588,591,594,596,599,602],{"class":59,"line":153},[57,589,590],{"class":63},"    key",[57,592,593],{"class":102},": () ",[57,595,540],{"class":92},[57,597,598],{"class":102}," [",[57,600,601],{"class":71},"'comments'",[57,603,604],{"class":102},", frontmatter.value.id],\n",[57,606,607,610,612],{"class":59,"line":184},[57,608,609],{"class":63},"    query",[57,611,593],{"class":102},[57,613,614],{"class":92},"=>\n",[57,616,617,620,623,626,628,631,634],{"class":59,"line":202},[57,618,619],{"class":63},"      fetchComments",[57,621,622],{"class":102},"(frontmatter.value.id).",[57,624,625],{"class":63},"then",[57,627,103],{"class":102},[57,629,630],{"class":106},"response",[57,632,633],{"class":92}," =>",[57,635,636],{"class":102}," response.data),\n",[57,638,639,642,645,648,651,654],{"class":59,"line":214},[57,640,641],{"class":102},"    enabled: ",[57,643,644],{"class":92},"typeof",[57,646,647],{"class":102}," document ",[57,649,650],{"class":92},"!==",[57,652,653],{"class":71}," 'undefined'",[57,655,211],{"class":102},[57,657,658],{"class":59,"line":220},[57,659,223],{"class":102},[57,661,662],{"class":59,"line":226},[57,663,664],{"class":102},"})\n",[10,666,667,670,671,674],{},[42,668,669],{},"defineQuery"," creates a composable that runs in the Vue context. That lets us use ",[42,672,673],{},"useData"," to read the current page's frontmatter and request comments for only that post.",[676,677],"hr",{},[10,679,680,681,684],{},"In the automation article, we added an ",[42,682,683],{},"id"," property to each post's frontmatter. This unique value connects the frontend post to its backend record, so we can request comments with it.",[686,687,688],"blockquote",{},[10,689,690,691,693,694,417],{},"The frontend calls this value ",[42,692,683],{},", while the database calls it ",[42,695,696],{},"meta_id",[10,698,699,700,171,703,706,707,709,710,712,713,716,717,719,720,722,723,725],{},"When the frontend requests ",[42,701,702],{},"\u002Fapi\u002Fposts\u002F2\u002Fcomments",[42,704,705],{},"2"," refers to ",[42,708,696],{},", not the database's internal ",[42,711,683],{},". If the database record with internal ID ",[42,714,715],{},"1"," has ",[42,718,696],{}," ",[42,721,705],{},", default route model binding would look for internal ID ",[42,724,705],{}," instead. That would return the wrong post or no post at all.",[727,728,731],"callout",{"color":729,"icon":730},"info","i-ph-info-duotone",[10,732,733,734,737,738,741],{},"Route model binding lets Laravel inject the model matching a route parameter. For ",[42,735,736],{},"\u002Fposts\u002F{post}",", Laravel uses the parameter name and the controller argument type to determine which ",[42,739,740],{},"Post"," record to retrieve.",[10,743,744,745,747,748,750,751,753],{},"To correct this, we need to customize the route key name in the ",[42,746,740],{}," model. This way, we can tell Laravel to use the ",[42,749,696],{}," column instead of the default ",[42,752,683],{}," column.",[47,755,758],{"className":369,"code":756,"filename":757,"language":372,"meta":53,"style":53},"final class Post extends Model\n{\n    \u002F**\n     * Get the route key for the model.\n     *\u002F\n    public function getRouteKeyName(): string\n    {\n        return 'meta_id';\n    }\n}\n","app\u002FModels\u002FPost.php",[42,759,760,765,770,775,780,785,790,795,800,805],{"__ignoreMap":53},[57,761,762],{"class":59,"line":60},[57,763,764],{},"final class Post extends Model\n",[57,766,767],{"class":59,"line":119},[57,768,769],{},"{\n",[57,771,772],{"class":59,"line":141},[57,773,774],{},"    \u002F**\n",[57,776,777],{"class":59,"line":147},[57,778,779],{},"     * Get the route key for the model.\n",[57,781,782],{"class":59,"line":153},[57,783,784],{},"     *\u002F\n",[57,786,787],{"class":59,"line":184},[57,788,789],{},"    public function getRouteKeyName(): string\n",[57,791,792],{"class":59,"line":202},[57,793,794],{},"    {\n",[57,796,797],{"class":59,"line":214},[57,798,799],{},"        return 'meta_id';\n",[57,801,802],{"class":59,"line":220},[57,803,804],{},"    }\n",[57,806,807],{"class":59,"line":226},[57,808,144],{},[10,810,811,812,110],{},"Add two tests to ensure that posts are always retrieved by ",[42,813,696],{},[47,815,818],{"className":369,"code":816,"filename":817,"language":372,"meta":53,"style":53},"test('route key name', function () {\n    expect((new Post())->getRouteKeyName())->toBe('meta_id');\n});\n","tests\u002FUnit\u002FModels\u002FPostTest.php",[42,819,820,825,830],{"__ignoreMap":53},[57,821,822],{"class":59,"line":60},[57,823,824],{},"test('route key name', function () {\n",[57,826,827],{"class":59,"line":119},[57,828,829],{},"    expect((new Post())->getRouteKeyName())->toBe('meta_id');\n",[57,831,832],{"class":59,"line":141},[57,833,834],{},"});\n",[47,836,839],{"className":369,"code":837,"filename":838,"language":372,"meta":53,"style":53},"it('returns comments by using the post meta id', function () {\n    Comment::factory()\n        ->for(Post::factory()->create(['id' => 1, 'meta_id' => 5]))\n        ->create();\n\n    $this->getJson(route('posts.comments', ['post' => 5]))\n        ->assertJson(\n            fn (AssertableJson $json) => $json\n                ->has(\n                    'data',\n                    1,\n                )\n        );\n});\n","tests\u002FHttp\u002FApi\u002FPost\u002FComment\u002FIndexTest.php",[42,840,841,846,851,856,861,865,870,875,880,885,890,895,900,905],{"__ignoreMap":53},[57,842,843],{"class":59,"line":60},[57,844,845],{},"it('returns comments by using the post meta id', function () {\n",[57,847,848],{"class":59,"line":119},[57,849,850],{},"    Comment::factory()\n",[57,852,853],{"class":59,"line":141},[57,854,855],{},"        ->for(Post::factory()->create(['id' => 1, 'meta_id' => 5]))\n",[57,857,858],{"class":59,"line":147},[57,859,860],{},"        ->create();\n",[57,862,863],{"class":59,"line":153},[57,864,150],{"emptyLinePlaceholder":22},[57,866,867],{"class":59,"line":184},[57,868,869],{},"    $this->getJson(route('posts.comments', ['post' => 5]))\n",[57,871,872],{"class":59,"line":202},[57,873,874],{},"        ->assertJson(\n",[57,876,877],{"class":59,"line":214},[57,878,879],{},"            fn (AssertableJson $json) => $json\n",[57,881,882],{"class":59,"line":220},[57,883,884],{},"                ->has(\n",[57,886,887],{"class":59,"line":226},[57,888,889],{},"                    'data',\n",[57,891,892],{"class":59,"line":231},[57,893,894],{},"                    1,\n",[57,896,897],{"class":59,"line":236},[57,898,899],{},"                )\n",[57,901,902],{"class":59,"line":265},[57,903,904],{},"        );\n",[57,906,907],{"class":59,"line":284},[57,908,834],{},[676,910],{},[10,912,913,914,417],{},"Now that the query uses the correct post, display the comments in ",[42,915,511],{},[10,917,918,919,110],{},"Create three components in ",[42,920,921],{},".vitepress\u002Ftheme\u002Fcomments\u002Fcomponents",[923,924,925,932,938],"ol",{},[926,927,928,931],"li",{},[42,929,930],{},"Comment.vue",": Displays one comment.",[926,933,934,937],{},[42,935,936],{},"CommentList.vue",": Displays a list of comments.",[926,939,940,943],{},[42,941,942],{},"CommentSection.vue",": Displays the comment section and its list.",[10,945,946,948],{},[42,947,930],{}," is a presentational component. It receives a comment through its props and displays it.",[47,950,955],{"className":951,"code":952,"filename":953,"language":954,"meta":53,"style":53},"language-vue shiki shiki-themes github-light github-light github-dark","\u003Cscript lang=\"ts\">\nimport type { Comment } from '@\u002Fcomments\u002Ftypes\u002Fcomment'\n\nconst blogComment = tv({\n  slots: {\n    base: 'space-y-4',\n    content: '',\n    author: 'flex items-center gap-2 font-semibold',\n    authorAvatar: 'size-8 rounded-full',\n  },\n})\n\nexport interface BlogCommentProps {\n  comment: Comment\n  class?: any\n  ui?: Partial\u003Ctypeof blogComment.slots>\n}\nexport interface BlogCommentEmits {}\nexport interface BlogCommentSlots {}\n\u003C\u002Fscript>\n\n\u003Cscript lang=\"ts\" setup>\nconst props = defineProps\u003CBlogCommentProps>()\ndefineEmits\u003CBlogCommentEmits>()\ndefineSlots\u003CBlogCommentSlots>()\n\nconst { mutate: deleteComment } = useDeleteComment()\n\nconst update = ref(false)\n\nconst ui = computed(() => blogComment())\n\u003C\u002Fscript>\n\n\u003Ctemplate>\n  \u003Carticle :class=\"ui.base({ class: [props.class, props.ui?.base] })\">\n    \u003Cp>\n      {{ props.comment.content }}\n    \u003C\u002Fp>\n\n    \u003Cdiv :class=\"ui.author({ class: props.ui?.author })\">\n      \u003Cimg\n        v-if=\"props.comment.author.avatar\"\n        :src=\"props.comment.author.avatar\"\n        :class=\"ui.authorAvatar({ class: props.ui?.authorAvatar })\"\n      >\n      \u003Ctemplate v-if=\"props.comment.author.name\">\n        {{ props.comment.author.name }} ({{ props.comment.author.username }})\n      \u003C\u002Ftemplate>\n      \u003Ctemplate v-else>\n        {{ props.comment.author.username }}\n      \u003C\u002Ftemplate>\n    \u003C\u002Fdiv>\n  \u003C\u002Farticle>\n\u003C\u002Ftemplate>\n",".vitepress\u002Ftheme\u002Fcomments\u002Fcomponents\u002FComment.vue","vue",[42,956,957,976,990,994,1010,1015,1025,1035,1045,1055,1060,1064,1068,1079,1089,1100,1117,1121,1133,1144,1153,1157,1174,1195,1208,1221,1226,1251,1256,1276,1281,1303,1312,1317,1327,1346,1356,1362,1372,1377,1394,1403,1414,1424,1435,1441,1463,1469,1479,1491,1497,1506,1515,1525],{"__ignoreMap":53},[57,958,959,961,965,968,970,973],{"class":59,"line":60},[57,960,579],{"class":102},[57,962,964],{"class":963},"sovSZ","script",[57,966,967],{"class":63}," lang",[57,969,559],{"class":102},[57,971,972],{"class":71},"\"ts\"",[57,974,975],{"class":102},">\n",[57,977,978,980,982,985,987],{"class":59,"line":119},[57,979,438],{"class":92},[57,981,441],{"class":92},[57,983,984],{"class":102}," { Comment } ",[57,986,447],{"class":92},[57,988,989],{"class":71}," '@\u002Fcomments\u002Ftypes\u002Fcomment'\n",[57,991,992],{"class":59,"line":141},[57,993,150],{"emptyLinePlaceholder":22},[57,995,996,999,1002,1004,1007],{"class":59,"line":147},[57,997,998],{"class":92},"const",[57,1000,1001],{"class":67}," blogComment",[57,1003,531],{"class":92},[57,1005,1006],{"class":63}," tv",[57,1008,1009],{"class":102},"({\n",[57,1011,1012],{"class":59,"line":153},[57,1013,1014],{"class":102},"  slots: {\n",[57,1016,1017,1020,1023],{"class":59,"line":184},[57,1018,1019],{"class":102},"    base: ",[57,1021,1022],{"class":71},"'space-y-4'",[57,1024,211],{"class":102},[57,1026,1027,1030,1033],{"class":59,"line":202},[57,1028,1029],{"class":102},"    content: ",[57,1031,1032],{"class":71},"''",[57,1034,211],{"class":102},[57,1036,1037,1040,1043],{"class":59,"line":214},[57,1038,1039],{"class":102},"    author: ",[57,1041,1042],{"class":71},"'flex items-center gap-2 font-semibold'",[57,1044,211],{"class":102},[57,1046,1047,1050,1053],{"class":59,"line":220},[57,1048,1049],{"class":102},"    authorAvatar: ",[57,1051,1052],{"class":71},"'size-8 rounded-full'",[57,1054,211],{"class":102},[57,1056,1057],{"class":59,"line":226},[57,1058,1059],{"class":102},"  },\n",[57,1061,1062],{"class":59,"line":231},[57,1063,664],{"class":102},[57,1065,1066],{"class":59,"line":236},[57,1067,150],{"emptyLinePlaceholder":22},[57,1069,1070,1072,1074,1077],{"class":59,"line":265},[57,1071,93],{"class":92},[57,1073,461],{"class":92},[57,1075,1076],{"class":63}," BlogCommentProps",[57,1078,467],{"class":102},[57,1080,1081,1084,1086],{"class":59,"line":284},[57,1082,1083],{"class":106},"  comment",[57,1085,110],{"class":92},[57,1087,1088],{"class":63}," Comment\n",[57,1090,1091,1094,1097],{"class":59,"line":294},[57,1092,1093],{"class":106},"  class",[57,1095,1096],{"class":92},"?:",[57,1098,1099],{"class":67}," any\n",[57,1101,1102,1105,1107,1110,1112,1114],{"class":59,"line":299},[57,1103,1104],{"class":106},"  ui",[57,1106,1096],{"class":92},[57,1108,1109],{"class":63}," Partial",[57,1111,579],{"class":102},[57,1113,644],{"class":92},[57,1115,1116],{"class":102}," blogComment.slots>\n",[57,1118,1119],{"class":59,"line":304},[57,1120,144],{"class":102},[57,1122,1123,1125,1127,1130],{"class":59,"line":309},[57,1124,93],{"class":92},[57,1126,461],{"class":92},[57,1128,1129],{"class":63}," BlogCommentEmits",[57,1131,1132],{"class":102}," {}\n",[57,1134,1135,1137,1139,1142],{"class":59,"line":329},[57,1136,93],{"class":92},[57,1138,461],{"class":92},[57,1140,1141],{"class":63}," BlogCommentSlots",[57,1143,1132],{"class":102},[57,1145,1146,1149,1151],{"class":59,"line":346},[57,1147,1148],{"class":102},"\u003C\u002F",[57,1150,964],{"class":963},[57,1152,975],{"class":102},[57,1154,1155],{"class":59,"line":356},[57,1156,150],{"emptyLinePlaceholder":22},[57,1158,1159,1161,1163,1165,1167,1169,1172],{"class":59,"line":361},[57,1160,579],{"class":102},[57,1162,964],{"class":963},[57,1164,967],{"class":63},[57,1166,559],{"class":102},[57,1168,972],{"class":71},[57,1170,1171],{"class":63}," setup",[57,1173,975],{"class":102},[57,1175,1177,1179,1182,1184,1187,1189,1192],{"class":59,"line":1176},23,[57,1178,998],{"class":92},[57,1180,1181],{"class":67}," props",[57,1183,531],{"class":92},[57,1185,1186],{"class":63}," defineProps",[57,1188,579],{"class":102},[57,1190,1191],{"class":63},"BlogCommentProps",[57,1193,1194],{"class":102},">()\n",[57,1196,1198,1201,1203,1206],{"class":59,"line":1197},24,[57,1199,1200],{"class":63},"defineEmits",[57,1202,579],{"class":102},[57,1204,1205],{"class":63},"BlogCommentEmits",[57,1207,1194],{"class":102},[57,1209,1211,1214,1216,1219],{"class":59,"line":1210},25,[57,1212,1213],{"class":63},"defineSlots",[57,1215,579],{"class":102},[57,1217,1218],{"class":63},"BlogCommentSlots",[57,1220,1194],{"class":102},[57,1222,1224],{"class":59,"line":1223},26,[57,1225,150],{"emptyLinePlaceholder":22},[57,1227,1229,1231,1233,1236,1239,1242,1244,1246,1249],{"class":59,"line":1228},27,[57,1230,998],{"class":92},[57,1232,550],{"class":102},[57,1234,1235],{"class":106},"mutate",[57,1237,1238],{"class":102},": ",[57,1240,1241],{"class":67},"deleteComment",[57,1243,556],{"class":102},[57,1245,559],{"class":92},[57,1247,1248],{"class":63}," useDeleteComment",[57,1250,565],{"class":102},[57,1252,1254],{"class":59,"line":1253},28,[57,1255,150],{"emptyLinePlaceholder":22},[57,1257,1259,1261,1264,1266,1269,1271,1274],{"class":59,"line":1258},29,[57,1260,998],{"class":92},[57,1262,1263],{"class":67}," update",[57,1265,531],{"class":92},[57,1267,1268],{"class":63}," ref",[57,1270,103],{"class":102},[57,1272,1273],{"class":67},"false",[57,1275,138],{"class":102},[57,1277,1279],{"class":59,"line":1278},30,[57,1280,150],{"emptyLinePlaceholder":22},[57,1282,1284,1286,1289,1291,1294,1296,1298,1300],{"class":59,"line":1283},31,[57,1285,998],{"class":92},[57,1287,1288],{"class":67}," ui",[57,1290,531],{"class":92},[57,1292,1293],{"class":63}," computed",[57,1295,537],{"class":102},[57,1297,540],{"class":92},[57,1299,1001],{"class":63},[57,1301,1302],{"class":102},"())\n",[57,1304,1306,1308,1310],{"class":59,"line":1305},32,[57,1307,1148],{"class":102},[57,1309,964],{"class":963},[57,1311,975],{"class":102},[57,1313,1315],{"class":59,"line":1314},33,[57,1316,150],{"emptyLinePlaceholder":22},[57,1318,1320,1322,1325],{"class":59,"line":1319},34,[57,1321,579],{"class":102},[57,1323,1324],{"class":963},"template",[57,1326,975],{"class":102},[57,1328,1330,1333,1336,1339,1341,1344],{"class":59,"line":1329},35,[57,1331,1332],{"class":102},"  \u003C",[57,1334,1335],{"class":963},"article",[57,1337,1338],{"class":63}," :class",[57,1340,559],{"class":102},[57,1342,1343],{"class":71},"\"ui.base({ class: [props.class, props.ui?.base] })\"",[57,1345,975],{"class":102},[57,1347,1349,1352,1354],{"class":59,"line":1348},36,[57,1350,1351],{"class":102},"    \u003C",[57,1353,10],{"class":963},[57,1355,975],{"class":102},[57,1357,1359],{"class":59,"line":1358},37,[57,1360,1361],{"class":102},"      {{ props.comment.content }}\n",[57,1363,1365,1368,1370],{"class":59,"line":1364},38,[57,1366,1367],{"class":102},"    \u003C\u002F",[57,1369,10],{"class":963},[57,1371,975],{"class":102},[57,1373,1375],{"class":59,"line":1374},39,[57,1376,150],{"emptyLinePlaceholder":22},[57,1378,1380,1382,1385,1387,1389,1392],{"class":59,"line":1379},40,[57,1381,1351],{"class":102},[57,1383,1384],{"class":963},"div",[57,1386,1338],{"class":63},[57,1388,559],{"class":102},[57,1390,1391],{"class":71},"\"ui.author({ class: props.ui?.author })\"",[57,1393,975],{"class":102},[57,1395,1397,1400],{"class":59,"line":1396},41,[57,1398,1399],{"class":102},"      \u003C",[57,1401,1402],{"class":963},"img\n",[57,1404,1406,1409,1411],{"class":59,"line":1405},42,[57,1407,1408],{"class":63},"        v-if",[57,1410,559],{"class":102},[57,1412,1413],{"class":71},"\"props.comment.author.avatar\"\n",[57,1415,1417,1420,1422],{"class":59,"line":1416},43,[57,1418,1419],{"class":63},"        :src",[57,1421,559],{"class":102},[57,1423,1413],{"class":71},[57,1425,1427,1430,1432],{"class":59,"line":1426},44,[57,1428,1429],{"class":63},"        :class",[57,1431,559],{"class":102},[57,1433,1434],{"class":71},"\"ui.authorAvatar({ class: props.ui?.authorAvatar })\"\n",[57,1436,1438],{"class":59,"line":1437},45,[57,1439,1440],{"class":102},"      >\n",[57,1442,1444,1446,1448,1451,1453,1456,1459,1461],{"class":59,"line":1443},46,[57,1445,1399],{"class":102},[57,1447,1324],{"class":963},[57,1449,1450],{"class":92}," v-if",[57,1452,559],{"class":102},[57,1454,1455],{"class":71},"\"",[57,1457,1458],{"class":102},"props.comment.author.name",[57,1460,1455],{"class":71},[57,1462,975],{"class":102},[57,1464,1466],{"class":59,"line":1465},47,[57,1467,1468],{"class":102},"        {{ props.comment.author.name }} ({{ props.comment.author.username }})\n",[57,1470,1472,1475,1477],{"class":59,"line":1471},48,[57,1473,1474],{"class":102},"      \u003C\u002F",[57,1476,1324],{"class":963},[57,1478,975],{"class":102},[57,1480,1482,1484,1486,1489],{"class":59,"line":1481},49,[57,1483,1399],{"class":102},[57,1485,1324],{"class":963},[57,1487,1488],{"class":92}," v-else",[57,1490,975],{"class":102},[57,1492,1494],{"class":59,"line":1493},50,[57,1495,1496],{"class":102},"        {{ props.comment.author.username }}\n",[57,1498,1500,1502,1504],{"class":59,"line":1499},51,[57,1501,1474],{"class":102},[57,1503,1324],{"class":963},[57,1505,975],{"class":102},[57,1507,1509,1511,1513],{"class":59,"line":1508},52,[57,1510,1367],{"class":102},[57,1512,1384],{"class":963},[57,1514,975],{"class":102},[57,1516,1518,1521,1523],{"class":59,"line":1517},53,[57,1519,1520],{"class":102},"  \u003C\u002F",[57,1522,1335],{"class":963},[57,1524,975],{"class":102},[57,1526,1528,1530,1532],{"class":59,"line":1527},54,[57,1529,1148],{"class":102},[57,1531,1324],{"class":963},[57,1533,975],{"class":102},[10,1535,1536,1538,1539,417],{},[42,1537,936],{}," is also presentational. It receives a list and renders each item with ",[42,1540,930],{},[47,1542,1545],{"className":951,"code":1543,"filename":1544,"language":954,"meta":53,"style":53},"\u003Cscript lang=\"ts\">\nimport type { Comment } from '@\u002Fcomments\u002Ftypes\u002Fcomment'\n\nconst blogComments = tv({\n  slots: {\n    base: 'space-y-8',\n    empty: '',\n  },\n})\n\nexport interface BlogCommentsProps {\n  comments: Comment[]\n  class?: any\n  ui?: Partial\u003Ctypeof blogComments.slots>\n}\nexport interface BlogCommentsEmits {}\nexport interface BlogCommentsSlots {}\n\u003C\u002Fscript>\n\n\u003Cscript lang=\"ts\" setup>\nconst props = defineProps\u003CBlogCommentsProps>()\ndefineEmits\u003CBlogCommentsEmits>()\ndefineSlots\u003CBlogCommentsSlots>()\n\nconst ui = computed(() => blogComments())\n\u003C\u002Fscript>\n\n\u003Ctemplate>\n  \u003Col :class=\"ui.base({ class: props.ui?.base })\">\n    \u003Cli\n      v-if=\"props.comments.length === 0\"\n      :class=\"ui.empty({ class: props.ui?.empty })\"\n    >\n      No comments yet.\n    \u003C\u002Fli>\n    \u003Ctemplate v-else>\n      \u003Cli v-for=\"comment in props.comments\" :key=\"comment.id\">\n        \u003CComment :comment=\"comment\" \u002F>\n      \u003C\u002Fli>\n    \u003C\u002Ftemplate>\n  \u003C\u002Fol>\n\u003C\u002Ftemplate>\n",".vitepress\u002Ftheme\u002Fcomments\u002Fcomponents\u002FCommentList.vue",[42,1546,1547,1561,1573,1577,1590,1594,1603,1612,1616,1620,1624,1635,1647,1655,1670,1674,1685,1696,1704,1708,1724,1741,1752,1763,1767,1785,1793,1797,1805,1820,1827,1837,1847,1852,1857,1865,1875,1899,1923,1931,1939,1947],{"__ignoreMap":53},[57,1548,1549,1551,1553,1555,1557,1559],{"class":59,"line":60},[57,1550,579],{"class":102},[57,1552,964],{"class":963},[57,1554,967],{"class":63},[57,1556,559],{"class":102},[57,1558,972],{"class":71},[57,1560,975],{"class":102},[57,1562,1563,1565,1567,1569,1571],{"class":59,"line":119},[57,1564,438],{"class":92},[57,1566,441],{"class":92},[57,1568,984],{"class":102},[57,1570,447],{"class":92},[57,1572,989],{"class":71},[57,1574,1575],{"class":59,"line":141},[57,1576,150],{"emptyLinePlaceholder":22},[57,1578,1579,1581,1584,1586,1588],{"class":59,"line":147},[57,1580,998],{"class":92},[57,1582,1583],{"class":67}," blogComments",[57,1585,531],{"class":92},[57,1587,1006],{"class":63},[57,1589,1009],{"class":102},[57,1591,1592],{"class":59,"line":153},[57,1593,1014],{"class":102},[57,1595,1596,1598,1601],{"class":59,"line":184},[57,1597,1019],{"class":102},[57,1599,1600],{"class":71},"'space-y-8'",[57,1602,211],{"class":102},[57,1604,1605,1608,1610],{"class":59,"line":202},[57,1606,1607],{"class":102},"    empty: ",[57,1609,1032],{"class":71},[57,1611,211],{"class":102},[57,1613,1614],{"class":59,"line":214},[57,1615,1059],{"class":102},[57,1617,1618],{"class":59,"line":220},[57,1619,664],{"class":102},[57,1621,1622],{"class":59,"line":226},[57,1623,150],{"emptyLinePlaceholder":22},[57,1625,1626,1628,1630,1633],{"class":59,"line":231},[57,1627,93],{"class":92},[57,1629,461],{"class":92},[57,1631,1632],{"class":63}," BlogCommentsProps",[57,1634,467],{"class":102},[57,1636,1637,1640,1642,1644],{"class":59,"line":236},[57,1638,1639],{"class":106},"  comments",[57,1641,110],{"class":92},[57,1643,464],{"class":63},[57,1645,1646],{"class":102},"[]\n",[57,1648,1649,1651,1653],{"class":59,"line":265},[57,1650,1093],{"class":106},[57,1652,1096],{"class":92},[57,1654,1099],{"class":67},[57,1656,1657,1659,1661,1663,1665,1667],{"class":59,"line":284},[57,1658,1104],{"class":106},[57,1660,1096],{"class":92},[57,1662,1109],{"class":63},[57,1664,579],{"class":102},[57,1666,644],{"class":92},[57,1668,1669],{"class":102}," blogComments.slots>\n",[57,1671,1672],{"class":59,"line":294},[57,1673,144],{"class":102},[57,1675,1676,1678,1680,1683],{"class":59,"line":299},[57,1677,93],{"class":92},[57,1679,461],{"class":92},[57,1681,1682],{"class":63}," BlogCommentsEmits",[57,1684,1132],{"class":102},[57,1686,1687,1689,1691,1694],{"class":59,"line":304},[57,1688,93],{"class":92},[57,1690,461],{"class":92},[57,1692,1693],{"class":63}," BlogCommentsSlots",[57,1695,1132],{"class":102},[57,1697,1698,1700,1702],{"class":59,"line":309},[57,1699,1148],{"class":102},[57,1701,964],{"class":963},[57,1703,975],{"class":102},[57,1705,1706],{"class":59,"line":329},[57,1707,150],{"emptyLinePlaceholder":22},[57,1709,1710,1712,1714,1716,1718,1720,1722],{"class":59,"line":346},[57,1711,579],{"class":102},[57,1713,964],{"class":963},[57,1715,967],{"class":63},[57,1717,559],{"class":102},[57,1719,972],{"class":71},[57,1721,1171],{"class":63},[57,1723,975],{"class":102},[57,1725,1726,1728,1730,1732,1734,1736,1739],{"class":59,"line":356},[57,1727,998],{"class":92},[57,1729,1181],{"class":67},[57,1731,531],{"class":92},[57,1733,1186],{"class":63},[57,1735,579],{"class":102},[57,1737,1738],{"class":63},"BlogCommentsProps",[57,1740,1194],{"class":102},[57,1742,1743,1745,1747,1750],{"class":59,"line":361},[57,1744,1200],{"class":63},[57,1746,579],{"class":102},[57,1748,1749],{"class":63},"BlogCommentsEmits",[57,1751,1194],{"class":102},[57,1753,1754,1756,1758,1761],{"class":59,"line":1176},[57,1755,1213],{"class":63},[57,1757,579],{"class":102},[57,1759,1760],{"class":63},"BlogCommentsSlots",[57,1762,1194],{"class":102},[57,1764,1765],{"class":59,"line":1197},[57,1766,150],{"emptyLinePlaceholder":22},[57,1768,1769,1771,1773,1775,1777,1779,1781,1783],{"class":59,"line":1210},[57,1770,998],{"class":92},[57,1772,1288],{"class":67},[57,1774,531],{"class":92},[57,1776,1293],{"class":63},[57,1778,537],{"class":102},[57,1780,540],{"class":92},[57,1782,1583],{"class":63},[57,1784,1302],{"class":102},[57,1786,1787,1789,1791],{"class":59,"line":1223},[57,1788,1148],{"class":102},[57,1790,964],{"class":963},[57,1792,975],{"class":102},[57,1794,1795],{"class":59,"line":1228},[57,1796,150],{"emptyLinePlaceholder":22},[57,1798,1799,1801,1803],{"class":59,"line":1253},[57,1800,579],{"class":102},[57,1802,1324],{"class":963},[57,1804,975],{"class":102},[57,1806,1807,1809,1811,1813,1815,1818],{"class":59,"line":1258},[57,1808,1332],{"class":102},[57,1810,923],{"class":963},[57,1812,1338],{"class":63},[57,1814,559],{"class":102},[57,1816,1817],{"class":71},"\"ui.base({ class: props.ui?.base })\"",[57,1819,975],{"class":102},[57,1821,1822,1824],{"class":59,"line":1278},[57,1823,1351],{"class":102},[57,1825,1826],{"class":963},"li\n",[57,1828,1829,1832,1834],{"class":59,"line":1283},[57,1830,1831],{"class":63},"      v-if",[57,1833,559],{"class":102},[57,1835,1836],{"class":71},"\"props.comments.length === 0\"\n",[57,1838,1839,1842,1844],{"class":59,"line":1305},[57,1840,1841],{"class":63},"      :class",[57,1843,559],{"class":102},[57,1845,1846],{"class":71},"\"ui.empty({ class: props.ui?.empty })\"\n",[57,1848,1849],{"class":59,"line":1314},[57,1850,1851],{"class":102},"    >\n",[57,1853,1854],{"class":59,"line":1319},[57,1855,1856],{"class":102},"      No comments yet.\n",[57,1858,1859,1861,1863],{"class":59,"line":1329},[57,1860,1367],{"class":102},[57,1862,926],{"class":963},[57,1864,975],{"class":102},[57,1866,1867,1869,1871,1873],{"class":59,"line":1348},[57,1868,1351],{"class":102},[57,1870,1324],{"class":963},[57,1872,1488],{"class":92},[57,1874,975],{"class":102},[57,1876,1877,1879,1881,1884,1886,1889,1892,1894,1897],{"class":59,"line":1358},[57,1878,1399],{"class":102},[57,1880,926],{"class":963},[57,1882,1883],{"class":63}," v-for",[57,1885,559],{"class":102},[57,1887,1888],{"class":71},"\"comment in props.comments\"",[57,1890,1891],{"class":63}," :key",[57,1893,559],{"class":102},[57,1895,1896],{"class":71},"\"comment.id\"",[57,1898,975],{"class":102},[57,1900,1901,1904,1906,1909,1912,1914,1916,1918,1920],{"class":59,"line":1364},[57,1902,1903],{"class":102},"        \u003C",[57,1905,582],{"class":963},[57,1907,1908],{"class":102}," :",[57,1910,1911],{"class":63},"comment",[57,1913,559],{"class":102},[57,1915,1455],{"class":71},[57,1917,1911],{"class":102},[57,1919,1455],{"class":71},[57,1921,1922],{"class":102}," \u002F>\n",[57,1924,1925,1927,1929],{"class":59,"line":1374},[57,1926,1474],{"class":102},[57,1928,926],{"class":963},[57,1930,975],{"class":102},[57,1932,1933,1935,1937],{"class":59,"line":1379},[57,1934,1367],{"class":102},[57,1936,1324],{"class":963},[57,1938,975],{"class":102},[57,1940,1941,1943,1945],{"class":59,"line":1396},[57,1942,1520],{"class":102},[57,1944,923],{"class":963},[57,1946,975],{"class":102},[57,1948,1949,1951,1953],{"class":59,"line":1405},[57,1950,1148],{"class":102},[57,1952,1324],{"class":963},[57,1954,975],{"class":102},[10,1956,1957,1958,1960],{},"Finally, ",[42,1959,942],{}," displays the titled section and fetches the comments:",[47,1962,1966],{"className":1963,"code":1964,"filename":1965,"language":954,"meta":53,"style":53},"language-vue shiki shiki-themes github-light github-light github-dark has-highlighted","\u003Cscript lang=\"ts\">\nconst blogCommentsSection = tv({\n  slots: {\n    base: 'space-y-12',\n    title: 'text-2xl font-bold',\n    list: 'space-y-8',\n  },\n})\n\nexport interface BlogCommentsSectionProps {\n  class?: any\n  ui?: Partial\u003Ctypeof blogCommentsSection.slots>\n}\nexport interface BlogCommentsSectionEmits {}\nexport interface BlogCommentsSectionSlots {}\n\u003C\u002Fscript>\n\n\u003Cscript lang=\"ts\" setup>\nconst props = defineProps\u003CBlogCommentsSectionProps>()\ndefineEmits\u003CBlogCommentsSectionEmits>()\ndefineSlots\u003CBlogCommentsSectionSlots>()\n\nconst { state: commentsState } = useComments() \u002F\u002F [!code highlight]\n\nconst ui = computed(() => blogCommentsSection())\n\u003C\u002Fscript>\n\n\u003Ctemplate>\n  \u003Csection :class=\"ui.base({ class: [props.class, props.ui?.base] })\">\n    \u003Ch2 :class=\"ui.title({ class: props.ui?.title })\">\n      Comments\n    \u003C\u002Fh2>\n\n    \u003Cdiv v-if=\"commentsState.status === 'pending'\">\n      Loading comments...\n    \u003C\u002Fdiv>\n    \u003Cdiv v-else-if=\"commentsState.status === 'error'\">\n      Error loading comments\n    \u003C\u002Fdiv>\n\n    \u003Ctemplate v-else>\n      \u003CCommentList\n        :comments=\"commentsState.data\"\n        :class=\"ui.list({ class: props.ui?.list })\"\n      \u002F>\n    \u003C\u002Ftemplate>\n  \u003C\u002Fsection>\n\u003C\u002Ftemplate>\n",".vitepress\u002Ftheme\u002Fcomments\u002Fcomponents\u002FCommentSection.vue",[42,1967,1968,1982,1995,1999,2008,2018,2027,2031,2035,2039,2050,2058,2073,2077,2088,2099,2107,2111,2127,2144,2155,2166,2170,2195,2199,2217,2225,2229,2237,2252,2267,2272,2280,2284,2299,2304,2312,2328,2333,2341,2345,2355,2362,2380,2402,2407,2415,2423],{"__ignoreMap":53},[57,1969,1970,1972,1974,1976,1978,1980],{"class":59,"line":60},[57,1971,579],{"class":102},[57,1973,964],{"class":963},[57,1975,967],{"class":63},[57,1977,559],{"class":102},[57,1979,972],{"class":71},[57,1981,975],{"class":102},[57,1983,1984,1986,1989,1991,1993],{"class":59,"line":119},[57,1985,998],{"class":92},[57,1987,1988],{"class":67}," blogCommentsSection",[57,1990,531],{"class":92},[57,1992,1006],{"class":63},[57,1994,1009],{"class":102},[57,1996,1997],{"class":59,"line":141},[57,1998,1014],{"class":102},[57,2000,2001,2003,2006],{"class":59,"line":147},[57,2002,1019],{"class":102},[57,2004,2005],{"class":71},"'space-y-12'",[57,2007,211],{"class":102},[57,2009,2010,2013,2016],{"class":59,"line":153},[57,2011,2012],{"class":102},"    title: ",[57,2014,2015],{"class":71},"'text-2xl font-bold'",[57,2017,211],{"class":102},[57,2019,2020,2023,2025],{"class":59,"line":184},[57,2021,2022],{"class":102},"    list: ",[57,2024,1600],{"class":71},[57,2026,211],{"class":102},[57,2028,2029],{"class":59,"line":202},[57,2030,1059],{"class":102},[57,2032,2033],{"class":59,"line":214},[57,2034,664],{"class":102},[57,2036,2037],{"class":59,"line":220},[57,2038,150],{"emptyLinePlaceholder":22},[57,2040,2041,2043,2045,2048],{"class":59,"line":226},[57,2042,93],{"class":92},[57,2044,461],{"class":92},[57,2046,2047],{"class":63}," BlogCommentsSectionProps",[57,2049,467],{"class":102},[57,2051,2052,2054,2056],{"class":59,"line":231},[57,2053,1093],{"class":106},[57,2055,1096],{"class":92},[57,2057,1099],{"class":67},[57,2059,2060,2062,2064,2066,2068,2070],{"class":59,"line":236},[57,2061,1104],{"class":106},[57,2063,1096],{"class":92},[57,2065,1109],{"class":63},[57,2067,579],{"class":102},[57,2069,644],{"class":92},[57,2071,2072],{"class":102}," blogCommentsSection.slots>\n",[57,2074,2075],{"class":59,"line":265},[57,2076,144],{"class":102},[57,2078,2079,2081,2083,2086],{"class":59,"line":284},[57,2080,93],{"class":92},[57,2082,461],{"class":92},[57,2084,2085],{"class":63}," BlogCommentsSectionEmits",[57,2087,1132],{"class":102},[57,2089,2090,2092,2094,2097],{"class":59,"line":294},[57,2091,93],{"class":92},[57,2093,461],{"class":92},[57,2095,2096],{"class":63}," BlogCommentsSectionSlots",[57,2098,1132],{"class":102},[57,2100,2101,2103,2105],{"class":59,"line":299},[57,2102,1148],{"class":102},[57,2104,964],{"class":963},[57,2106,975],{"class":102},[57,2108,2109],{"class":59,"line":304},[57,2110,150],{"emptyLinePlaceholder":22},[57,2112,2113,2115,2117,2119,2121,2123,2125],{"class":59,"line":309},[57,2114,579],{"class":102},[57,2116,964],{"class":963},[57,2118,967],{"class":63},[57,2120,559],{"class":102},[57,2122,972],{"class":71},[57,2124,1171],{"class":63},[57,2126,975],{"class":102},[57,2128,2129,2131,2133,2135,2137,2139,2142],{"class":59,"line":329},[57,2130,998],{"class":92},[57,2132,1181],{"class":67},[57,2134,531],{"class":92},[57,2136,1186],{"class":63},[57,2138,579],{"class":102},[57,2140,2141],{"class":63},"BlogCommentsSectionProps",[57,2143,1194],{"class":102},[57,2145,2146,2148,2150,2153],{"class":59,"line":346},[57,2147,1200],{"class":63},[57,2149,579],{"class":102},[57,2151,2152],{"class":63},"BlogCommentsSectionEmits",[57,2154,1194],{"class":102},[57,2156,2157,2159,2161,2164],{"class":59,"line":356},[57,2158,1213],{"class":63},[57,2160,579],{"class":102},[57,2162,2163],{"class":63},"BlogCommentsSectionSlots",[57,2165,1194],{"class":102},[57,2167,2168],{"class":59,"line":361},[57,2169,150],{"emptyLinePlaceholder":22},[57,2171,2174,2176,2178,2181,2183,2186,2188,2190,2192],{"class":2172,"line":1176},[59,2173],"highlighted",[57,2175,998],{"class":92},[57,2177,550],{"class":102},[57,2179,2180],{"class":106},"state",[57,2182,1238],{"class":102},[57,2184,2185],{"class":67},"commentsState",[57,2187,556],{"class":102},[57,2189,559],{"class":92},[57,2191,528],{"class":63},[57,2193,2194],{"class":102},"() ",[57,2196,2197],{"class":59,"line":1197},[57,2198,150],{"emptyLinePlaceholder":22},[57,2200,2201,2203,2205,2207,2209,2211,2213,2215],{"class":59,"line":1210},[57,2202,998],{"class":92},[57,2204,1288],{"class":67},[57,2206,531],{"class":92},[57,2208,1293],{"class":63},[57,2210,537],{"class":102},[57,2212,540],{"class":92},[57,2214,1988],{"class":63},[57,2216,1302],{"class":102},[57,2218,2219,2221,2223],{"class":59,"line":1223},[57,2220,1148],{"class":102},[57,2222,964],{"class":963},[57,2224,975],{"class":102},[57,2226,2227],{"class":59,"line":1228},[57,2228,150],{"emptyLinePlaceholder":22},[57,2230,2231,2233,2235],{"class":59,"line":1253},[57,2232,579],{"class":102},[57,2234,1324],{"class":963},[57,2236,975],{"class":102},[57,2238,2239,2241,2244,2246,2248,2250],{"class":59,"line":1258},[57,2240,1332],{"class":102},[57,2242,2243],{"class":963},"section",[57,2245,1338],{"class":63},[57,2247,559],{"class":102},[57,2249,1343],{"class":71},[57,2251,975],{"class":102},[57,2253,2254,2256,2258,2260,2262,2265],{"class":59,"line":1278},[57,2255,1351],{"class":102},[57,2257,34],{"class":963},[57,2259,1338],{"class":63},[57,2261,559],{"class":102},[57,2263,2264],{"class":71},"\"ui.title({ class: props.ui?.title })\"",[57,2266,975],{"class":102},[57,2268,2269],{"class":59,"line":1283},[57,2270,2271],{"class":102},"      Comments\n",[57,2273,2274,2276,2278],{"class":59,"line":1305},[57,2275,1367],{"class":102},[57,2277,34],{"class":963},[57,2279,975],{"class":102},[57,2281,2282],{"class":59,"line":1314},[57,2283,150],{"emptyLinePlaceholder":22},[57,2285,2286,2288,2290,2292,2294,2297],{"class":59,"line":1319},[57,2287,1351],{"class":102},[57,2289,1384],{"class":963},[57,2291,1450],{"class":63},[57,2293,559],{"class":102},[57,2295,2296],{"class":71},"\"commentsState.status === 'pending'\"",[57,2298,975],{"class":102},[57,2300,2301],{"class":59,"line":1329},[57,2302,2303],{"class":102},"      Loading comments...\n",[57,2305,2306,2308,2310],{"class":59,"line":1348},[57,2307,1367],{"class":102},[57,2309,1384],{"class":963},[57,2311,975],{"class":102},[57,2313,2314,2316,2318,2321,2323,2326],{"class":59,"line":1358},[57,2315,1351],{"class":102},[57,2317,1384],{"class":963},[57,2319,2320],{"class":63}," v-else-if",[57,2322,559],{"class":102},[57,2324,2325],{"class":71},"\"commentsState.status === 'error'\"",[57,2327,975],{"class":102},[57,2329,2330],{"class":59,"line":1364},[57,2331,2332],{"class":102},"      Error loading comments\n",[57,2334,2335,2337,2339],{"class":59,"line":1374},[57,2336,1367],{"class":102},[57,2338,1384],{"class":963},[57,2340,975],{"class":102},[57,2342,2343],{"class":59,"line":1379},[57,2344,150],{"emptyLinePlaceholder":22},[57,2346,2347,2349,2351,2353],{"class":59,"line":1396},[57,2348,1351],{"class":102},[57,2350,1324],{"class":963},[57,2352,1488],{"class":92},[57,2354,975],{"class":102},[57,2356,2357,2359],{"class":59,"line":1405},[57,2358,1399],{"class":102},[57,2360,2361],{"class":963},"CommentList\n",[57,2363,2364,2367,2370,2372,2374,2377],{"class":59,"line":1416},[57,2365,2366],{"class":102},"        :",[57,2368,2369],{"class":63},"comments",[57,2371,559],{"class":102},[57,2373,1455],{"class":71},[57,2375,2376],{"class":102},"commentsState.data",[57,2378,2379],{"class":71},"\"\n",[57,2381,2382,2384,2387,2389,2391,2394,2397,2400],{"class":59,"line":1426},[57,2383,2366],{"class":102},[57,2385,2386],{"class":63},"class",[57,2388,559],{"class":102},[57,2390,1455],{"class":71},[57,2392,2393],{"class":102},"ui.",[57,2395,2396],{"class":63},"list",[57,2398,2399],{"class":102},"({ class: props.ui?.list })",[57,2401,2379],{"class":71},[57,2403,2404],{"class":59,"line":1437},[57,2405,2406],{"class":102},"      \u002F>\n",[57,2408,2409,2411,2413],{"class":59,"line":1443},[57,2410,1367],{"class":102},[57,2412,1324],{"class":963},[57,2414,975],{"class":102},[57,2416,2417,2419,2421],{"class":59,"line":1465},[57,2418,1520],{"class":102},[57,2420,2243],{"class":963},[57,2422,975],{"class":102},[57,2424,2425,2427,2429],{"class":59,"line":1471},[57,2426,1148],{"class":102},[57,2428,1324],{"class":963},[57,2430,975],{"class":102},[10,2432,2433,2434,2437,2438,2440],{},"Use ",[42,2435,2436],{},"CommentSection"," in ",[42,2439,511],{}," to display the post's comments.",[47,2442,2446],{"className":2443,"code":2444,"filename":2445,"language":954,"meta":53,"style":53},"language-vue shiki shiki-themes github-light github-light github-dark has-diff","\u003Cscript lang=\"ts\" setup>\nconst { frontmatter } = useData()\n\u003C\u002Fscript>\n\n\u003Ctemplate>\n  \u003CPage>\n    \u003CBlogArticle :title=\"frontmatter.title\" \u002F>\n\n    \u003CCommentSection \u002F> \u003C!-- [!code ++] -->\n\n    \u003CPageFooter :back-to=\"{ href: '\u002Fblog', label: 'Back to Blog' }\" \u002F>\n  \u003C\u002FPage>\n\u003C\u002Ftemplate>\n",".vitepress\u002Ftheme\u002FBlogShow.vue",[42,2447,2448,2464,2480,2488,2492,2500,2509,2532,2536,2548,2552,2587,2595],{"__ignoreMap":53},[57,2449,2450,2452,2454,2456,2458,2460,2462],{"class":59,"line":60},[57,2451,579],{"class":102},[57,2453,964],{"class":963},[57,2455,967],{"class":63},[57,2457,559],{"class":102},[57,2459,972],{"class":71},[57,2461,1171],{"class":63},[57,2463,975],{"class":102},[57,2465,2466,2468,2470,2472,2474,2476,2478],{"class":59,"line":119},[57,2467,998],{"class":92},[57,2469,550],{"class":102},[57,2471,553],{"class":67},[57,2473,556],{"class":102},[57,2475,559],{"class":92},[57,2477,562],{"class":63},[57,2479,565],{"class":102},[57,2481,2482,2484,2486],{"class":59,"line":141},[57,2483,1148],{"class":102},[57,2485,964],{"class":963},[57,2487,975],{"class":102},[57,2489,2490],{"class":59,"line":147},[57,2491,150],{"emptyLinePlaceholder":22},[57,2493,2494,2496,2498],{"class":59,"line":153},[57,2495,579],{"class":102},[57,2497,1324],{"class":963},[57,2499,975],{"class":102},[57,2501,2502,2504,2507],{"class":59,"line":184},[57,2503,1332],{"class":102},[57,2505,2506],{"class":963},"Page",[57,2508,975],{"class":102},[57,2510,2511,2513,2516,2518,2521,2523,2525,2528,2530],{"class":59,"line":202},[57,2512,1351],{"class":102},[57,2514,2515],{"class":963},"BlogArticle",[57,2517,1908],{"class":102},[57,2519,2520],{"class":63},"title",[57,2522,559],{"class":102},[57,2524,1455],{"class":71},[57,2526,2527],{"class":102},"frontmatter.title",[57,2529,1455],{"class":71},[57,2531,1922],{"class":102},[57,2533,2534],{"class":59,"line":214},[57,2535,150],{"emptyLinePlaceholder":22},[57,2537,2541,2543,2545],{"class":2538,"line":220},[59,2539,2540],"diff","add",[57,2542,1351],{"class":102},[57,2544,2436],{"class":963},[57,2546,2547],{"class":102}," \u002F> ",[57,2549,2550],{"class":59,"line":226},[57,2551,150],{"emptyLinePlaceholder":22},[57,2553,2554,2556,2559,2561,2564,2566,2568,2571,2574,2577,2580,2583,2585],{"class":59,"line":231},[57,2555,1351],{"class":102},[57,2557,2558],{"class":963},"PageFooter",[57,2560,1908],{"class":102},[57,2562,2563],{"class":63},"back-to",[57,2565,559],{"class":102},[57,2567,1455],{"class":71},[57,2569,2570],{"class":102},"{ href: ",[57,2572,2573],{"class":71},"'\u002Fblog'",[57,2575,2576],{"class":102},", label: ",[57,2578,2579],{"class":71},"'Back to Blog'",[57,2581,2582],{"class":102}," }",[57,2584,1455],{"class":71},[57,2586,1922],{"class":102},[57,2588,2589,2591,2593],{"class":59,"line":236},[57,2590,1520],{"class":102},[57,2592,2506],{"class":963},[57,2594,975],{"class":102},[57,2596,2597,2599,2601],{"class":59,"line":265},[57,2598,1148],{"class":102},[57,2600,1324],{"class":963},[57,2602,975],{"class":102},[10,2604,2605],{},"Splitting the feature into focused components makes it easier to add features, change the design, fix bugs, and write tests.",[10,2607,2608],{},"Start the frontend and backend with the seeded database to see the comments on a post.",[34,2610,2612],{"id":2611},"adding-a-comment","Adding a comment",[10,2614,2615,2616,2619],{},"To add a comment, we need a form with a textarea. The form will use the ",[42,2617,2618],{},"postComment"," mutation.",[10,2621,2622,2623,2626],{},"Create a ",[42,2624,2625],{},"CommentForm.vue"," component for the form.",[10,2628,2629],{},"Start with the template:",[47,2631,2634],{"className":951,"code":2632,"filename":2633,"language":954,"meta":53,"style":53},"\u003Ctemplate>\n  \u003Cform\n    :class=\"ui.base({ class: [props.class, props.ui?.base] })\"\n    @submit.prevent=\"onSubmit\"\n  >\n    \u003Ctextarea\n      v-model=\"content\"\n      placeholder=\"Write a comment...\"\n      :class=\"ui.textarea({ class: props.ui?.textarea })\"\n    \u002F>\n\n    \u003Cspan v-if=\"error\" class=\"text-red-500\">{{ error.data.message }}\u003C\u002Fspan>\n\n    \u003CButton\n      type=\"submit\"\n      label=\"Comment\"\n      :class=\"ui.button({ class: props.ui?.button })\"\n      :disabled=\"isLoading\"\n    \u002F>\n  \u003C\u002Fform>\n\u003C\u002Ftemplate>\n",".vitepress\u002Ftheme\u002Fcomments\u002Fcomponents\u002FCommentForm.vue",[42,2635,2636,2644,2651,2661,2671,2676,2683,2693,2703,2712,2720,2724,2752,2756,2763,2773,2783,2804,2820,2825,2834],{"__ignoreMap":53},[57,2637,2638,2640,2642],{"class":59,"line":60},[57,2639,579],{"class":102},[57,2641,1324],{"class":963},[57,2643,975],{"class":102},[57,2645,2646,2648],{"class":59,"line":119},[57,2647,1332],{"class":102},[57,2649,2650],{"class":963},"form\n",[57,2652,2653,2656,2658],{"class":59,"line":141},[57,2654,2655],{"class":63},"    :class",[57,2657,559],{"class":102},[57,2659,2660],{"class":71},"\"ui.base({ class: [props.class, props.ui?.base] })\"\n",[57,2662,2663,2666,2668],{"class":59,"line":147},[57,2664,2665],{"class":63},"    @submit.prevent",[57,2667,559],{"class":102},[57,2669,2670],{"class":71},"\"onSubmit\"\n",[57,2672,2673],{"class":59,"line":153},[57,2674,2675],{"class":102},"  >\n",[57,2677,2678,2680],{"class":59,"line":184},[57,2679,1351],{"class":102},[57,2681,2682],{"class":963},"textarea\n",[57,2684,2685,2688,2690],{"class":59,"line":202},[57,2686,2687],{"class":63},"      v-model",[57,2689,559],{"class":102},[57,2691,2692],{"class":71},"\"content\"\n",[57,2694,2695,2698,2700],{"class":59,"line":214},[57,2696,2697],{"class":63},"      placeholder",[57,2699,559],{"class":102},[57,2701,2702],{"class":71},"\"Write a comment...\"\n",[57,2704,2705,2707,2709],{"class":59,"line":220},[57,2706,1841],{"class":63},[57,2708,559],{"class":102},[57,2710,2711],{"class":71},"\"ui.textarea({ class: props.ui?.textarea })\"\n",[57,2713,2714,2718],{"class":59,"line":226},[57,2715,2717],{"class":2716},"sPrNH","    \u002F",[57,2719,975],{"class":102},[57,2721,2722],{"class":59,"line":231},[57,2723,150],{"emptyLinePlaceholder":22},[57,2725,2726,2728,2730,2732,2734,2737,2740,2742,2745,2748,2750],{"class":59,"line":236},[57,2727,1351],{"class":102},[57,2729,57],{"class":963},[57,2731,1450],{"class":63},[57,2733,559],{"class":102},[57,2735,2736],{"class":71},"\"error\"",[57,2738,2739],{"class":63}," class",[57,2741,559],{"class":102},[57,2743,2744],{"class":71},"\"text-red-500\"",[57,2746,2747],{"class":102},">{{ error.data.message }}\u003C\u002F",[57,2749,57],{"class":963},[57,2751,975],{"class":102},[57,2753,2754],{"class":59,"line":265},[57,2755,150],{"emptyLinePlaceholder":22},[57,2757,2758,2760],{"class":59,"line":284},[57,2759,1351],{"class":102},[57,2761,2762],{"class":963},"Button\n",[57,2764,2765,2768,2770],{"class":59,"line":294},[57,2766,2767],{"class":63},"      type",[57,2769,559],{"class":102},[57,2771,2772],{"class":71},"\"submit\"\n",[57,2774,2775,2778,2780],{"class":59,"line":299},[57,2776,2777],{"class":63},"      label",[57,2779,559],{"class":102},[57,2781,2782],{"class":71},"\"Comment\"\n",[57,2784,2785,2788,2790,2792,2794,2796,2799,2802],{"class":59,"line":304},[57,2786,2787],{"class":102},"      :",[57,2789,2386],{"class":63},[57,2791,559],{"class":102},[57,2793,1455],{"class":71},[57,2795,2393],{"class":102},[57,2797,2798],{"class":63},"button",[57,2800,2801],{"class":102},"({ class: props.ui?.button })",[57,2803,2379],{"class":71},[57,2805,2806,2808,2811,2813,2815,2818],{"class":59,"line":309},[57,2807,2787],{"class":102},[57,2809,2810],{"class":63},"disabled",[57,2812,559],{"class":102},[57,2814,1455],{"class":71},[57,2816,2817],{"class":102},"isLoading",[57,2819,2379],{"class":71},[57,2821,2822],{"class":59,"line":329},[57,2823,2824],{"class":102},"    \u002F>\n",[57,2826,2827,2829,2832],{"class":59,"line":346},[57,2828,1520],{"class":102},[57,2830,2831],{"class":963},"form",[57,2833,975],{"class":102},[57,2835,2836,2838,2840],{"class":59,"line":356},[57,2837,1148],{"class":102},[57,2839,1324],{"class":963},[57,2841,975],{"class":102},[10,2843,2844],{},"Then define the mutation in the script:",[47,2846,2848],{"className":951,"code":2847,"filename":2633,"language":954,"meta":53,"style":53},"\u003Cscript lang=\"ts\" setup>\nconst { frontmatter } = useData()\nconst queryCache = useQueryCache()\n\nconst content = ref('')\n\nconst {\n  mutate: storeComment,\n  isLoading,\n  error,\n} = useMutation\u003C\n  {\n    data: Comment\n  },\n  { postId: number, content: string, parentId?: number },\n  {\n    data: {\n      message: string\n      errors: {\n        content: string[]\n      }\n    }\n  }\n>({\n  mutation: ({ postId, content }) => postComment(postId, content),\n  onSuccess: () => {\n    content.value = ''\n  },\n  onSettled: () =>\n    queryCache.invalidateQueries({\n      key: ['comments', frontmatter.value.id],\n      exact: true,\n    }),\n})\n\u003C\u002Fscript>\n",[42,2849,2850,2866,2882,2896,2900,2917,2921,2927,2939,2946,2953,2966,2971,2979,2983,3003,3007,3014,3022,3029,3037,3042,3046,3051,3058,3082,3093,3103,3107,3116,3126,3135,3145,3150,3154],{"__ignoreMap":53},[57,2851,2852,2854,2856,2858,2860,2862,2864],{"class":59,"line":60},[57,2853,579],{"class":102},[57,2855,964],{"class":963},[57,2857,967],{"class":63},[57,2859,559],{"class":102},[57,2861,972],{"class":71},[57,2863,1171],{"class":63},[57,2865,975],{"class":102},[57,2867,2868,2870,2872,2874,2876,2878,2880],{"class":59,"line":119},[57,2869,998],{"class":92},[57,2871,550],{"class":102},[57,2873,553],{"class":67},[57,2875,556],{"class":102},[57,2877,559],{"class":92},[57,2879,562],{"class":63},[57,2881,565],{"class":102},[57,2883,2884,2886,2889,2891,2894],{"class":59,"line":141},[57,2885,998],{"class":92},[57,2887,2888],{"class":67}," queryCache",[57,2890,531],{"class":92},[57,2892,2893],{"class":63}," useQueryCache",[57,2895,565],{"class":102},[57,2897,2898],{"class":59,"line":147},[57,2899,150],{"emptyLinePlaceholder":22},[57,2901,2902,2904,2907,2909,2911,2913,2915],{"class":59,"line":153},[57,2903,998],{"class":92},[57,2905,2906],{"class":67}," content",[57,2908,531],{"class":92},[57,2910,1268],{"class":63},[57,2912,103],{"class":102},[57,2914,1032],{"class":71},[57,2916,138],{"class":102},[57,2918,2919],{"class":59,"line":184},[57,2920,150],{"emptyLinePlaceholder":22},[57,2922,2923,2925],{"class":59,"line":202},[57,2924,998],{"class":92},[57,2926,467],{"class":102},[57,2928,2929,2932,2934,2937],{"class":59,"line":214},[57,2930,2931],{"class":106},"  mutate",[57,2933,1238],{"class":102},[57,2935,2936],{"class":67},"storeComment",[57,2938,211],{"class":102},[57,2940,2941,2944],{"class":59,"line":220},[57,2942,2943],{"class":67},"  isLoading",[57,2945,211],{"class":102},[57,2947,2948,2951],{"class":59,"line":226},[57,2949,2950],{"class":67},"  error",[57,2952,211],{"class":102},[57,2954,2955,2958,2960,2963],{"class":59,"line":231},[57,2956,2957],{"class":102},"} ",[57,2959,559],{"class":92},[57,2961,2962],{"class":102}," useMutation",[57,2964,2965],{"class":92},"\u003C\n",[57,2967,2968],{"class":59,"line":236},[57,2969,2970],{"class":102},"  {\n",[57,2972,2973,2976],{"class":59,"line":265},[57,2974,2975],{"class":63},"    data",[57,2977,2978],{"class":102},": Comment\n",[57,2980,2981],{"class":59,"line":284},[57,2982,1059],{"class":102},[57,2984,2985,2988,2990,2993,2995,2998,3000],{"class":59,"line":294},[57,2986,2987],{"class":102},"  { ",[57,2989,107],{"class":63},[57,2991,2992],{"class":102},": number, ",[57,2994,174],{"class":63},[57,2996,2997],{"class":102},": string, parentId",[57,2999,1096],{"class":92},[57,3001,3002],{"class":102}," number },\n",[57,3004,3005],{"class":59,"line":299},[57,3006,2970],{"class":102},[57,3008,3009,3011],{"class":59,"line":304},[57,3010,2975],{"class":63},[57,3012,3013],{"class":102},": {\n",[57,3015,3016,3019],{"class":59,"line":309},[57,3017,3018],{"class":63},"      message",[57,3020,3021],{"class":102},": string\n",[57,3023,3024,3027],{"class":59,"line":329},[57,3025,3026],{"class":63},"      errors",[57,3028,3013],{"class":102},[57,3030,3031,3034],{"class":59,"line":346},[57,3032,3033],{"class":63},"        content",[57,3035,3036],{"class":102},": string[]\n",[57,3038,3039],{"class":59,"line":356},[57,3040,3041],{"class":102},"      }\n",[57,3043,3044],{"class":59,"line":361},[57,3045,804],{"class":102},[57,3047,3048],{"class":59,"line":1176},[57,3049,3050],{"class":102},"  }\n",[57,3052,3053,3056],{"class":59,"line":1197},[57,3054,3055],{"class":92},">",[57,3057,1009],{"class":102},[57,3059,3060,3063,3066,3068,3070,3072,3075,3077,3079],{"class":59,"line":1210},[57,3061,3062],{"class":63},"  mutation",[57,3064,3065],{"class":102},": ({ ",[57,3067,107],{"class":106},[57,3069,171],{"class":102},[57,3071,174],{"class":106},[57,3073,3074],{"class":102}," }) ",[57,3076,540],{"class":92},[57,3078,160],{"class":63},[57,3080,3081],{"class":102},"(postId, content),\n",[57,3083,3084,3087,3089,3091],{"class":59,"line":1223},[57,3085,3086],{"class":63},"  onSuccess",[57,3088,593],{"class":102},[57,3090,540],{"class":92},[57,3092,467],{"class":102},[57,3094,3095,3098,3100],{"class":59,"line":1228},[57,3096,3097],{"class":102},"    content.value ",[57,3099,559],{"class":92},[57,3101,3102],{"class":71}," ''\n",[57,3104,3105],{"class":59,"line":1253},[57,3106,1059],{"class":102},[57,3108,3109,3112,3114],{"class":59,"line":1258},[57,3110,3111],{"class":63},"  onSettled",[57,3113,593],{"class":102},[57,3115,614],{"class":92},[57,3117,3118,3121,3124],{"class":59,"line":1278},[57,3119,3120],{"class":102},"    queryCache.",[57,3122,3123],{"class":63},"invalidateQueries",[57,3125,1009],{"class":102},[57,3127,3128,3131,3133],{"class":59,"line":1283},[57,3129,3130],{"class":102},"      key: [",[57,3132,601],{"class":71},[57,3134,604],{"class":102},[57,3136,3137,3140,3143],{"class":59,"line":1305},[57,3138,3139],{"class":102},"      exact: ",[57,3141,3142],{"class":67},"true",[57,3144,211],{"class":102},[57,3146,3147],{"class":59,"line":1314},[57,3148,3149],{"class":102},"    }),\n",[57,3151,3152],{"class":59,"line":1319},[57,3153,664],{"class":102},[57,3155,3156,3158,3160],{"class":59,"line":1329},[57,3157,1148],{"class":102},[57,3159,964],{"class":963},[57,3161,975],{"class":102},[10,3163,3164],{},"The mutation exposes the action, loading state, and error. We can use them to show an error when the request fails and disable the button while it is in progress. A loading indicator could be added in the same place.",[10,3166,3167],{},"The error shape matches Laravel's validation response. Disabling the button prevents duplicate submissions while the request is running.",[727,3169,3170],{"color":729,"icon":730},[10,3171,3172],{},"To keep the example simple, the form only disables the submit button while it is busy.",[10,3174,3175],{},"Handle the submit event by calling the mutation:",[47,3177,3179],{"className":951,"code":3178,"filename":2633,"language":954,"meta":53,"style":53},"\u003Cscript lang=\"ts\" setup>\n\u002F\u002F ...\n\nfunction onSubmit() {\n  storeComment({ postId: frontmatter.value.id, content: content.value })\n}\n\u003C\u002Fscript>\n",[42,3180,3181,3197,3203,3207,3218,3226,3230],{"__ignoreMap":53},[57,3182,3183,3185,3187,3189,3191,3193,3195],{"class":59,"line":60},[57,3184,579],{"class":102},[57,3186,964],{"class":963},[57,3188,967],{"class":63},[57,3190,559],{"class":102},[57,3192,972],{"class":71},[57,3194,1171],{"class":63},[57,3196,975],{"class":102},[57,3198,3199],{"class":59,"line":119},[57,3200,3202],{"class":3201},"sCsY4","\u002F\u002F ...\n",[57,3204,3205],{"class":59,"line":141},[57,3206,150],{"emptyLinePlaceholder":22},[57,3208,3209,3212,3215],{"class":59,"line":147},[57,3210,3211],{"class":92},"function",[57,3213,3214],{"class":63}," onSubmit",[57,3216,3217],{"class":102},"() {\n",[57,3219,3220,3223],{"class":59,"line":153},[57,3221,3222],{"class":63},"  storeComment",[57,3224,3225],{"class":102},"({ postId: frontmatter.value.id, content: content.value })\n",[57,3227,3228],{"class":59,"line":184},[57,3229,144],{"class":102},[57,3231,3232,3234,3236],{"class":59,"line":202},[57,3233,1148],{"class":102},[57,3235,964],{"class":963},[57,3237,975],{"class":102},[727,3239,3240],{"color":729,"icon":730},[10,3241,3242],{},"I know this form will eventually create and edit comments, so I am designing it for both cases now. That avoids duplicated code, as the next section will demonstrate.",[10,3244,3245],{},"The complete form looks like this:",[47,3247,3249],{"className":951,"code":3248,"filename":2633,"language":954,"meta":53,"style":53},"\u003Cscript lang=\"ts\">\nimport type { Comment } from '@\u002Fcomments\u002Ftypes\u002Fcomment'\n\nconst commentForm = tv({\n  slots: {\n    base: 'flex flex-col gap-4',\n    textarea:\n      'border-4 border-black px-8 py-4 shadow-[4px_4px_0_black] focus:outline-none',\n    button: '',\n  },\n})\n\nexport interface CommentFormProps {\n  comment?: Comment\n  class?: any\n  ui?: Partial\u003Ctypeof commentForm.slots>\n}\nexport interface CommentFormEmits {\n  submit: [void]\n}\nexport interface CommentFormSlots {}\n\u003C\u002Fscript>\n\n\u003Cscript lang=\"ts\" setup>\nconst props = defineProps\u003CCommentFormProps>()\nconst emit = defineEmits\u003CCommentFormEmits>()\ndefineSlots\u003CCommentFormSlots>()\n\nconst { frontmatter } = useData()\nconst queryCache = useQueryCache()\n\nconst content = ref(props.comment?.content ?? '')\n\nconst {\n  mutate: storeComment,\n  isLoading,\n  error,\n} = useMutation\u003C\n  {\n    data: Comment\n  },\n  { postId: number, content: string, parentId?: number },\n  {\n    data: {\n      message: string\n      errors: {\n        content: string[]\n      }\n    }\n  }\n>({\n  mutation: ({ postId, content }) => postComment(postId, content),\n  onSuccess: () => {\n    content.value = ''\n  },\n  onSettled: () =>\n    queryCache.invalidateQueries({\n      key: ['comments', frontmatter.value.id],\n      exact: true,\n    }),\n})\n\nfunction onSubmit() {\n  storeComment({ postId: frontmatter.value.id, content: content.value })\n}\n\nconst ui = computed(() => commentForm())\n\u003C\u002Fscript>\n\n\u003Ctemplate>\n  \u003Cform\n    :class=\"ui.base({ class: [props.class, props.ui?.base] })\"\n    @submit.prevent=\"onSubmit\"\n  >\n    \u003Ctextarea\n      v-model=\"content\"\n      placeholder=\"Write a comment...\"\n      :class=\"ui.textarea({ class: props.ui?.textarea })\"\n    \u002F>\n\n    \u003Cspan v-if=\"error\" class=\"text-red-500\">{{ error.data.message }}\u003C\u002Fspan>\n\n    \u003CButton\n      type=\"submit\"\n      label=\"Comment\"\n      :class=\"ui.button({ class: props.ui?.button })\"\n      :disabled=\"isLoading\"\n    \u002F>\n  \u003C\u002Fform>\n\u003C\u002Ftemplate>\n",[42,3250,3251,3265,3277,3281,3294,3298,3307,3312,3319,3328,3332,3336,3340,3351,3359,3367,3382,3386,3397,3412,3416,3427,3435,3439,3455,3472,3491,3502,3506,3522,3534,3538,3559,3563,3569,3579,3585,3591,3601,3605,3611,3615,3631,3635,3641,3647,3653,3659,3663,3667,3671,3677,3697,3707,3715,3720,3729,3738,3747,3756,3761,3766,3771,3780,3787,3792,3797,3816,3825,3830,3839,3846,3855,3864,3869,3876,3885,3894,3903,3910,3915,3940,3945,3952,3961,3970,3989,4004,4009,4018],{"__ignoreMap":53},[57,3252,3253,3255,3257,3259,3261,3263],{"class":59,"line":60},[57,3254,579],{"class":102},[57,3256,964],{"class":963},[57,3258,967],{"class":63},[57,3260,559],{"class":102},[57,3262,972],{"class":71},[57,3264,975],{"class":102},[57,3266,3267,3269,3271,3273,3275],{"class":59,"line":119},[57,3268,438],{"class":92},[57,3270,441],{"class":92},[57,3272,984],{"class":102},[57,3274,447],{"class":92},[57,3276,989],{"class":71},[57,3278,3279],{"class":59,"line":141},[57,3280,150],{"emptyLinePlaceholder":22},[57,3282,3283,3285,3288,3290,3292],{"class":59,"line":147},[57,3284,998],{"class":92},[57,3286,3287],{"class":67}," commentForm",[57,3289,531],{"class":92},[57,3291,1006],{"class":63},[57,3293,1009],{"class":102},[57,3295,3296],{"class":59,"line":153},[57,3297,1014],{"class":102},[57,3299,3300,3302,3305],{"class":59,"line":184},[57,3301,1019],{"class":102},[57,3303,3304],{"class":71},"'flex flex-col gap-4'",[57,3306,211],{"class":102},[57,3308,3309],{"class":59,"line":202},[57,3310,3311],{"class":102},"    textarea:\n",[57,3313,3314,3317],{"class":59,"line":214},[57,3315,3316],{"class":71},"      'border-4 border-black px-8 py-4 shadow-[4px_4px_0_black] focus:outline-none'",[57,3318,211],{"class":102},[57,3320,3321,3324,3326],{"class":59,"line":220},[57,3322,3323],{"class":102},"    button: ",[57,3325,1032],{"class":71},[57,3327,211],{"class":102},[57,3329,3330],{"class":59,"line":226},[57,3331,1059],{"class":102},[57,3333,3334],{"class":59,"line":231},[57,3335,664],{"class":102},[57,3337,3338],{"class":59,"line":236},[57,3339,150],{"emptyLinePlaceholder":22},[57,3341,3342,3344,3346,3349],{"class":59,"line":265},[57,3343,93],{"class":92},[57,3345,461],{"class":92},[57,3347,3348],{"class":63}," CommentFormProps",[57,3350,467],{"class":102},[57,3352,3353,3355,3357],{"class":59,"line":284},[57,3354,1083],{"class":106},[57,3356,1096],{"class":92},[57,3358,1088],{"class":63},[57,3360,3361,3363,3365],{"class":59,"line":294},[57,3362,1093],{"class":106},[57,3364,1096],{"class":92},[57,3366,1099],{"class":67},[57,3368,3369,3371,3373,3375,3377,3379],{"class":59,"line":299},[57,3370,1104],{"class":106},[57,3372,1096],{"class":92},[57,3374,1109],{"class":63},[57,3376,579],{"class":102},[57,3378,644],{"class":92},[57,3380,3381],{"class":102}," commentForm.slots>\n",[57,3383,3384],{"class":59,"line":304},[57,3385,144],{"class":102},[57,3387,3388,3390,3392,3395],{"class":59,"line":309},[57,3389,93],{"class":92},[57,3391,461],{"class":92},[57,3393,3394],{"class":63}," CommentFormEmits",[57,3396,467],{"class":102},[57,3398,3399,3402,3404,3406,3409],{"class":59,"line":329},[57,3400,3401],{"class":106},"  submit",[57,3403,110],{"class":92},[57,3405,598],{"class":102},[57,3407,3408],{"class":67},"void",[57,3410,3411],{"class":102},"]\n",[57,3413,3414],{"class":59,"line":346},[57,3415,144],{"class":102},[57,3417,3418,3420,3422,3425],{"class":59,"line":356},[57,3419,93],{"class":92},[57,3421,461],{"class":92},[57,3423,3424],{"class":63}," CommentFormSlots",[57,3426,1132],{"class":102},[57,3428,3429,3431,3433],{"class":59,"line":361},[57,3430,1148],{"class":102},[57,3432,964],{"class":963},[57,3434,975],{"class":102},[57,3436,3437],{"class":59,"line":1176},[57,3438,150],{"emptyLinePlaceholder":22},[57,3440,3441,3443,3445,3447,3449,3451,3453],{"class":59,"line":1197},[57,3442,579],{"class":102},[57,3444,964],{"class":963},[57,3446,967],{"class":63},[57,3448,559],{"class":102},[57,3450,972],{"class":71},[57,3452,1171],{"class":63},[57,3454,975],{"class":102},[57,3456,3457,3459,3461,3463,3465,3467,3470],{"class":59,"line":1210},[57,3458,998],{"class":92},[57,3460,1181],{"class":67},[57,3462,531],{"class":92},[57,3464,1186],{"class":63},[57,3466,579],{"class":102},[57,3468,3469],{"class":63},"CommentFormProps",[57,3471,1194],{"class":102},[57,3473,3474,3476,3479,3481,3484,3486,3489],{"class":59,"line":1223},[57,3475,998],{"class":92},[57,3477,3478],{"class":67}," emit",[57,3480,531],{"class":92},[57,3482,3483],{"class":63}," defineEmits",[57,3485,579],{"class":102},[57,3487,3488],{"class":63},"CommentFormEmits",[57,3490,1194],{"class":102},[57,3492,3493,3495,3497,3500],{"class":59,"line":1228},[57,3494,1213],{"class":63},[57,3496,579],{"class":102},[57,3498,3499],{"class":63},"CommentFormSlots",[57,3501,1194],{"class":102},[57,3503,3504],{"class":59,"line":1253},[57,3505,150],{"emptyLinePlaceholder":22},[57,3507,3508,3510,3512,3514,3516,3518,3520],{"class":59,"line":1258},[57,3509,998],{"class":92},[57,3511,550],{"class":102},[57,3513,553],{"class":67},[57,3515,556],{"class":102},[57,3517,559],{"class":92},[57,3519,562],{"class":63},[57,3521,565],{"class":102},[57,3523,3524,3526,3528,3530,3532],{"class":59,"line":1278},[57,3525,998],{"class":92},[57,3527,2888],{"class":67},[57,3529,531],{"class":92},[57,3531,2893],{"class":63},[57,3533,565],{"class":102},[57,3535,3536],{"class":59,"line":1283},[57,3537,150],{"emptyLinePlaceholder":22},[57,3539,3540,3542,3544,3546,3548,3551,3554,3557],{"class":59,"line":1305},[57,3541,998],{"class":92},[57,3543,2906],{"class":67},[57,3545,531],{"class":92},[57,3547,1268],{"class":63},[57,3549,3550],{"class":102},"(props.comment?.content ",[57,3552,3553],{"class":92},"??",[57,3555,3556],{"class":71}," ''",[57,3558,138],{"class":102},[57,3560,3561],{"class":59,"line":1314},[57,3562,150],{"emptyLinePlaceholder":22},[57,3564,3565,3567],{"class":59,"line":1319},[57,3566,998],{"class":92},[57,3568,467],{"class":102},[57,3570,3571,3573,3575,3577],{"class":59,"line":1329},[57,3572,2931],{"class":106},[57,3574,1238],{"class":102},[57,3576,2936],{"class":67},[57,3578,211],{"class":102},[57,3580,3581,3583],{"class":59,"line":1348},[57,3582,2943],{"class":67},[57,3584,211],{"class":102},[57,3586,3587,3589],{"class":59,"line":1358},[57,3588,2950],{"class":67},[57,3590,211],{"class":102},[57,3592,3593,3595,3597,3599],{"class":59,"line":1364},[57,3594,2957],{"class":102},[57,3596,559],{"class":92},[57,3598,2962],{"class":102},[57,3600,2965],{"class":92},[57,3602,3603],{"class":59,"line":1374},[57,3604,2970],{"class":102},[57,3606,3607,3609],{"class":59,"line":1379},[57,3608,2975],{"class":63},[57,3610,2978],{"class":102},[57,3612,3613],{"class":59,"line":1396},[57,3614,1059],{"class":102},[57,3616,3617,3619,3621,3623,3625,3627,3629],{"class":59,"line":1405},[57,3618,2987],{"class":102},[57,3620,107],{"class":63},[57,3622,2992],{"class":102},[57,3624,174],{"class":63},[57,3626,2997],{"class":102},[57,3628,1096],{"class":92},[57,3630,3002],{"class":102},[57,3632,3633],{"class":59,"line":1416},[57,3634,2970],{"class":102},[57,3636,3637,3639],{"class":59,"line":1426},[57,3638,2975],{"class":63},[57,3640,3013],{"class":102},[57,3642,3643,3645],{"class":59,"line":1437},[57,3644,3018],{"class":63},[57,3646,3021],{"class":102},[57,3648,3649,3651],{"class":59,"line":1443},[57,3650,3026],{"class":63},[57,3652,3013],{"class":102},[57,3654,3655,3657],{"class":59,"line":1465},[57,3656,3033],{"class":63},[57,3658,3036],{"class":102},[57,3660,3661],{"class":59,"line":1471},[57,3662,3041],{"class":102},[57,3664,3665],{"class":59,"line":1481},[57,3666,804],{"class":102},[57,3668,3669],{"class":59,"line":1493},[57,3670,3050],{"class":102},[57,3672,3673,3675],{"class":59,"line":1499},[57,3674,3055],{"class":92},[57,3676,1009],{"class":102},[57,3678,3679,3681,3683,3685,3687,3689,3691,3693,3695],{"class":59,"line":1508},[57,3680,3062],{"class":63},[57,3682,3065],{"class":102},[57,3684,107],{"class":106},[57,3686,171],{"class":102},[57,3688,174],{"class":106},[57,3690,3074],{"class":102},[57,3692,540],{"class":92},[57,3694,160],{"class":63},[57,3696,3081],{"class":102},[57,3698,3699,3701,3703,3705],{"class":59,"line":1517},[57,3700,3086],{"class":63},[57,3702,593],{"class":102},[57,3704,540],{"class":92},[57,3706,467],{"class":102},[57,3708,3709,3711,3713],{"class":59,"line":1527},[57,3710,3097],{"class":102},[57,3712,559],{"class":92},[57,3714,3102],{"class":71},[57,3716,3718],{"class":59,"line":3717},55,[57,3719,1059],{"class":102},[57,3721,3723,3725,3727],{"class":59,"line":3722},56,[57,3724,3111],{"class":63},[57,3726,593],{"class":102},[57,3728,614],{"class":92},[57,3730,3732,3734,3736],{"class":59,"line":3731},57,[57,3733,3120],{"class":102},[57,3735,3123],{"class":63},[57,3737,1009],{"class":102},[57,3739,3741,3743,3745],{"class":59,"line":3740},58,[57,3742,3130],{"class":102},[57,3744,601],{"class":71},[57,3746,604],{"class":102},[57,3748,3750,3752,3754],{"class":59,"line":3749},59,[57,3751,3139],{"class":102},[57,3753,3142],{"class":67},[57,3755,211],{"class":102},[57,3757,3759],{"class":59,"line":3758},60,[57,3760,3149],{"class":102},[57,3762,3764],{"class":59,"line":3763},61,[57,3765,664],{"class":102},[57,3767,3769],{"class":59,"line":3768},62,[57,3770,150],{"emptyLinePlaceholder":22},[57,3772,3774,3776,3778],{"class":59,"line":3773},63,[57,3775,3211],{"class":92},[57,3777,3214],{"class":63},[57,3779,3217],{"class":102},[57,3781,3783,3785],{"class":59,"line":3782},64,[57,3784,3222],{"class":63},[57,3786,3225],{"class":102},[57,3788,3790],{"class":59,"line":3789},65,[57,3791,144],{"class":102},[57,3793,3795],{"class":59,"line":3794},66,[57,3796,150],{"emptyLinePlaceholder":22},[57,3798,3800,3802,3804,3806,3808,3810,3812,3814],{"class":59,"line":3799},67,[57,3801,998],{"class":92},[57,3803,1288],{"class":67},[57,3805,531],{"class":92},[57,3807,1293],{"class":63},[57,3809,537],{"class":102},[57,3811,540],{"class":92},[57,3813,3287],{"class":63},[57,3815,1302],{"class":102},[57,3817,3819,3821,3823],{"class":59,"line":3818},68,[57,3820,1148],{"class":102},[57,3822,964],{"class":963},[57,3824,975],{"class":102},[57,3826,3828],{"class":59,"line":3827},69,[57,3829,150],{"emptyLinePlaceholder":22},[57,3831,3833,3835,3837],{"class":59,"line":3832},70,[57,3834,579],{"class":102},[57,3836,1324],{"class":963},[57,3838,975],{"class":102},[57,3840,3842,3844],{"class":59,"line":3841},71,[57,3843,1332],{"class":102},[57,3845,2650],{"class":963},[57,3847,3849,3851,3853],{"class":59,"line":3848},72,[57,3850,2655],{"class":63},[57,3852,559],{"class":102},[57,3854,2660],{"class":71},[57,3856,3858,3860,3862],{"class":59,"line":3857},73,[57,3859,2665],{"class":63},[57,3861,559],{"class":102},[57,3863,2670],{"class":71},[57,3865,3867],{"class":59,"line":3866},74,[57,3868,2675],{"class":102},[57,3870,3872,3874],{"class":59,"line":3871},75,[57,3873,1351],{"class":102},[57,3875,2682],{"class":963},[57,3877,3879,3881,3883],{"class":59,"line":3878},76,[57,3880,2687],{"class":63},[57,3882,559],{"class":102},[57,3884,2692],{"class":71},[57,3886,3888,3890,3892],{"class":59,"line":3887},77,[57,3889,2697],{"class":63},[57,3891,559],{"class":102},[57,3893,2702],{"class":71},[57,3895,3897,3899,3901],{"class":59,"line":3896},78,[57,3898,1841],{"class":63},[57,3900,559],{"class":102},[57,3902,2711],{"class":71},[57,3904,3906,3908],{"class":59,"line":3905},79,[57,3907,2717],{"class":2716},[57,3909,975],{"class":102},[57,3911,3913],{"class":59,"line":3912},80,[57,3914,150],{"emptyLinePlaceholder":22},[57,3916,3918,3920,3922,3924,3926,3928,3930,3932,3934,3936,3938],{"class":59,"line":3917},81,[57,3919,1351],{"class":102},[57,3921,57],{"class":963},[57,3923,1450],{"class":63},[57,3925,559],{"class":102},[57,3927,2736],{"class":71},[57,3929,2739],{"class":63},[57,3931,559],{"class":102},[57,3933,2744],{"class":71},[57,3935,2747],{"class":102},[57,3937,57],{"class":963},[57,3939,975],{"class":102},[57,3941,3943],{"class":59,"line":3942},82,[57,3944,150],{"emptyLinePlaceholder":22},[57,3946,3948,3950],{"class":59,"line":3947},83,[57,3949,1351],{"class":102},[57,3951,2762],{"class":963},[57,3953,3955,3957,3959],{"class":59,"line":3954},84,[57,3956,2767],{"class":63},[57,3958,559],{"class":102},[57,3960,2772],{"class":71},[57,3962,3964,3966,3968],{"class":59,"line":3963},85,[57,3965,2777],{"class":63},[57,3967,559],{"class":102},[57,3969,2782],{"class":71},[57,3971,3973,3975,3977,3979,3981,3983,3985,3987],{"class":59,"line":3972},86,[57,3974,2787],{"class":102},[57,3976,2386],{"class":63},[57,3978,559],{"class":102},[57,3980,1455],{"class":71},[57,3982,2393],{"class":102},[57,3984,2798],{"class":63},[57,3986,2801],{"class":102},[57,3988,2379],{"class":71},[57,3990,3992,3994,3996,3998,4000,4002],{"class":59,"line":3991},87,[57,3993,2787],{"class":102},[57,3995,2810],{"class":63},[57,3997,559],{"class":102},[57,3999,1455],{"class":71},[57,4001,2817],{"class":102},[57,4003,2379],{"class":71},[57,4005,4007],{"class":59,"line":4006},88,[57,4008,2824],{"class":102},[57,4010,4012,4014,4016],{"class":59,"line":4011},89,[57,4013,1520],{"class":102},[57,4015,2831],{"class":963},[57,4017,975],{"class":102},[57,4019,4021,4023,4025],{"class":59,"line":4020},90,[57,4022,1148],{"class":102},[57,4024,1324],{"class":963},[57,4026,975],{"class":102},[10,4028,4029,4030,4033],{},"Place the form in an ",[42,4031,4032],{},"AddComment.vue"," component with a title. Show the form only to authenticated users so visitors do not see a control they cannot use:",[47,4035,4038],{"className":951,"code":4036,"filename":4037,"language":954,"meta":53,"style":53},"\u003Cscript lang=\"ts\">\nconst addComment = tv({\n  slots: {\n    base: 'space-y-4',\n    header: 'flex items-center gap-2',\n    avatar: 'size-8 rounded-full',\n    title: 'text-lg font-semibold',\n  },\n})\n\nexport interface AddCommentProps {\n  class?: any\n  ui?: Partial\u003Ctypeof addComment.slots>\n}\nexport interface AddCommentEmits {}\nexport interface AddCommentSlots {}\n\u003C\u002Fscript>\n\n\u003Cscript lang=\"ts\" setup>\nconst props = defineProps\u003CAddCommentProps>()\ndefineEmits\u003CAddCommentEmits>()\ndefineSlots\u003CAddCommentSlots>()\n\nconst { state: userState } = useUser()\n\nconst loginUrl = `${import.meta.env.VITE_API_URL}\u002Fauth\u002Fgithub\u002Fredirect`\n\nconst ui = computed(() => addComment())\n\u003C\u002Fscript>\n\n\u003Ctemplate>\n  \u003Cdiv :class=\"ui.base({ class: [props.class, props.ui?.base] })\">\n    \u003Cdiv :class=\"ui.header({ class: props.ui?.header })\">\n      \u003Cimg\n        v-if=\"userState.data && userState.data.avatar\"\n        :src=\"userState.data.avatar\"\n        :class=\"ui.avatar({ class: props.ui?.avatar })\"\n      >\n      \u003Ch3 :class=\"ui.title({ class: props.ui?.title })\">\n        Add a comment\n      \u003C\u002Fh3>\n    \u003C\u002Fdiv>\n\n    \u003CCommentForm v-if=\"userState.data\" \u002F>\n    \u003Cdiv v-else class=\"flex justify-center\">\n      \u003CButton label=\"Login to comment\" :href=\"loginUrl\" \u002F>\n    \u003C\u002Fdiv>\n  \u003C\u002Fdiv>\n\u003C\u002Ftemplate>\n",".vitepress\u002Ftheme\u002Fcomments\u002Fcomponents\u002FAddComment.vue",[42,4039,4040,4054,4067,4071,4079,4089,4098,4107,4111,4115,4119,4130,4138,4153,4157,4168,4179,4187,4191,4207,4224,4235,4246,4250,4272,4276,4308,4312,4330,4338,4342,4350,4364,4379,4385,4394,4403,4412,4416,4431,4436,4444,4452,4456,4476,4493,4524,4532,4540],{"__ignoreMap":53},[57,4041,4042,4044,4046,4048,4050,4052],{"class":59,"line":60},[57,4043,579],{"class":102},[57,4045,964],{"class":963},[57,4047,967],{"class":63},[57,4049,559],{"class":102},[57,4051,972],{"class":71},[57,4053,975],{"class":102},[57,4055,4056,4058,4061,4063,4065],{"class":59,"line":119},[57,4057,998],{"class":92},[57,4059,4060],{"class":67}," addComment",[57,4062,531],{"class":92},[57,4064,1006],{"class":63},[57,4066,1009],{"class":102},[57,4068,4069],{"class":59,"line":141},[57,4070,1014],{"class":102},[57,4072,4073,4075,4077],{"class":59,"line":147},[57,4074,1019],{"class":102},[57,4076,1022],{"class":71},[57,4078,211],{"class":102},[57,4080,4081,4084,4087],{"class":59,"line":153},[57,4082,4083],{"class":102},"    header: ",[57,4085,4086],{"class":71},"'flex items-center gap-2'",[57,4088,211],{"class":102},[57,4090,4091,4094,4096],{"class":59,"line":184},[57,4092,4093],{"class":102},"    avatar: ",[57,4095,1052],{"class":71},[57,4097,211],{"class":102},[57,4099,4100,4102,4105],{"class":59,"line":202},[57,4101,2012],{"class":102},[57,4103,4104],{"class":71},"'text-lg font-semibold'",[57,4106,211],{"class":102},[57,4108,4109],{"class":59,"line":214},[57,4110,1059],{"class":102},[57,4112,4113],{"class":59,"line":220},[57,4114,664],{"class":102},[57,4116,4117],{"class":59,"line":226},[57,4118,150],{"emptyLinePlaceholder":22},[57,4120,4121,4123,4125,4128],{"class":59,"line":231},[57,4122,93],{"class":92},[57,4124,461],{"class":92},[57,4126,4127],{"class":63}," AddCommentProps",[57,4129,467],{"class":102},[57,4131,4132,4134,4136],{"class":59,"line":236},[57,4133,1093],{"class":106},[57,4135,1096],{"class":92},[57,4137,1099],{"class":67},[57,4139,4140,4142,4144,4146,4148,4150],{"class":59,"line":265},[57,4141,1104],{"class":106},[57,4143,1096],{"class":92},[57,4145,1109],{"class":63},[57,4147,579],{"class":102},[57,4149,644],{"class":92},[57,4151,4152],{"class":102}," addComment.slots>\n",[57,4154,4155],{"class":59,"line":284},[57,4156,144],{"class":102},[57,4158,4159,4161,4163,4166],{"class":59,"line":294},[57,4160,93],{"class":92},[57,4162,461],{"class":92},[57,4164,4165],{"class":63}," AddCommentEmits",[57,4167,1132],{"class":102},[57,4169,4170,4172,4174,4177],{"class":59,"line":299},[57,4171,93],{"class":92},[57,4173,461],{"class":92},[57,4175,4176],{"class":63}," AddCommentSlots",[57,4178,1132],{"class":102},[57,4180,4181,4183,4185],{"class":59,"line":304},[57,4182,1148],{"class":102},[57,4184,964],{"class":963},[57,4186,975],{"class":102},[57,4188,4189],{"class":59,"line":309},[57,4190,150],{"emptyLinePlaceholder":22},[57,4192,4193,4195,4197,4199,4201,4203,4205],{"class":59,"line":329},[57,4194,579],{"class":102},[57,4196,964],{"class":963},[57,4198,967],{"class":63},[57,4200,559],{"class":102},[57,4202,972],{"class":71},[57,4204,1171],{"class":63},[57,4206,975],{"class":102},[57,4208,4209,4211,4213,4215,4217,4219,4222],{"class":59,"line":346},[57,4210,998],{"class":92},[57,4212,1181],{"class":67},[57,4214,531],{"class":92},[57,4216,1186],{"class":63},[57,4218,579],{"class":102},[57,4220,4221],{"class":63},"AddCommentProps",[57,4223,1194],{"class":102},[57,4225,4226,4228,4230,4233],{"class":59,"line":356},[57,4227,1200],{"class":63},[57,4229,579],{"class":102},[57,4231,4232],{"class":63},"AddCommentEmits",[57,4234,1194],{"class":102},[57,4236,4237,4239,4241,4244],{"class":59,"line":361},[57,4238,1213],{"class":63},[57,4240,579],{"class":102},[57,4242,4243],{"class":63},"AddCommentSlots",[57,4245,1194],{"class":102},[57,4247,4248],{"class":59,"line":1176},[57,4249,150],{"emptyLinePlaceholder":22},[57,4251,4252,4254,4256,4258,4260,4263,4265,4267,4270],{"class":59,"line":1197},[57,4253,998],{"class":92},[57,4255,550],{"class":102},[57,4257,2180],{"class":106},[57,4259,1238],{"class":102},[57,4261,4262],{"class":67},"userState",[57,4264,556],{"class":102},[57,4266,559],{"class":92},[57,4268,4269],{"class":63}," useUser",[57,4271,565],{"class":102},[57,4273,4274],{"class":59,"line":1210},[57,4275,150],{"emptyLinePlaceholder":22},[57,4277,4278,4280,4283,4285,4288,4290,4292,4295,4297,4300,4302,4305],{"class":59,"line":1223},[57,4279,998],{"class":92},[57,4281,4282],{"class":67}," loginUrl",[57,4284,531],{"class":92},[57,4286,4287],{"class":71}," `${",[57,4289,438],{"class":92},[57,4291,417],{"class":71},[57,4293,4294],{"class":67},"meta",[57,4296,417],{"class":71},[57,4298,4299],{"class":102},"env",[57,4301,417],{"class":71},[57,4303,4304],{"class":67},"VITE_API_URL",[57,4306,4307],{"class":71},"}\u002Fauth\u002Fgithub\u002Fredirect`\n",[57,4309,4310],{"class":59,"line":1228},[57,4311,150],{"emptyLinePlaceholder":22},[57,4313,4314,4316,4318,4320,4322,4324,4326,4328],{"class":59,"line":1253},[57,4315,998],{"class":92},[57,4317,1288],{"class":67},[57,4319,531],{"class":92},[57,4321,1293],{"class":63},[57,4323,537],{"class":102},[57,4325,540],{"class":92},[57,4327,4060],{"class":63},[57,4329,1302],{"class":102},[57,4331,4332,4334,4336],{"class":59,"line":1258},[57,4333,1148],{"class":102},[57,4335,964],{"class":963},[57,4337,975],{"class":102},[57,4339,4340],{"class":59,"line":1278},[57,4341,150],{"emptyLinePlaceholder":22},[57,4343,4344,4346,4348],{"class":59,"line":1283},[57,4345,579],{"class":102},[57,4347,1324],{"class":963},[57,4349,975],{"class":102},[57,4351,4352,4354,4356,4358,4360,4362],{"class":59,"line":1305},[57,4353,1332],{"class":102},[57,4355,1384],{"class":963},[57,4357,1338],{"class":63},[57,4359,559],{"class":102},[57,4361,1343],{"class":71},[57,4363,975],{"class":102},[57,4365,4366,4368,4370,4372,4374,4377],{"class":59,"line":1314},[57,4367,1351],{"class":102},[57,4369,1384],{"class":963},[57,4371,1338],{"class":63},[57,4373,559],{"class":102},[57,4375,4376],{"class":71},"\"ui.header({ class: props.ui?.header })\"",[57,4378,975],{"class":102},[57,4380,4381,4383],{"class":59,"line":1319},[57,4382,1399],{"class":102},[57,4384,1402],{"class":963},[57,4386,4387,4389,4391],{"class":59,"line":1329},[57,4388,1408],{"class":63},[57,4390,559],{"class":102},[57,4392,4393],{"class":71},"\"userState.data && userState.data.avatar\"\n",[57,4395,4396,4398,4400],{"class":59,"line":1348},[57,4397,1419],{"class":63},[57,4399,559],{"class":102},[57,4401,4402],{"class":71},"\"userState.data.avatar\"\n",[57,4404,4405,4407,4409],{"class":59,"line":1358},[57,4406,1429],{"class":63},[57,4408,559],{"class":102},[57,4410,4411],{"class":71},"\"ui.avatar({ class: props.ui?.avatar })\"\n",[57,4413,4414],{"class":59,"line":1364},[57,4415,1440],{"class":102},[57,4417,4418,4420,4423,4425,4427,4429],{"class":59,"line":1374},[57,4419,1399],{"class":102},[57,4421,4422],{"class":963},"h3",[57,4424,1338],{"class":63},[57,4426,559],{"class":102},[57,4428,2264],{"class":71},[57,4430,975],{"class":102},[57,4432,4433],{"class":59,"line":1379},[57,4434,4435],{"class":102},"        Add a comment\n",[57,4437,4438,4440,4442],{"class":59,"line":1396},[57,4439,1474],{"class":102},[57,4441,4422],{"class":963},[57,4443,975],{"class":102},[57,4445,4446,4448,4450],{"class":59,"line":1405},[57,4447,1367],{"class":102},[57,4449,1384],{"class":963},[57,4451,975],{"class":102},[57,4453,4454],{"class":59,"line":1416},[57,4455,150],{"emptyLinePlaceholder":22},[57,4457,4458,4460,4463,4465,4467,4469,4472,4474],{"class":59,"line":1426},[57,4459,1351],{"class":102},[57,4461,4462],{"class":963},"CommentForm",[57,4464,1450],{"class":92},[57,4466,559],{"class":102},[57,4468,1455],{"class":71},[57,4470,4471],{"class":102},"userState.data",[57,4473,1455],{"class":71},[57,4475,1922],{"class":102},[57,4477,4478,4480,4482,4484,4486,4488,4491],{"class":59,"line":1437},[57,4479,1351],{"class":102},[57,4481,1384],{"class":963},[57,4483,1488],{"class":63},[57,4485,2739],{"class":63},[57,4487,559],{"class":102},[57,4489,4490],{"class":71},"\"flex justify-center\"",[57,4492,975],{"class":102},[57,4494,4495,4497,4500,4503,4505,4508,4510,4513,4515,4517,4520,4522],{"class":59,"line":1443},[57,4496,1399],{"class":102},[57,4498,4499],{"class":963},"Button",[57,4501,4502],{"class":63}," label",[57,4504,559],{"class":102},[57,4506,4507],{"class":71},"\"Login to comment\"",[57,4509,1908],{"class":102},[57,4511,4512],{"class":63},"href",[57,4514,559],{"class":102},[57,4516,1455],{"class":71},[57,4518,4519],{"class":102},"loginUrl",[57,4521,1455],{"class":71},[57,4523,1922],{"class":102},[57,4525,4526,4528,4530],{"class":59,"line":1465},[57,4527,1367],{"class":102},[57,4529,1384],{"class":963},[57,4531,975],{"class":102},[57,4533,4534,4536,4538],{"class":59,"line":1471},[57,4535,1520],{"class":102},[57,4537,1384],{"class":963},[57,4539,975],{"class":102},[57,4541,4542,4544,4546],{"class":59,"line":1481},[57,4543,1148],{"class":102},[57,4545,1324],{"class":963},[57,4547,975],{"class":102},[10,4549,4550,4551,4554],{},"Unauthenticated users see a button that redirects them to GitHub. We use ",[42,4552,4553],{},"useUser"," here just as we did in the header. Pinia Colada deduplicates the request and shares the result, so we do not need prop drilling or a high-level fetch far from where the data is used.",[10,4556,4557,4558,2437,4561,4563],{},"Finally, use ",[42,4559,4560],{},"AddComment",[42,4562,942],{}," below the list:",[47,4565,4567],{"className":951,"code":4566,"filename":1965,"language":954,"meta":53,"style":53},"\u003Ctemplate>\n  \u003Csection :class=\"ui.base({ class: [props.class, props.ui?.base] })\">\n    \u003C!-- ... -->\n\n    \u003C!-- eslint-disable-next-line vue\u002Fvalid-v-else -->\n    \u003Ctemplate v-else>\n      \u003C!-- ... -->\n\n      \u003CAddComment \u002F>\n    \u003C\u002Ftemplate>\n  \u003C\u002Fsection>\n\u003C\u002Ftemplate>\n",[42,4568,4569,4577,4591,4596,4600,4605,4615,4620,4624,4632,4640,4648],{"__ignoreMap":53},[57,4570,4571,4573,4575],{"class":59,"line":60},[57,4572,579],{"class":102},[57,4574,1324],{"class":963},[57,4576,975],{"class":102},[57,4578,4579,4581,4583,4585,4587,4589],{"class":59,"line":119},[57,4580,1332],{"class":102},[57,4582,2243],{"class":963},[57,4584,1338],{"class":63},[57,4586,559],{"class":102},[57,4588,1343],{"class":71},[57,4590,975],{"class":102},[57,4592,4593],{"class":59,"line":141},[57,4594,4595],{"class":3201},"    \u003C!-- ... -->\n",[57,4597,4598],{"class":59,"line":147},[57,4599,150],{"emptyLinePlaceholder":22},[57,4601,4602],{"class":59,"line":153},[57,4603,4604],{"class":3201},"    \u003C!-- eslint-disable-next-line vue\u002Fvalid-v-else -->\n",[57,4606,4607,4609,4611,4613],{"class":59,"line":184},[57,4608,1351],{"class":102},[57,4610,1324],{"class":963},[57,4612,1488],{"class":92},[57,4614,975],{"class":102},[57,4616,4617],{"class":59,"line":202},[57,4618,4619],{"class":3201},"      \u003C!-- ... -->\n",[57,4621,4622],{"class":59,"line":214},[57,4623,150],{"emptyLinePlaceholder":22},[57,4625,4626,4628,4630],{"class":59,"line":220},[57,4627,1399],{"class":102},[57,4629,4560],{"class":963},[57,4631,1922],{"class":102},[57,4633,4634,4636,4638],{"class":59,"line":226},[57,4635,1367],{"class":102},[57,4637,1324],{"class":963},[57,4639,975],{"class":102},[57,4641,4642,4644,4646],{"class":59,"line":231},[57,4643,1520],{"class":102},[57,4645,2243],{"class":963},[57,4647,975],{"class":102},[57,4649,4650,4652,4654],{"class":59,"line":236},[57,4651,1148],{"class":102},[57,4653,1324],{"class":963},[57,4655,975],{"class":102},[34,4657,4659],{"id":4658},"editing-a-comment","Editing a comment",[10,4661,4662],{},"Users should be able to edit their own comments, so we need to handle that state in the interface.",[10,4664,4665,4666,4669],{},"How do we know which comments the current user may edit? The backend uses ",[42,4667,4668],{},"CommentPolicy"," for that decision. The frontend should not display an edit button when the policy denies access.",[10,4671,4672],{},"We could duplicate the policy in the frontend, but that would create two sources of truth. Any backend policy change would then require a matching frontend change, and that duplication would become harder to maintain as the policy grows.",[10,4674,4675,4676,4679],{},"Instead, return a ",[42,4677,4678],{},"can"," property with each comment. The backend can populate it by reusing the policy, giving the frontend the permissions it needs without duplicating the rules.",[10,4681,4682],{},"In the backend, we already check if the user is allowed to edit or delete a comment in the controller:",[47,4684,4687],{"className":369,"code":4685,"filename":4686,"language":372,"meta":53,"style":53},"final class CommentController extends Controller\n{\n    public function destroy(Comment $comment): Response\n    {\n        Gate::authorize('delete', $comment); \u002F\u002F [!code highlight]\n    }\n}\n","app\u002FHttp\u002FControllers\u002FApi\u002FCommentController.php",[42,4688,4689,4694,4698,4703,4707,4712,4716],{"__ignoreMap":53},[57,4690,4691],{"class":59,"line":60},[57,4692,4693],{},"final class CommentController extends Controller\n",[57,4695,4696],{"class":59,"line":119},[57,4697,769],{},[57,4699,4700],{"class":59,"line":141},[57,4701,4702],{},"    public function destroy(Comment $comment): Response\n",[57,4704,4705],{"class":59,"line":147},[57,4706,794],{},[57,4708,4709],{"class":59,"line":153},[57,4710,4711],{},"        Gate::authorize('delete', $comment); \u002F\u002F [!code highlight]\n",[57,4713,4714],{"class":59,"line":184},[57,4715,804],{},[57,4717,4718],{"class":59,"line":202},[57,4719,144],{},[10,4721,4722],{},"We also need to expose whether the user may delete the comment, so we will handle both permissions together.",[10,4724,4725,4726,4729,4730,4732],{},"In the ",[42,4727,4728],{},"CommentResource",", we can create a new property called ",[42,4731,4678],{}," that will contain the permissions of the user on the comment:",[47,4734,4738],{"className":4735,"code":4736,"filename":4737,"language":372,"meta":53,"style":53},"language-php shiki shiki-themes github-light github-light github-dark has-highlighted","final class CommentResource extends JsonResource\n{\n    public function toArray(Request $request): array\n    {\n        return [\n            \u002F\u002F ...\n            'can' => [\n                'update' => $request->user()?->can('update', $this->resource) ?? false, \u002F\u002F [!code highlight]\n                'delete' => $request->user()?->can('delete', $this->resource) ?? false, \u002F\u002F [!code highlight]\n            ],\n        ];\n    }\n}\n","app\u002FHttp\u002FResources\u002FCommentResource.php",[42,4739,4740,4745,4749,4754,4758,4763,4768,4773,4779,4785,4790,4795,4799],{"__ignoreMap":53},[57,4741,4742],{"class":59,"line":60},[57,4743,4744],{},"final class CommentResource extends JsonResource\n",[57,4746,4747],{"class":59,"line":119},[57,4748,769],{},[57,4750,4751],{"class":59,"line":141},[57,4752,4753],{},"    public function toArray(Request $request): array\n",[57,4755,4756],{"class":59,"line":147},[57,4757,794],{},[57,4759,4760],{"class":59,"line":153},[57,4761,4762],{},"        return [\n",[57,4764,4765],{"class":59,"line":184},[57,4766,4767],{},"            \u002F\u002F ...\n",[57,4769,4770],{"class":59,"line":202},[57,4771,4772],{},"            'can' => [\n",[57,4774,4776],{"class":4775,"line":214},[59,2173],[57,4777,4778],{},"                'update' => $request->user()?->can('update', $this->resource) ?? false,",[57,4780,4782],{"class":4781,"line":220},[59,2173],[57,4783,4784],{},"                'delete' => $request->user()?->can('delete', $this->resource) ?? false,",[57,4786,4787],{"class":59,"line":226},[57,4788,4789],{},"            ],\n",[57,4791,4792],{"class":59,"line":231},[57,4793,4794],{},"        ];\n",[57,4796,4797],{"class":59,"line":236},[57,4798,804],{},[57,4800,4801],{"class":59,"line":265},[57,4802,144],{},[10,4804,4805],{},"The frontend can now check both permissions. The response will look like this:",[47,4807,4812],{"className":4808,"code":4809,"filename":4810,"language":4811,"meta":53,"style":53},"language-json shiki shiki-themes github-light github-light github-dark has-highlighted","{\n  \"data\": {\n    \"id\": 1,\n    \"content\": \"This is a comment\",\n    \"author\": {\n      \"id\": 1,\n      \"name\": \"John Doe\",\n      \"username\": \"johndoe\",\n      \"avatar\": null\n    },\n    \"can\": {\n      \"update\": true, \u002F\u002F [!code highlight]\n      \"delete\": true \u002F\u002F [!code highlight]\n    }\n  }\n}\n","Example","json",[42,4813,4814,4818,4825,4836,4848,4855,4866,4878,4890,4900,4905,4912,4924,4934,4938,4942],{"__ignoreMap":53},[57,4815,4816],{"class":59,"line":60},[57,4817,769],{"class":102},[57,4819,4820,4823],{"class":59,"line":119},[57,4821,4822],{"class":67},"  \"data\"",[57,4824,3013],{"class":102},[57,4826,4827,4830,4832,4834],{"class":59,"line":141},[57,4828,4829],{"class":67},"    \"id\"",[57,4831,1238],{"class":102},[57,4833,715],{"class":67},[57,4835,211],{"class":102},[57,4837,4838,4841,4843,4846],{"class":59,"line":147},[57,4839,4840],{"class":67},"    \"content\"",[57,4842,1238],{"class":102},[57,4844,4845],{"class":71},"\"This is a comment\"",[57,4847,211],{"class":102},[57,4849,4850,4853],{"class":59,"line":153},[57,4851,4852],{"class":67},"    \"author\"",[57,4854,3013],{"class":102},[57,4856,4857,4860,4862,4864],{"class":59,"line":184},[57,4858,4859],{"class":67},"      \"id\"",[57,4861,1238],{"class":102},[57,4863,715],{"class":67},[57,4865,211],{"class":102},[57,4867,4868,4871,4873,4876],{"class":59,"line":202},[57,4869,4870],{"class":67},"      \"name\"",[57,4872,1238],{"class":102},[57,4874,4875],{"class":71},"\"John Doe\"",[57,4877,211],{"class":102},[57,4879,4880,4883,4885,4888],{"class":59,"line":214},[57,4881,4882],{"class":67},"      \"username\"",[57,4884,1238],{"class":102},[57,4886,4887],{"class":71},"\"johndoe\"",[57,4889,211],{"class":102},[57,4891,4892,4895,4897],{"class":59,"line":220},[57,4893,4894],{"class":67},"      \"avatar\"",[57,4896,1238],{"class":102},[57,4898,4899],{"class":67},"null\n",[57,4901,4902],{"class":59,"line":226},[57,4903,4904],{"class":102},"    },\n",[57,4906,4907,4910],{"class":59,"line":231},[57,4908,4909],{"class":67},"    \"can\"",[57,4911,3013],{"class":102},[57,4913,4915,4918,4920,4922],{"class":4914,"line":236},[59,2173],[57,4916,4917],{"class":67},"      \"update\"",[57,4919,1238],{"class":102},[57,4921,3142],{"class":67},[57,4923,171],{"class":102},[57,4925,4927,4930,4932],{"class":4926,"line":265},[59,2173],[57,4928,4929],{"class":67},"      \"delete\"",[57,4931,1238],{"class":102},[57,4933,3142],{"class":67},[57,4935,4936],{"class":59,"line":284},[57,4937,804],{"class":102},[57,4939,4940],{"class":59,"line":294},[57,4941,3050],{"class":102},[57,4943,4944],{"class":59,"line":299},[57,4945,144],{"class":102},[10,4947,4948,4949,4952],{},"The frontend can use these values in ",[42,4950,4951],{},"v-if"," conditions to display the appropriate actions.",[10,4954,4955,4956,4958],{},"Update the tests to verify that ",[42,4957,4678],{}," is populated correctly.",[47,4960,4963],{"className":369,"code":4961,"filename":4962,"language":372,"meta":53,"style":53},"it('returns the comment', function () {\n    \u002F\u002F ...\n\n    $this->actingAs($user)\n        ->putJson(route('comments.update', $comment), [\n            'content' => 'Updated content',\n        ])\n        ->assertJson(\n            fn (AssertableJson $json) => $json\n                ->has(\n                    'data',\n                    fn (AssertableJson $json) => $json\n                        \u002F\u002F ...\n                        ->has(\n                            'can',\n                            fn (AssertableJson $json) => $json\n                                ->where('update', true) \u002F\u002F [!code highlight]\n                                ->where('delete', true) \u002F\u002F [!code highlight]\n                        )\n                )\n        );\n});\n","tests\u002FHttp\u002FApi\u002FComment\u002FUpdateTest.php",[42,4964,4965,4970,4975,4979,4984,4989,4994,4999,5003,5007,5011,5015,5020,5025,5030,5035,5040,5045,5050,5055,5059,5063],{"__ignoreMap":53},[57,4966,4967],{"class":59,"line":60},[57,4968,4969],{},"it('returns the comment', function () {\n",[57,4971,4972],{"class":59,"line":119},[57,4973,4974],{},"    \u002F\u002F ...\n",[57,4976,4977],{"class":59,"line":141},[57,4978,150],{"emptyLinePlaceholder":22},[57,4980,4981],{"class":59,"line":147},[57,4982,4983],{},"    $this->actingAs($user)\n",[57,4985,4986],{"class":59,"line":153},[57,4987,4988],{},"        ->putJson(route('comments.update', $comment), [\n",[57,4990,4991],{"class":59,"line":184},[57,4992,4993],{},"            'content' => 'Updated content',\n",[57,4995,4996],{"class":59,"line":202},[57,4997,4998],{},"        ])\n",[57,5000,5001],{"class":59,"line":214},[57,5002,874],{},[57,5004,5005],{"class":59,"line":220},[57,5006,879],{},[57,5008,5009],{"class":59,"line":226},[57,5010,884],{},[57,5012,5013],{"class":59,"line":231},[57,5014,889],{},[57,5016,5017],{"class":59,"line":236},[57,5018,5019],{},"                    fn (AssertableJson $json) => $json\n",[57,5021,5022],{"class":59,"line":265},[57,5023,5024],{},"                        \u002F\u002F ...\n",[57,5026,5027],{"class":59,"line":284},[57,5028,5029],{},"                        ->has(\n",[57,5031,5032],{"class":59,"line":294},[57,5033,5034],{},"                            'can',\n",[57,5036,5037],{"class":59,"line":299},[57,5038,5039],{},"                            fn (AssertableJson $json) => $json\n",[57,5041,5042],{"class":59,"line":304},[57,5043,5044],{},"                                ->where('update', true) \u002F\u002F [!code highlight]\n",[57,5046,5047],{"class":59,"line":309},[57,5048,5049],{},"                                ->where('delete', true) \u002F\u002F [!code highlight]\n",[57,5051,5052],{"class":59,"line":329},[57,5053,5054],{},"                        )\n",[57,5056,5057],{"class":59,"line":346},[57,5058,899],{},[57,5060,5061],{"class":59,"line":356},[57,5062,904],{},[57,5064,5065],{"class":59,"line":361},[57,5066,834],{},[47,5068,5070],{"className":369,"code":5069,"filename":838,"language":372,"meta":53,"style":53},"it('returns comments', function () {\n    \u002F\u002F ...\n\n    $this->getJson(route('posts.comments', $post))\n        ->assertJson(\n            fn (AssertableJson $json) => $json\n                ->has(\n                    'data',\n                    2,\n                    fn (AssertableJson $json) => $json\n                        \u002F\u002F ...\n                        ->has(\n                            'can',\n                            fn (AssertableJson $json) => $json\n                                ->where('update', false) \u002F\u002F [!code highlight]\n                                ->where('delete', false) \u002F\u002F [!code highlight]\n                        )\n                )\n        );\n});\n\n",[42,5071,5072,5077,5081,5085,5090,5094,5098,5102,5106,5111,5115,5119,5123,5127,5131,5136,5141,5145,5149,5153],{"__ignoreMap":53},[57,5073,5074],{"class":59,"line":60},[57,5075,5076],{},"it('returns comments', function () {\n",[57,5078,5079],{"class":59,"line":119},[57,5080,4974],{},[57,5082,5083],{"class":59,"line":141},[57,5084,150],{"emptyLinePlaceholder":22},[57,5086,5087],{"class":59,"line":147},[57,5088,5089],{},"    $this->getJson(route('posts.comments', $post))\n",[57,5091,5092],{"class":59,"line":153},[57,5093,874],{},[57,5095,5096],{"class":59,"line":184},[57,5097,879],{},[57,5099,5100],{"class":59,"line":202},[57,5101,884],{},[57,5103,5104],{"class":59,"line":214},[57,5105,889],{},[57,5107,5108],{"class":59,"line":220},[57,5109,5110],{},"                    2,\n",[57,5112,5113],{"class":59,"line":226},[57,5114,5019],{},[57,5116,5117],{"class":59,"line":231},[57,5118,5024],{},[57,5120,5121],{"class":59,"line":236},[57,5122,5029],{},[57,5124,5125],{"class":59,"line":265},[57,5126,5034],{},[57,5128,5129],{"class":59,"line":284},[57,5130,5039],{},[57,5132,5133],{"class":59,"line":294},[57,5134,5135],{},"                                ->where('update', false) \u002F\u002F [!code highlight]\n",[57,5137,5138],{"class":59,"line":299},[57,5139,5140],{},"                                ->where('delete', false) \u002F\u002F [!code highlight]\n",[57,5142,5143],{"class":59,"line":304},[57,5144,5054],{},[57,5146,5147],{"class":59,"line":309},[57,5148,899],{},[57,5150,5151],{"class":59,"line":329},[57,5152,904],{},[57,5154,5155],{"class":59,"line":346},[57,5156,834],{},[47,5158,5160],{"className":369,"code":5159,"filename":838,"language":372,"meta":53,"style":53},"it('returns the created comment', function () {\n    \u002F\u002F ...\n\n    $response\n        ->assertJson(\n            fn (AssertableJson $json) => $json\n                ->has(\n                    'data',\n                    fn (AssertableJson $json) => $json\n                        \u002F\u002F ...\n                        ->has(\n                            'can',\n                            fn (AssertableJson $json) => $json\n                                ->where('update', true) \u002F\u002F [!code highlight]\n                                ->where('delete', true) \u002F\u002F [!code highlight]\n                        )\n                )\n        );\n});\n",[42,5161,5162,5167,5171,5175,5180,5184,5188,5192,5196,5200,5204,5208,5212,5216,5220,5224,5228,5232,5236],{"__ignoreMap":53},[57,5163,5164],{"class":59,"line":60},[57,5165,5166],{},"it('returns the created comment', function () {\n",[57,5168,5169],{"class":59,"line":119},[57,5170,4974],{},[57,5172,5173],{"class":59,"line":141},[57,5174,150],{"emptyLinePlaceholder":22},[57,5176,5177],{"class":59,"line":147},[57,5178,5179],{},"    $response\n",[57,5181,5182],{"class":59,"line":153},[57,5183,874],{},[57,5185,5186],{"class":59,"line":184},[57,5187,879],{},[57,5189,5190],{"class":59,"line":202},[57,5191,884],{},[57,5193,5194],{"class":59,"line":214},[57,5195,889],{},[57,5197,5198],{"class":59,"line":220},[57,5199,5019],{},[57,5201,5202],{"class":59,"line":226},[57,5203,5024],{},[57,5205,5206],{"class":59,"line":231},[57,5207,5029],{},[57,5209,5210],{"class":59,"line":236},[57,5211,5034],{},[57,5213,5214],{"class":59,"line":265},[57,5215,5039],{},[57,5217,5218],{"class":59,"line":284},[57,5219,5044],{},[57,5221,5222],{"class":59,"line":294},[57,5223,5049],{},[57,5225,5226],{"class":59,"line":299},[57,5227,5054],{},[57,5229,5230],{"class":59,"line":304},[57,5231,899],{},[57,5233,5234],{"class":59,"line":309},[57,5235,904],{},[57,5237,5238],{"class":59,"line":329},[57,5239,834],{},[10,5241,5242,5243,417],{},"With the API response in place, add an edit button to ",[42,5244,930],{},[10,5246,5247,5248,5250,5251,110],{},"Before changing the component, update the ",[42,5249,582],{}," interface to include ",[42,5252,4678],{},[47,5254,5256],{"className":82,"code":5255,"filename":431,"language":85,"meta":53,"style":53},"import type { User } from '@\u002Fuser\u002Ftypes\u002Fuser'\n\nexport interface Comment {\n  id: number\n  content: string\n  author: User\n\n  can: {\n    update: boolean\n    delete: boolean\n  }\n}\n",[42,5257,5258,5270,5274,5284,5292,5300,5308,5312,5321,5331,5340,5344],{"__ignoreMap":53},[57,5259,5260,5262,5264,5266,5268],{"class":59,"line":60},[57,5261,438],{"class":92},[57,5263,441],{"class":92},[57,5265,444],{"class":102},[57,5267,447],{"class":92},[57,5269,450],{"class":71},[57,5271,5272],{"class":59,"line":119},[57,5273,150],{"emptyLinePlaceholder":22},[57,5275,5276,5278,5280,5282],{"class":59,"line":141},[57,5277,93],{"class":92},[57,5279,461],{"class":92},[57,5281,464],{"class":63},[57,5283,467],{"class":102},[57,5285,5286,5288,5290],{"class":59,"line":147},[57,5287,472],{"class":106},[57,5289,110],{"class":92},[57,5291,477],{"class":67},[57,5293,5294,5296,5298],{"class":59,"line":153},[57,5295,482],{"class":106},[57,5297,110],{"class":92},[57,5299,487],{"class":67},[57,5301,5302,5304,5306],{"class":59,"line":184},[57,5303,492],{"class":106},[57,5305,110],{"class":92},[57,5307,497],{"class":63},[57,5309,5310],{"class":59,"line":202},[57,5311,150],{"emptyLinePlaceholder":22},[57,5313,5314,5317,5319],{"class":59,"line":214},[57,5315,5316],{"class":106},"  can",[57,5318,110],{"class":92},[57,5320,467],{"class":102},[57,5322,5323,5326,5328],{"class":59,"line":220},[57,5324,5325],{"class":106},"    update",[57,5327,110],{"class":92},[57,5329,5330],{"class":67}," boolean\n",[57,5332,5333,5336,5338],{"class":59,"line":226},[57,5334,5335],{"class":106},"    delete",[57,5337,110],{"class":92},[57,5339,5330],{"class":67},[57,5341,5342],{"class":59,"line":231},[57,5343,3050],{"class":102},[57,5345,5346],{"class":59,"line":236},[57,5347,144],{"class":102},[10,5349,5350,5351,5354],{},"The button will be displayed only when the backend grants the ",[42,5352,5353],{},"update"," permission.",[47,5356,5358],{"className":951,"code":5357,"filename":953,"language":954,"meta":53,"style":53},"\u003Cscript lang=\"ts\">\nconst blogComment = tv({\n  slots: {\n    footer: 'flex items-center justify-between',\n    actions: 'flex items-center gap-2',\n  },\n})\n\u003C\u002Fscript>\n\n\u003Cscript lang=\"ts\" setup>\n\u002F\u002F ...\n\u003C\u002Fscript>\n\n\u003Ctemplate>\n  \u003Carticle :class=\"ui.base({ class: [props.class, props.ui?.base] })\">\n    \u003C!-- ... -->\n\n    \u003Cdiv :class=\"ui.footer({ class: props.ui?.footer })\">\n      \u003Cdiv :class=\"ui.author({ class: props.ui?.author })\">\n        \u003C!-- ... -->\n      \u003C\u002Fdiv>\n\n      \u003Cdiv :class=\"ui.actions({ class: props.ui?.actions })\">\n        \u003Cbutton v-if=\"props.comment.can.update\">\n          Edit\n        \u003C\u002Fbutton>\n      \u003C\u002Fdiv>\n    \u003C\u002Fdiv>\n  \u003C\u002Farticle>\n\u003C\u002Ftemplate>\n",[42,5359,5360,5374,5386,5390,5400,5409,5413,5417,5425,5429,5445,5449,5457,5461,5469,5483,5487,5491,5506,5520,5525,5533,5537,5552,5567,5572,5581,5589,5597,5605],{"__ignoreMap":53},[57,5361,5362,5364,5366,5368,5370,5372],{"class":59,"line":60},[57,5363,579],{"class":102},[57,5365,964],{"class":963},[57,5367,967],{"class":63},[57,5369,559],{"class":102},[57,5371,972],{"class":71},[57,5373,975],{"class":102},[57,5375,5376,5378,5380,5382,5384],{"class":59,"line":119},[57,5377,998],{"class":92},[57,5379,1001],{"class":67},[57,5381,531],{"class":92},[57,5383,1006],{"class":63},[57,5385,1009],{"class":102},[57,5387,5388],{"class":59,"line":141},[57,5389,1014],{"class":102},[57,5391,5392,5395,5398],{"class":59,"line":147},[57,5393,5394],{"class":102},"    footer: ",[57,5396,5397],{"class":71},"'flex items-center justify-between'",[57,5399,211],{"class":102},[57,5401,5402,5405,5407],{"class":59,"line":153},[57,5403,5404],{"class":102},"    actions: ",[57,5406,4086],{"class":71},[57,5408,211],{"class":102},[57,5410,5411],{"class":59,"line":184},[57,5412,1059],{"class":102},[57,5414,5415],{"class":59,"line":202},[57,5416,664],{"class":102},[57,5418,5419,5421,5423],{"class":59,"line":214},[57,5420,1148],{"class":102},[57,5422,964],{"class":963},[57,5424,975],{"class":102},[57,5426,5427],{"class":59,"line":220},[57,5428,150],{"emptyLinePlaceholder":22},[57,5430,5431,5433,5435,5437,5439,5441,5443],{"class":59,"line":226},[57,5432,579],{"class":102},[57,5434,964],{"class":963},[57,5436,967],{"class":63},[57,5438,559],{"class":102},[57,5440,972],{"class":71},[57,5442,1171],{"class":63},[57,5444,975],{"class":102},[57,5446,5447],{"class":59,"line":231},[57,5448,3202],{"class":3201},[57,5450,5451,5453,5455],{"class":59,"line":236},[57,5452,1148],{"class":102},[57,5454,964],{"class":963},[57,5456,975],{"class":102},[57,5458,5459],{"class":59,"line":265},[57,5460,150],{"emptyLinePlaceholder":22},[57,5462,5463,5465,5467],{"class":59,"line":284},[57,5464,579],{"class":102},[57,5466,1324],{"class":963},[57,5468,975],{"class":102},[57,5470,5471,5473,5475,5477,5479,5481],{"class":59,"line":294},[57,5472,1332],{"class":102},[57,5474,1335],{"class":963},[57,5476,1338],{"class":63},[57,5478,559],{"class":102},[57,5480,1343],{"class":71},[57,5482,975],{"class":102},[57,5484,5485],{"class":59,"line":299},[57,5486,4595],{"class":3201},[57,5488,5489],{"class":59,"line":304},[57,5490,150],{"emptyLinePlaceholder":22},[57,5492,5493,5495,5497,5499,5501,5504],{"class":59,"line":309},[57,5494,1351],{"class":102},[57,5496,1384],{"class":963},[57,5498,1338],{"class":63},[57,5500,559],{"class":102},[57,5502,5503],{"class":71},"\"ui.footer({ class: props.ui?.footer })\"",[57,5505,975],{"class":102},[57,5507,5508,5510,5512,5514,5516,5518],{"class":59,"line":329},[57,5509,1399],{"class":102},[57,5511,1384],{"class":963},[57,5513,1338],{"class":63},[57,5515,559],{"class":102},[57,5517,1391],{"class":71},[57,5519,975],{"class":102},[57,5521,5522],{"class":59,"line":346},[57,5523,5524],{"class":3201},"        \u003C!-- ... -->\n",[57,5526,5527,5529,5531],{"class":59,"line":356},[57,5528,1474],{"class":102},[57,5530,1384],{"class":963},[57,5532,975],{"class":102},[57,5534,5535],{"class":59,"line":361},[57,5536,150],{"emptyLinePlaceholder":22},[57,5538,5539,5541,5543,5545,5547,5550],{"class":59,"line":1176},[57,5540,1399],{"class":102},[57,5542,1384],{"class":963},[57,5544,1338],{"class":63},[57,5546,559],{"class":102},[57,5548,5549],{"class":71},"\"ui.actions({ class: props.ui?.actions })\"",[57,5551,975],{"class":102},[57,5553,5554,5556,5558,5560,5562,5565],{"class":59,"line":1197},[57,5555,1903],{"class":102},[57,5557,2798],{"class":963},[57,5559,1450],{"class":63},[57,5561,559],{"class":102},[57,5563,5564],{"class":71},"\"props.comment.can.update\"",[57,5566,975],{"class":102},[57,5568,5569],{"class":59,"line":1210},[57,5570,5571],{"class":102},"          Edit\n",[57,5573,5574,5577,5579],{"class":59,"line":1223},[57,5575,5576],{"class":102},"        \u003C\u002F",[57,5578,2798],{"class":963},[57,5580,975],{"class":102},[57,5582,5583,5585,5587],{"class":59,"line":1228},[57,5584,1474],{"class":102},[57,5586,1384],{"class":963},[57,5588,975],{"class":102},[57,5590,5591,5593,5595],{"class":59,"line":1253},[57,5592,1367],{"class":102},[57,5594,1384],{"class":963},[57,5596,975],{"class":102},[57,5598,5599,5601,5603],{"class":59,"line":1258},[57,5600,1520],{"class":102},[57,5602,1335],{"class":963},[57,5604,975],{"class":102},[57,5606,5607,5609,5611],{"class":59,"line":1278},[57,5608,1148],{"class":102},[57,5610,1324],{"class":963},[57,5612,975],{"class":102},[10,5614,5615],{},"The backend policy now controls whether this button is shown.",[10,5617,5618,5619,5621],{},"When the user clicks the button, show ",[42,5620,2625],{}," in place of the comment content so the comment can be edited inline.",[10,5623,5624,5625,5627],{},"Add a ref to ",[42,5626,930],{}," to track edit mode:",[47,5629,5631],{"className":951,"code":5630,"filename":953,"language":954,"meta":53,"style":53},"\u003Cscript lang=\"ts\">\n\u002F\u002F ...\n\u003C\u002Fscript>\n\n\u003Cscript lang=\"ts\" setup>\nconst update = ref(false)\n\u003C\u002Fscript>\n\n\u003Ctemplate>\n  \u003Carticle :class=\"ui.base({ class: [props.class, props.ui?.base] })\">\n    \u003CCommentForm\n      v-if=\"update\"\n      :comment=\"props.comment\"\n      @submit=\"update = false\"\n    \u002F>\n    \u003Cp v-else>\n      {{ props.comment.content }}\n    \u003C\u002Fp>\n\n    \u003Cdiv :class=\"ui.footer({ class: props.ui?.footer })\">\n      \u003C!-- ... -->\n\n      \u003Cdiv :class=\"ui.actions({ class: props.ui?.actions })\">\n        \u003Cbutton v-if=\"props.comment.can.update\" @click=\"update = !update\">\n          Edit\n        \u003C\u002Fbutton>\n      \u003C\u002Fdiv>\n    \u003C\u002Fdiv>\n  \u003C\u002Farticle>\n\u003C\u002Ftemplate>\n",[42,5632,5633,5647,5651,5659,5663,5679,5695,5703,5707,5715,5729,5736,5748,5763,5785,5789,5799,5803,5811,5815,5829,5833,5837,5851,5873,5877,5885,5893,5901,5909],{"__ignoreMap":53},[57,5634,5635,5637,5639,5641,5643,5645],{"class":59,"line":60},[57,5636,579],{"class":102},[57,5638,964],{"class":963},[57,5640,967],{"class":63},[57,5642,559],{"class":102},[57,5644,972],{"class":71},[57,5646,975],{"class":102},[57,5648,5649],{"class":59,"line":119},[57,5650,3202],{"class":3201},[57,5652,5653,5655,5657],{"class":59,"line":141},[57,5654,1148],{"class":102},[57,5656,964],{"class":963},[57,5658,975],{"class":102},[57,5660,5661],{"class":59,"line":147},[57,5662,150],{"emptyLinePlaceholder":22},[57,5664,5665,5667,5669,5671,5673,5675,5677],{"class":59,"line":153},[57,5666,579],{"class":102},[57,5668,964],{"class":963},[57,5670,967],{"class":63},[57,5672,559],{"class":102},[57,5674,972],{"class":71},[57,5676,1171],{"class":63},[57,5678,975],{"class":102},[57,5680,5681,5683,5685,5687,5689,5691,5693],{"class":59,"line":184},[57,5682,998],{"class":92},[57,5684,1263],{"class":67},[57,5686,531],{"class":92},[57,5688,1268],{"class":63},[57,5690,103],{"class":102},[57,5692,1273],{"class":67},[57,5694,138],{"class":102},[57,5696,5697,5699,5701],{"class":59,"line":202},[57,5698,1148],{"class":102},[57,5700,964],{"class":963},[57,5702,975],{"class":102},[57,5704,5705],{"class":59,"line":214},[57,5706,150],{"emptyLinePlaceholder":22},[57,5708,5709,5711,5713],{"class":59,"line":220},[57,5710,579],{"class":102},[57,5712,1324],{"class":963},[57,5714,975],{"class":102},[57,5716,5717,5719,5721,5723,5725,5727],{"class":59,"line":226},[57,5718,1332],{"class":102},[57,5720,1335],{"class":963},[57,5722,1338],{"class":63},[57,5724,559],{"class":102},[57,5726,1343],{"class":71},[57,5728,975],{"class":102},[57,5730,5731,5733],{"class":59,"line":231},[57,5732,1351],{"class":102},[57,5734,5735],{"class":963},"CommentForm\n",[57,5737,5738,5740,5742,5744,5746],{"class":59,"line":236},[57,5739,1831],{"class":92},[57,5741,559],{"class":102},[57,5743,1455],{"class":71},[57,5745,5353],{"class":102},[57,5747,2379],{"class":71},[57,5749,5750,5752,5754,5756,5758,5761],{"class":59,"line":265},[57,5751,2787],{"class":102},[57,5753,1911],{"class":63},[57,5755,559],{"class":102},[57,5757,1455],{"class":71},[57,5759,5760],{"class":102},"props.comment",[57,5762,2379],{"class":71},[57,5764,5765,5768,5771,5773,5775,5778,5780,5783],{"class":59,"line":284},[57,5766,5767],{"class":102},"      @",[57,5769,5770],{"class":63},"submit",[57,5772,559],{"class":102},[57,5774,1455],{"class":71},[57,5776,5777],{"class":102},"update ",[57,5779,559],{"class":92},[57,5781,5782],{"class":67}," false",[57,5784,2379],{"class":71},[57,5786,5787],{"class":59,"line":294},[57,5788,2824],{"class":102},[57,5790,5791,5793,5795,5797],{"class":59,"line":299},[57,5792,1351],{"class":102},[57,5794,10],{"class":963},[57,5796,1488],{"class":63},[57,5798,975],{"class":102},[57,5800,5801],{"class":59,"line":304},[57,5802,1361],{"class":102},[57,5804,5805,5807,5809],{"class":59,"line":309},[57,5806,1367],{"class":102},[57,5808,10],{"class":963},[57,5810,975],{"class":102},[57,5812,5813],{"class":59,"line":329},[57,5814,150],{"emptyLinePlaceholder":22},[57,5816,5817,5819,5821,5823,5825,5827],{"class":59,"line":346},[57,5818,1351],{"class":102},[57,5820,1384],{"class":963},[57,5822,1338],{"class":63},[57,5824,559],{"class":102},[57,5826,5503],{"class":71},[57,5828,975],{"class":102},[57,5830,5831],{"class":59,"line":356},[57,5832,4619],{"class":3201},[57,5834,5835],{"class":59,"line":361},[57,5836,150],{"emptyLinePlaceholder":22},[57,5838,5839,5841,5843,5845,5847,5849],{"class":59,"line":1176},[57,5840,1399],{"class":102},[57,5842,1384],{"class":963},[57,5844,1338],{"class":63},[57,5846,559],{"class":102},[57,5848,5549],{"class":71},[57,5850,975],{"class":102},[57,5852,5853,5855,5857,5859,5861,5863,5866,5868,5871],{"class":59,"line":1197},[57,5854,1903],{"class":102},[57,5856,2798],{"class":963},[57,5858,1450],{"class":63},[57,5860,559],{"class":102},[57,5862,5564],{"class":71},[57,5864,5865],{"class":63}," @click",[57,5867,559],{"class":102},[57,5869,5870],{"class":71},"\"update = !update\"",[57,5872,975],{"class":102},[57,5874,5875],{"class":59,"line":1210},[57,5876,5571],{"class":102},[57,5878,5879,5881,5883],{"class":59,"line":1223},[57,5880,5576],{"class":102},[57,5882,2798],{"class":963},[57,5884,975],{"class":102},[57,5886,5887,5889,5891],{"class":59,"line":1228},[57,5888,1474],{"class":102},[57,5890,1384],{"class":963},[57,5892,975],{"class":102},[57,5894,5895,5897,5899],{"class":59,"line":1253},[57,5896,1367],{"class":102},[57,5898,1384],{"class":963},[57,5900,975],{"class":102},[57,5902,5903,5905,5907],{"class":59,"line":1258},[57,5904,1520],{"class":102},[57,5906,1335],{"class":963},[57,5908,975],{"class":102},[57,5910,5911,5913,5915],{"class":59,"line":1278},[57,5912,1148],{"class":102},[57,5914,1324],{"class":963},[57,5916,975],{"class":102},[10,5918,5919,5920,5922],{},"Finally, update ",[42,5921,2625],{}," for edit mode. Pass the comment as a prop and initialize the textarea with its content. The presence of that prop tells the form which mode to use.",[47,5924,5926],{"className":951,"code":5925,"filename":2633,"language":954,"meta":53,"style":53},"\u003Cscript lang=\"ts\">\nimport type { Comment } from '@\u002Fcomments\u002Ftypes\u002Fcomment'\n\nconst commentForm = tv({\n  slots: {\n    base: 'flex flex-col gap-4',\n    textarea:\n      'border-4 border-black px-8 py-4 shadow-[4px_4px_0_black] focus:outline-none',\n    button: '',\n  },\n})\n\nexport interface CommentFormProps {\n  comment?: Comment\n  class?: any\n  ui?: Partial\u003Ctypeof commentForm.slots>\n}\nexport interface CommentFormEmits {\n  submit: [void]\n}\nexport interface CommentFormSlots {}\n\u003C\u002Fscript>\n\n\u003Cscript lang=\"ts\" setup>\nconst props = defineProps\u003CCommentFormProps>()\nconst emit = defineEmits\u003CCommentFormEmits>()\ndefineSlots\u003CCommentFormSlots>()\n\nconst { frontmatter } = useData()\nconst queryCache = useQueryCache()\n\nconst content = ref(props.comment?.content ?? '')\n\nconst {\n  mutate: storeComment,\n  isLoading: isStoreCommentLoading,\n  error: storeCommentError,\n} = useMutation\u003C\n  {\n    data: Comment\n  },\n  { postId: number, content: string, parentId?: number },\n  {\n    data: {\n      message: string\n      errors: {\n        content: string[]\n      }\n    }\n  }\n>({\n  mutation: ({ postId, content }) => postComment(postId, content),\n  onSuccess: () => {\n    content.value = ''\n  },\n  onSettled: () =>\n    queryCache.invalidateQueries({\n      key: ['comments', frontmatter.value.id],\n      exact: true,\n    }),\n})\n\nconst {\n  mutate: updateComment,\n  isLoading: isUpdateCommentLoading,\n  error: updateCommentError,\n} = useMutation\u003C\n  {\n    data: Comment\n  },\n  { commentId: number, content: string },\n  {\n    data: {\n      message: string\n      errors: {\n        content: string[]\n      }\n    }\n  }\n>({\n  mutation: ({ commentId, content }) => putComment(commentId, content),\n  onSuccess: (data) => {\n    content.value = ''\n\n    const comments\n      = queryCache.getQueryData\u003CComment[]>(['comments', frontmatter.value.id])\n        ?? ([] as Comment[])\n\n    const index = comments.findIndex(\n      (comment: Comment) => comment.id === data.data.id,\n    )\n    if (index !== -1) {\n      comments[index] = data.data\n      queryCache.setQueryData(['comments', frontmatter.value.id], comments)\n    }\n\n    emit('submit')\n  },\n  onSettled: () =>\n    queryCache.invalidateQueries({\n      key: ['comments', frontmatter.value.id],\n      exact: true,\n    }),\n})\n\nfunction onSubmit() {\n  if (props.comment) {\n    updateComment({\n      commentId: props.comment.id,\n      content: content.value,\n    })\n  }\n  else {\n    storeComment({ postId: frontmatter.value.id, content: content.value })\n  }\n}\n\nconst error = computed(\n  () => storeCommentError.value || updateCommentError.value,\n)\nconst isLoading = computed(\n  () => isStoreCommentLoading.value || isUpdateCommentLoading.value,\n)\n\nconst ui = computed(() => commentForm())\n\u003C\u002Fscript>\n\n\u003Ctemplate>\n  \u003Cform\n    :class=\"ui.base({ class: [props.class, props.ui?.base] })\"\n    @submit.prevent=\"onSubmit\"\n  >\n    \u003Ctextarea\n      v-model=\"content\"\n      placeholder=\"Write a comment...\"\n      :class=\"ui.textarea({ class: props.ui?.textarea })\"\n    \u002F>\n\n    \u003Cspan v-if=\"error\" class=\"text-red-500\">{{ error.data.message }}\u003C\u002Fspan>\n\n    \u003CButton\n      type=\"submit\"\n      :label=\"props.comment ? 'Edit' : 'Comment'\"\n      :class=\"ui.button({ class: props.ui?.button })\"\n      :disabled=\"isLoading\"\n    \u002F>\n  \u003C\u002Fform>\n\u003C\u002Ftemplate>\n",[42,5927,5928,5942,5954,5958,5970,5974,5982,5986,5992,6000,6004,6008,6012,6022,6030,6038,6052,6056,6066,6078,6082,6092,6100,6104,6120,6136,6152,6162,6166,6182,6194,6198,6216,6220,6226,6236,6247,6258,6268,6272,6278,6282,6298,6302,6308,6314,6320,6326,6330,6334,6338,6344,6364,6374,6382,6386,6394,6402,6410,6418,6422,6426,6430,6436,6447,6458,6469,6479,6483,6489,6493,6506,6510,6516,6522,6528,6534,6538,6542,6546,6552,6573,6590,6598,6602,6610,6633,6649,6653,6671,6695,6701,6719,6730,6747,6752,6757,6770,6775,6784,6793,6802,6811,6816,6821,6826,6835,6844,6852,6858,6864,6870,6875,6883,6891,6896,6901,6906,6920,6937,6942,6956,6971,6976,6981,7000,7009,7014,7023,7030,7039,7048,7053,7060,7069,7078,7087,7094,7099,7124,7129,7136,7145,7171,7190,7205,7210,7219],{"__ignoreMap":53},[57,5929,5930,5932,5934,5936,5938,5940],{"class":59,"line":60},[57,5931,579],{"class":102},[57,5933,964],{"class":963},[57,5935,967],{"class":63},[57,5937,559],{"class":102},[57,5939,972],{"class":71},[57,5941,975],{"class":102},[57,5943,5944,5946,5948,5950,5952],{"class":59,"line":119},[57,5945,438],{"class":92},[57,5947,441],{"class":92},[57,5949,984],{"class":102},[57,5951,447],{"class":92},[57,5953,989],{"class":71},[57,5955,5956],{"class":59,"line":141},[57,5957,150],{"emptyLinePlaceholder":22},[57,5959,5960,5962,5964,5966,5968],{"class":59,"line":147},[57,5961,998],{"class":92},[57,5963,3287],{"class":67},[57,5965,531],{"class":92},[57,5967,1006],{"class":63},[57,5969,1009],{"class":102},[57,5971,5972],{"class":59,"line":153},[57,5973,1014],{"class":102},[57,5975,5976,5978,5980],{"class":59,"line":184},[57,5977,1019],{"class":102},[57,5979,3304],{"class":71},[57,5981,211],{"class":102},[57,5983,5984],{"class":59,"line":202},[57,5985,3311],{"class":102},[57,5987,5988,5990],{"class":59,"line":214},[57,5989,3316],{"class":71},[57,5991,211],{"class":102},[57,5993,5994,5996,5998],{"class":59,"line":220},[57,5995,3323],{"class":102},[57,5997,1032],{"class":71},[57,5999,211],{"class":102},[57,6001,6002],{"class":59,"line":226},[57,6003,1059],{"class":102},[57,6005,6006],{"class":59,"line":231},[57,6007,664],{"class":102},[57,6009,6010],{"class":59,"line":236},[57,6011,150],{"emptyLinePlaceholder":22},[57,6013,6014,6016,6018,6020],{"class":59,"line":265},[57,6015,93],{"class":92},[57,6017,461],{"class":92},[57,6019,3348],{"class":63},[57,6021,467],{"class":102},[57,6023,6024,6026,6028],{"class":59,"line":284},[57,6025,1083],{"class":106},[57,6027,1096],{"class":92},[57,6029,1088],{"class":63},[57,6031,6032,6034,6036],{"class":59,"line":294},[57,6033,1093],{"class":106},[57,6035,1096],{"class":92},[57,6037,1099],{"class":67},[57,6039,6040,6042,6044,6046,6048,6050],{"class":59,"line":299},[57,6041,1104],{"class":106},[57,6043,1096],{"class":92},[57,6045,1109],{"class":63},[57,6047,579],{"class":102},[57,6049,644],{"class":92},[57,6051,3381],{"class":102},[57,6053,6054],{"class":59,"line":304},[57,6055,144],{"class":102},[57,6057,6058,6060,6062,6064],{"class":59,"line":309},[57,6059,93],{"class":92},[57,6061,461],{"class":92},[57,6063,3394],{"class":63},[57,6065,467],{"class":102},[57,6067,6068,6070,6072,6074,6076],{"class":59,"line":329},[57,6069,3401],{"class":106},[57,6071,110],{"class":92},[57,6073,598],{"class":102},[57,6075,3408],{"class":67},[57,6077,3411],{"class":102},[57,6079,6080],{"class":59,"line":346},[57,6081,144],{"class":102},[57,6083,6084,6086,6088,6090],{"class":59,"line":356},[57,6085,93],{"class":92},[57,6087,461],{"class":92},[57,6089,3424],{"class":63},[57,6091,1132],{"class":102},[57,6093,6094,6096,6098],{"class":59,"line":361},[57,6095,1148],{"class":102},[57,6097,964],{"class":963},[57,6099,975],{"class":102},[57,6101,6102],{"class":59,"line":1176},[57,6103,150],{"emptyLinePlaceholder":22},[57,6105,6106,6108,6110,6112,6114,6116,6118],{"class":59,"line":1197},[57,6107,579],{"class":102},[57,6109,964],{"class":963},[57,6111,967],{"class":63},[57,6113,559],{"class":102},[57,6115,972],{"class":71},[57,6117,1171],{"class":63},[57,6119,975],{"class":102},[57,6121,6122,6124,6126,6128,6130,6132,6134],{"class":59,"line":1210},[57,6123,998],{"class":92},[57,6125,1181],{"class":67},[57,6127,531],{"class":92},[57,6129,1186],{"class":63},[57,6131,579],{"class":102},[57,6133,3469],{"class":63},[57,6135,1194],{"class":102},[57,6137,6138,6140,6142,6144,6146,6148,6150],{"class":59,"line":1223},[57,6139,998],{"class":92},[57,6141,3478],{"class":67},[57,6143,531],{"class":92},[57,6145,3483],{"class":63},[57,6147,579],{"class":102},[57,6149,3488],{"class":63},[57,6151,1194],{"class":102},[57,6153,6154,6156,6158,6160],{"class":59,"line":1228},[57,6155,1213],{"class":63},[57,6157,579],{"class":102},[57,6159,3499],{"class":63},[57,6161,1194],{"class":102},[57,6163,6164],{"class":59,"line":1253},[57,6165,150],{"emptyLinePlaceholder":22},[57,6167,6168,6170,6172,6174,6176,6178,6180],{"class":59,"line":1258},[57,6169,998],{"class":92},[57,6171,550],{"class":102},[57,6173,553],{"class":67},[57,6175,556],{"class":102},[57,6177,559],{"class":92},[57,6179,562],{"class":63},[57,6181,565],{"class":102},[57,6183,6184,6186,6188,6190,6192],{"class":59,"line":1278},[57,6185,998],{"class":92},[57,6187,2888],{"class":67},[57,6189,531],{"class":92},[57,6191,2893],{"class":63},[57,6193,565],{"class":102},[57,6195,6196],{"class":59,"line":1283},[57,6197,150],{"emptyLinePlaceholder":22},[57,6199,6200,6202,6204,6206,6208,6210,6212,6214],{"class":59,"line":1305},[57,6201,998],{"class":92},[57,6203,2906],{"class":67},[57,6205,531],{"class":92},[57,6207,1268],{"class":63},[57,6209,3550],{"class":102},[57,6211,3553],{"class":92},[57,6213,3556],{"class":71},[57,6215,138],{"class":102},[57,6217,6218],{"class":59,"line":1314},[57,6219,150],{"emptyLinePlaceholder":22},[57,6221,6222,6224],{"class":59,"line":1319},[57,6223,998],{"class":92},[57,6225,467],{"class":102},[57,6227,6228,6230,6232,6234],{"class":59,"line":1329},[57,6229,2931],{"class":106},[57,6231,1238],{"class":102},[57,6233,2936],{"class":67},[57,6235,211],{"class":102},[57,6237,6238,6240,6242,6245],{"class":59,"line":1348},[57,6239,2943],{"class":106},[57,6241,1238],{"class":102},[57,6243,6244],{"class":67},"isStoreCommentLoading",[57,6246,211],{"class":102},[57,6248,6249,6251,6253,6256],{"class":59,"line":1358},[57,6250,2950],{"class":106},[57,6252,1238],{"class":102},[57,6254,6255],{"class":67},"storeCommentError",[57,6257,211],{"class":102},[57,6259,6260,6262,6264,6266],{"class":59,"line":1364},[57,6261,2957],{"class":102},[57,6263,559],{"class":92},[57,6265,2962],{"class":102},[57,6267,2965],{"class":92},[57,6269,6270],{"class":59,"line":1374},[57,6271,2970],{"class":102},[57,6273,6274,6276],{"class":59,"line":1379},[57,6275,2975],{"class":63},[57,6277,2978],{"class":102},[57,6279,6280],{"class":59,"line":1396},[57,6281,1059],{"class":102},[57,6283,6284,6286,6288,6290,6292,6294,6296],{"class":59,"line":1405},[57,6285,2987],{"class":102},[57,6287,107],{"class":63},[57,6289,2992],{"class":102},[57,6291,174],{"class":63},[57,6293,2997],{"class":102},[57,6295,1096],{"class":92},[57,6297,3002],{"class":102},[57,6299,6300],{"class":59,"line":1416},[57,6301,2970],{"class":102},[57,6303,6304,6306],{"class":59,"line":1426},[57,6305,2975],{"class":63},[57,6307,3013],{"class":102},[57,6309,6310,6312],{"class":59,"line":1437},[57,6311,3018],{"class":63},[57,6313,3021],{"class":102},[57,6315,6316,6318],{"class":59,"line":1443},[57,6317,3026],{"class":63},[57,6319,3013],{"class":102},[57,6321,6322,6324],{"class":59,"line":1465},[57,6323,3033],{"class":63},[57,6325,3036],{"class":102},[57,6327,6328],{"class":59,"line":1471},[57,6329,3041],{"class":102},[57,6331,6332],{"class":59,"line":1481},[57,6333,804],{"class":102},[57,6335,6336],{"class":59,"line":1493},[57,6337,3050],{"class":102},[57,6339,6340,6342],{"class":59,"line":1499},[57,6341,3055],{"class":92},[57,6343,1009],{"class":102},[57,6345,6346,6348,6350,6352,6354,6356,6358,6360,6362],{"class":59,"line":1508},[57,6347,3062],{"class":63},[57,6349,3065],{"class":102},[57,6351,107],{"class":106},[57,6353,171],{"class":102},[57,6355,174],{"class":106},[57,6357,3074],{"class":102},[57,6359,540],{"class":92},[57,6361,160],{"class":63},[57,6363,3081],{"class":102},[57,6365,6366,6368,6370,6372],{"class":59,"line":1517},[57,6367,3086],{"class":63},[57,6369,593],{"class":102},[57,6371,540],{"class":92},[57,6373,467],{"class":102},[57,6375,6376,6378,6380],{"class":59,"line":1527},[57,6377,3097],{"class":102},[57,6379,559],{"class":92},[57,6381,3102],{"class":71},[57,6383,6384],{"class":59,"line":3717},[57,6385,1059],{"class":102},[57,6387,6388,6390,6392],{"class":59,"line":3722},[57,6389,3111],{"class":63},[57,6391,593],{"class":102},[57,6393,614],{"class":92},[57,6395,6396,6398,6400],{"class":59,"line":3731},[57,6397,3120],{"class":102},[57,6399,3123],{"class":63},[57,6401,1009],{"class":102},[57,6403,6404,6406,6408],{"class":59,"line":3740},[57,6405,3130],{"class":102},[57,6407,601],{"class":71},[57,6409,604],{"class":102},[57,6411,6412,6414,6416],{"class":59,"line":3749},[57,6413,3139],{"class":102},[57,6415,3142],{"class":67},[57,6417,211],{"class":102},[57,6419,6420],{"class":59,"line":3758},[57,6421,3149],{"class":102},[57,6423,6424],{"class":59,"line":3763},[57,6425,664],{"class":102},[57,6427,6428],{"class":59,"line":3768},[57,6429,150],{"emptyLinePlaceholder":22},[57,6431,6432,6434],{"class":59,"line":3773},[57,6433,998],{"class":92},[57,6435,467],{"class":102},[57,6437,6438,6440,6442,6445],{"class":59,"line":3782},[57,6439,2931],{"class":106},[57,6441,1238],{"class":102},[57,6443,6444],{"class":67},"updateComment",[57,6446,211],{"class":102},[57,6448,6449,6451,6453,6456],{"class":59,"line":3789},[57,6450,2943],{"class":106},[57,6452,1238],{"class":102},[57,6454,6455],{"class":67},"isUpdateCommentLoading",[57,6457,211],{"class":102},[57,6459,6460,6462,6464,6467],{"class":59,"line":3794},[57,6461,2950],{"class":106},[57,6463,1238],{"class":102},[57,6465,6466],{"class":67},"updateCommentError",[57,6468,211],{"class":102},[57,6470,6471,6473,6475,6477],{"class":59,"line":3799},[57,6472,2957],{"class":102},[57,6474,559],{"class":92},[57,6476,2962],{"class":102},[57,6478,2965],{"class":92},[57,6480,6481],{"class":59,"line":3818},[57,6482,2970],{"class":102},[57,6484,6485,6487],{"class":59,"line":3827},[57,6486,2975],{"class":63},[57,6488,2978],{"class":102},[57,6490,6491],{"class":59,"line":3832},[57,6492,1059],{"class":102},[57,6494,6495,6497,6499,6501,6503],{"class":59,"line":3841},[57,6496,2987],{"class":102},[57,6498,248],{"class":63},[57,6500,2992],{"class":102},[57,6502,174],{"class":63},[57,6504,6505],{"class":102},": string },\n",[57,6507,6508],{"class":59,"line":3848},[57,6509,2970],{"class":102},[57,6511,6512,6514],{"class":59,"line":3857},[57,6513,2975],{"class":63},[57,6515,3013],{"class":102},[57,6517,6518,6520],{"class":59,"line":3866},[57,6519,3018],{"class":63},[57,6521,3021],{"class":102},[57,6523,6524,6526],{"class":59,"line":3871},[57,6525,3026],{"class":63},[57,6527,3013],{"class":102},[57,6529,6530,6532],{"class":59,"line":3878},[57,6531,3033],{"class":63},[57,6533,3036],{"class":102},[57,6535,6536],{"class":59,"line":3887},[57,6537,3041],{"class":102},[57,6539,6540],{"class":59,"line":3896},[57,6541,804],{"class":102},[57,6543,6544],{"class":59,"line":3905},[57,6545,3050],{"class":102},[57,6547,6548,6550],{"class":59,"line":3912},[57,6549,3055],{"class":92},[57,6551,1009],{"class":102},[57,6553,6554,6556,6558,6560,6562,6564,6566,6568,6570],{"class":59,"line":3917},[57,6555,3062],{"class":63},[57,6557,3065],{"class":102},[57,6559,248],{"class":106},[57,6561,171],{"class":102},[57,6563,174],{"class":106},[57,6565,3074],{"class":102},[57,6567,540],{"class":92},[57,6569,243],{"class":63},[57,6571,6572],{"class":102},"(commentId, content),\n",[57,6574,6575,6577,6580,6583,6586,6588],{"class":59,"line":3942},[57,6576,3086],{"class":63},[57,6578,6579],{"class":102},": (",[57,6581,6582],{"class":106},"data",[57,6584,6585],{"class":102},") ",[57,6587,540],{"class":92},[57,6589,467],{"class":102},[57,6591,6592,6594,6596],{"class":59,"line":3947},[57,6593,3097],{"class":102},[57,6595,559],{"class":92},[57,6597,3102],{"class":71},[57,6599,6600],{"class":59,"line":3954},[57,6601,150],{"emptyLinePlaceholder":22},[57,6603,6604,6607],{"class":59,"line":3963},[57,6605,6606],{"class":92},"    const",[57,6608,6609],{"class":67}," comments\n",[57,6611,6612,6615,6618,6621,6623,6625,6628,6630],{"class":59,"line":3972},[57,6613,6614],{"class":92},"      =",[57,6616,6617],{"class":102}," queryCache.",[57,6619,6620],{"class":63},"getQueryData",[57,6622,579],{"class":102},[57,6624,582],{"class":63},[57,6626,6627],{"class":102},"[]>([",[57,6629,601],{"class":71},[57,6631,6632],{"class":102},", frontmatter.value.id])\n",[57,6634,6635,6638,6641,6644,6646],{"class":59,"line":3991},[57,6636,6637],{"class":92},"        ??",[57,6639,6640],{"class":102}," ([] ",[57,6642,6643],{"class":92},"as",[57,6645,464],{"class":63},[57,6647,6648],{"class":102},"[])\n",[57,6650,6651],{"class":59,"line":4006},[57,6652,150],{"emptyLinePlaceholder":22},[57,6654,6655,6657,6660,6662,6665,6668],{"class":59,"line":4011},[57,6656,6606],{"class":92},[57,6658,6659],{"class":67}," index",[57,6661,531],{"class":92},[57,6663,6664],{"class":102}," comments.",[57,6666,6667],{"class":63},"findIndex",[57,6669,6670],{"class":102},"(\n",[57,6672,6673,6676,6678,6680,6682,6684,6686,6689,6692],{"class":59,"line":4020},[57,6674,6675],{"class":102},"      (",[57,6677,1911],{"class":106},[57,6679,110],{"class":92},[57,6681,464],{"class":63},[57,6683,6585],{"class":102},[57,6685,540],{"class":92},[57,6687,6688],{"class":102}," comment.id ",[57,6690,6691],{"class":92},"===",[57,6693,6694],{"class":102}," data.data.id,\n",[57,6696,6698],{"class":59,"line":6697},91,[57,6699,6700],{"class":102},"    )\n",[57,6702,6704,6707,6710,6712,6715,6717],{"class":59,"line":6703},92,[57,6705,6706],{"class":92},"    if",[57,6708,6709],{"class":102}," (index ",[57,6711,650],{"class":92},[57,6713,6714],{"class":92}," -",[57,6716,715],{"class":67},[57,6718,116],{"class":102},[57,6720,6722,6725,6727],{"class":59,"line":6721},93,[57,6723,6724],{"class":102},"      comments[index] ",[57,6726,559],{"class":92},[57,6728,6729],{"class":102}," data.data\n",[57,6731,6733,6736,6739,6742,6744],{"class":59,"line":6732},94,[57,6734,6735],{"class":102},"      queryCache.",[57,6737,6738],{"class":63},"setQueryData",[57,6740,6741],{"class":102},"([",[57,6743,601],{"class":71},[57,6745,6746],{"class":102},", frontmatter.value.id], comments)\n",[57,6748,6750],{"class":59,"line":6749},95,[57,6751,804],{"class":102},[57,6753,6755],{"class":59,"line":6754},96,[57,6756,150],{"emptyLinePlaceholder":22},[57,6758,6760,6763,6765,6768],{"class":59,"line":6759},97,[57,6761,6762],{"class":63},"    emit",[57,6764,103],{"class":102},[57,6766,6767],{"class":71},"'submit'",[57,6769,138],{"class":102},[57,6771,6773],{"class":59,"line":6772},98,[57,6774,1059],{"class":102},[57,6776,6778,6780,6782],{"class":59,"line":6777},99,[57,6779,3111],{"class":63},[57,6781,593],{"class":102},[57,6783,614],{"class":92},[57,6785,6787,6789,6791],{"class":59,"line":6786},100,[57,6788,3120],{"class":102},[57,6790,3123],{"class":63},[57,6792,1009],{"class":102},[57,6794,6796,6798,6800],{"class":59,"line":6795},101,[57,6797,3130],{"class":102},[57,6799,601],{"class":71},[57,6801,604],{"class":102},[57,6803,6805,6807,6809],{"class":59,"line":6804},102,[57,6806,3139],{"class":102},[57,6808,3142],{"class":67},[57,6810,211],{"class":102},[57,6812,6814],{"class":59,"line":6813},103,[57,6815,3149],{"class":102},[57,6817,6819],{"class":59,"line":6818},104,[57,6820,664],{"class":102},[57,6822,6824],{"class":59,"line":6823},105,[57,6825,150],{"emptyLinePlaceholder":22},[57,6827,6829,6831,6833],{"class":59,"line":6828},106,[57,6830,3211],{"class":92},[57,6832,3214],{"class":63},[57,6834,3217],{"class":102},[57,6836,6838,6841],{"class":59,"line":6837},107,[57,6839,6840],{"class":92},"  if",[57,6842,6843],{"class":102}," (props.comment) {\n",[57,6845,6847,6850],{"class":59,"line":6846},108,[57,6848,6849],{"class":63},"    updateComment",[57,6851,1009],{"class":102},[57,6853,6855],{"class":59,"line":6854},109,[57,6856,6857],{"class":102},"      commentId: props.comment.id,\n",[57,6859,6861],{"class":59,"line":6860},110,[57,6862,6863],{"class":102},"      content: content.value,\n",[57,6865,6867],{"class":59,"line":6866},111,[57,6868,6869],{"class":102},"    })\n",[57,6871,6873],{"class":59,"line":6872},112,[57,6874,3050],{"class":102},[57,6876,6878,6881],{"class":59,"line":6877},113,[57,6879,6880],{"class":92},"  else",[57,6882,467],{"class":102},[57,6884,6886,6889],{"class":59,"line":6885},114,[57,6887,6888],{"class":63},"    storeComment",[57,6890,3225],{"class":102},[57,6892,6894],{"class":59,"line":6893},115,[57,6895,3050],{"class":102},[57,6897,6899],{"class":59,"line":6898},116,[57,6900,144],{"class":102},[57,6902,6904],{"class":59,"line":6903},117,[57,6905,150],{"emptyLinePlaceholder":22},[57,6907,6909,6911,6914,6916,6918],{"class":59,"line":6908},118,[57,6910,998],{"class":92},[57,6912,6913],{"class":67}," error",[57,6915,531],{"class":92},[57,6917,1293],{"class":63},[57,6919,6670],{"class":102},[57,6921,6923,6926,6928,6931,6934],{"class":59,"line":6922},119,[57,6924,6925],{"class":102},"  () ",[57,6927,540],{"class":92},[57,6929,6930],{"class":102}," storeCommentError.value ",[57,6932,6933],{"class":92},"||",[57,6935,6936],{"class":102}," updateCommentError.value,\n",[57,6938,6940],{"class":59,"line":6939},120,[57,6941,138],{"class":102},[57,6943,6945,6947,6950,6952,6954],{"class":59,"line":6944},121,[57,6946,998],{"class":92},[57,6948,6949],{"class":67}," isLoading",[57,6951,531],{"class":92},[57,6953,1293],{"class":63},[57,6955,6670],{"class":102},[57,6957,6959,6961,6963,6966,6968],{"class":59,"line":6958},122,[57,6960,6925],{"class":102},[57,6962,540],{"class":92},[57,6964,6965],{"class":102}," isStoreCommentLoading.value ",[57,6967,6933],{"class":92},[57,6969,6970],{"class":102}," isUpdateCommentLoading.value,\n",[57,6972,6974],{"class":59,"line":6973},123,[57,6975,138],{"class":102},[57,6977,6979],{"class":59,"line":6978},124,[57,6980,150],{"emptyLinePlaceholder":22},[57,6982,6984,6986,6988,6990,6992,6994,6996,6998],{"class":59,"line":6983},125,[57,6985,998],{"class":92},[57,6987,1288],{"class":67},[57,6989,531],{"class":92},[57,6991,1293],{"class":63},[57,6993,537],{"class":102},[57,6995,540],{"class":92},[57,6997,3287],{"class":63},[57,6999,1302],{"class":102},[57,7001,7003,7005,7007],{"class":59,"line":7002},126,[57,7004,1148],{"class":102},[57,7006,964],{"class":963},[57,7008,975],{"class":102},[57,7010,7012],{"class":59,"line":7011},127,[57,7013,150],{"emptyLinePlaceholder":22},[57,7015,7017,7019,7021],{"class":59,"line":7016},128,[57,7018,579],{"class":102},[57,7020,1324],{"class":963},[57,7022,975],{"class":102},[57,7024,7026,7028],{"class":59,"line":7025},129,[57,7027,1332],{"class":102},[57,7029,2650],{"class":963},[57,7031,7033,7035,7037],{"class":59,"line":7032},130,[57,7034,2655],{"class":63},[57,7036,559],{"class":102},[57,7038,2660],{"class":71},[57,7040,7042,7044,7046],{"class":59,"line":7041},131,[57,7043,2665],{"class":63},[57,7045,559],{"class":102},[57,7047,2670],{"class":71},[57,7049,7051],{"class":59,"line":7050},132,[57,7052,2675],{"class":102},[57,7054,7056,7058],{"class":59,"line":7055},133,[57,7057,1351],{"class":102},[57,7059,2682],{"class":963},[57,7061,7063,7065,7067],{"class":59,"line":7062},134,[57,7064,2687],{"class":63},[57,7066,559],{"class":102},[57,7068,2692],{"class":71},[57,7070,7072,7074,7076],{"class":59,"line":7071},135,[57,7073,2697],{"class":63},[57,7075,559],{"class":102},[57,7077,2702],{"class":71},[57,7079,7081,7083,7085],{"class":59,"line":7080},136,[57,7082,1841],{"class":63},[57,7084,559],{"class":102},[57,7086,2711],{"class":71},[57,7088,7090,7092],{"class":59,"line":7089},137,[57,7091,2717],{"class":2716},[57,7093,975],{"class":102},[57,7095,7097],{"class":59,"line":7096},138,[57,7098,150],{"emptyLinePlaceholder":22},[57,7100,7102,7104,7106,7108,7110,7112,7114,7116,7118,7120,7122],{"class":59,"line":7101},139,[57,7103,1351],{"class":102},[57,7105,57],{"class":963},[57,7107,1450],{"class":63},[57,7109,559],{"class":102},[57,7111,2736],{"class":71},[57,7113,2739],{"class":63},[57,7115,559],{"class":102},[57,7117,2744],{"class":71},[57,7119,2747],{"class":102},[57,7121,57],{"class":963},[57,7123,975],{"class":102},[57,7125,7127],{"class":59,"line":7126},140,[57,7128,150],{"emptyLinePlaceholder":22},[57,7130,7132,7134],{"class":59,"line":7131},141,[57,7133,1351],{"class":102},[57,7135,2762],{"class":963},[57,7137,7139,7141,7143],{"class":59,"line":7138},142,[57,7140,2767],{"class":63},[57,7142,559],{"class":102},[57,7144,2772],{"class":71},[57,7146,7148,7150,7153,7155,7157,7160,7163,7166,7168],{"class":59,"line":7147},143,[57,7149,2787],{"class":102},[57,7151,7152],{"class":63},"label",[57,7154,559],{"class":102},[57,7156,1455],{"class":71},[57,7158,7159],{"class":102},"props.comment ",[57,7161,7162],{"class":92},"?",[57,7164,7165],{"class":71}," 'Edit'",[57,7167,1908],{"class":92},[57,7169,7170],{"class":71}," 'Comment'\"\n",[57,7172,7174,7176,7178,7180,7182,7184,7186,7188],{"class":59,"line":7173},144,[57,7175,2787],{"class":102},[57,7177,2386],{"class":63},[57,7179,559],{"class":102},[57,7181,1455],{"class":71},[57,7183,2393],{"class":102},[57,7185,2798],{"class":63},[57,7187,2801],{"class":102},[57,7189,2379],{"class":71},[57,7191,7193,7195,7197,7199,7201,7203],{"class":59,"line":7192},145,[57,7194,2787],{"class":102},[57,7196,2810],{"class":63},[57,7198,559],{"class":102},[57,7200,1455],{"class":71},[57,7202,2817],{"class":102},[57,7204,2379],{"class":71},[57,7206,7208],{"class":59,"line":7207},146,[57,7209,2824],{"class":102},[57,7211,7213,7215,7217],{"class":59,"line":7212},147,[57,7214,1520],{"class":102},[57,7216,2831],{"class":963},[57,7218,975],{"class":102},[57,7220,7222,7224,7226],{"class":59,"line":7221},148,[57,7223,1148],{"class":102},[57,7225,1324],{"class":963},[57,7227,975],{"class":102},[10,7229,7230,7231,7233,7234,7236,7237,7239,7240,417],{},"The textarea starts with the comment's content when the ",[42,7232,1911],{}," prop is set. We combine the store and update loading states so the button is disabled during either request, and combine their errors so one message can be displayed. The button label changes with the mode. On submit, the form checks whether ",[42,7235,1911],{}," exists and calls either ",[42,7238,6444],{}," or ",[42,7241,2936],{},[727,7243,7246],{"color":7244,"icon":7245},"success","i-ph-lightbulb-duotone",[10,7247,7248,7249,7251],{},"Reusing ",[42,7250,2625],{}," works well here because creation and editing differ only in the initial value and the API endpoint.",[34,7253,7255],{"id":7254},"deleting-a-comment","Deleting a comment",[10,7257,7258,7259,7262],{},"To delete a comment, create a ",[42,7260,7261],{},"useDeleteComment"," mutation. It will use an optimistic update to give immediate feedback while the request is running.",[47,7264,7267],{"className":82,"code":7265,"filename":7266,"language":85,"meta":53,"style":53},"import type { Comment } from '@\u002Fcomments\u002Ftypes\u002Fcomment'\n\nexport const useDeleteComment = defineMutation(() => {\n  const { frontmatter } = useData()\n\n  const queryCache = useQueryCache()\n\n  return useMutation({\n    mutation: ({ commentId }: { commentId: number }) =>\n      deleteComment(commentId),\n\n    onMutate: ({ commentId }) => {\n      const oldComments\n        = queryCache.getQueryData\u003CComment[]>([\n          'comments',\n          frontmatter.value.id,\n        ]) || ([] as Comment[])\n\n      const newComments = JSON.parse(JSON.stringify(oldComments)) as Comment[]\n      newComments.splice(\n        newComments.findIndex(c => c.id === commentId),\n        1,\n      )\n\n      queryCache.setQueryData(['comments', frontmatter.value.id], newComments)\n      queryCache.cancelQueries({\n        key: ['comments', frontmatter.value.id],\n        exact: true,\n      })\n\n      return { oldComments }\n    },\n    onError: (_, __, { oldComments }) => {\n      if (oldComments) {\n        queryCache.setQueryData(\n          ['comments', frontmatter.value.id],\n          oldComments,\n        )\n      }\n    },\n    onSettled: () =>\n      queryCache.invalidateQueries({\n        key: ['comments', frontmatter.value.id],\n        exact: true,\n      }),\n  })\n})\n",".vitepress\u002Ftheme\u002Fcomments\u002Fmutations\u002Fcomments.ts",[42,7268,7269,7281,7285,7304,7320,7324,7336,7340,7348,7373,7381,7385,7400,7408,7424,7431,7436,7451,7455,7491,7501,7523,7530,7535,7539,7552,7561,7570,7579,7584,7588,7596,7600,7627,7635,7644,7653,7658,7663,7667,7671,7680,7688,7696,7704,7709,7713],{"__ignoreMap":53},[57,7270,7271,7273,7275,7277,7279],{"class":59,"line":60},[57,7272,438],{"class":92},[57,7274,441],{"class":92},[57,7276,984],{"class":102},[57,7278,447],{"class":92},[57,7280,989],{"class":71},[57,7282,7283],{"class":59,"line":119},[57,7284,150],{"emptyLinePlaceholder":22},[57,7286,7287,7289,7291,7293,7295,7298,7300,7302],{"class":59,"line":141},[57,7288,93],{"class":92},[57,7290,525],{"class":92},[57,7292,1248],{"class":67},[57,7294,531],{"class":92},[57,7296,7297],{"class":63}," defineMutation",[57,7299,537],{"class":102},[57,7301,540],{"class":92},[57,7303,467],{"class":102},[57,7305,7306,7308,7310,7312,7314,7316,7318],{"class":59,"line":147},[57,7307,547],{"class":92},[57,7309,550],{"class":102},[57,7311,553],{"class":67},[57,7313,556],{"class":102},[57,7315,559],{"class":92},[57,7317,562],{"class":63},[57,7319,565],{"class":102},[57,7321,7322],{"class":59,"line":153},[57,7323,150],{"emptyLinePlaceholder":22},[57,7325,7326,7328,7330,7332,7334],{"class":59,"line":184},[57,7327,547],{"class":92},[57,7329,2888],{"class":67},[57,7331,531],{"class":92},[57,7333,2893],{"class":63},[57,7335,565],{"class":102},[57,7337,7338],{"class":59,"line":202},[57,7339,150],{"emptyLinePlaceholder":22},[57,7341,7342,7344,7346],{"class":59,"line":214},[57,7343,122],{"class":92},[57,7345,2962],{"class":63},[57,7347,1009],{"class":102},[57,7349,7350,7353,7355,7357,7359,7361,7363,7365,7367,7369,7371],{"class":59,"line":220},[57,7351,7352],{"class":63},"    mutation",[57,7354,3065],{"class":102},[57,7356,248],{"class":106},[57,7358,2582],{"class":102},[57,7360,110],{"class":92},[57,7362,550],{"class":102},[57,7364,248],{"class":106},[57,7366,110],{"class":92},[57,7368,113],{"class":67},[57,7370,3074],{"class":102},[57,7372,614],{"class":92},[57,7374,7375,7378],{"class":59,"line":226},[57,7376,7377],{"class":63},"      deleteComment",[57,7379,7380],{"class":102},"(commentId),\n",[57,7382,7383],{"class":59,"line":231},[57,7384,150],{"emptyLinePlaceholder":22},[57,7386,7387,7390,7392,7394,7396,7398],{"class":59,"line":236},[57,7388,7389],{"class":63},"    onMutate",[57,7391,3065],{"class":102},[57,7393,248],{"class":106},[57,7395,3074],{"class":102},[57,7397,540],{"class":92},[57,7399,467],{"class":102},[57,7401,7402,7405],{"class":59,"line":265},[57,7403,7404],{"class":92},"      const",[57,7406,7407],{"class":67}," oldComments\n",[57,7409,7410,7413,7415,7417,7419,7421],{"class":59,"line":284},[57,7411,7412],{"class":92},"        =",[57,7414,6617],{"class":102},[57,7416,6620],{"class":63},[57,7418,579],{"class":102},[57,7420,582],{"class":63},[57,7422,7423],{"class":102},"[]>([\n",[57,7425,7426,7429],{"class":59,"line":294},[57,7427,7428],{"class":71},"          'comments'",[57,7430,211],{"class":102},[57,7432,7433],{"class":59,"line":299},[57,7434,7435],{"class":102},"          frontmatter.value.id,\n",[57,7437,7438,7441,7443,7445,7447,7449],{"class":59,"line":304},[57,7439,7440],{"class":102},"        ]) ",[57,7442,6933],{"class":92},[57,7444,6640],{"class":102},[57,7446,6643],{"class":92},[57,7448,464],{"class":63},[57,7450,6648],{"class":102},[57,7452,7453],{"class":59,"line":309},[57,7454,150],{"emptyLinePlaceholder":22},[57,7456,7457,7459,7462,7464,7467,7469,7472,7474,7477,7479,7482,7485,7487,7489],{"class":59,"line":329},[57,7458,7404],{"class":92},[57,7460,7461],{"class":67}," newComments",[57,7463,531],{"class":92},[57,7465,7466],{"class":67}," JSON",[57,7468,417],{"class":102},[57,7470,7471],{"class":63},"parse",[57,7473,103],{"class":102},[57,7475,7476],{"class":67},"JSON",[57,7478,417],{"class":102},[57,7480,7481],{"class":63},"stringify",[57,7483,7484],{"class":102},"(oldComments)) ",[57,7486,6643],{"class":92},[57,7488,464],{"class":63},[57,7490,1646],{"class":102},[57,7492,7493,7496,7499],{"class":59,"line":346},[57,7494,7495],{"class":102},"      newComments.",[57,7497,7498],{"class":63},"splice",[57,7500,6670],{"class":102},[57,7502,7503,7506,7508,7510,7513,7515,7518,7520],{"class":59,"line":356},[57,7504,7505],{"class":102},"        newComments.",[57,7507,6667],{"class":63},[57,7509,103],{"class":102},[57,7511,7512],{"class":106},"c",[57,7514,633],{"class":92},[57,7516,7517],{"class":102}," c.id ",[57,7519,6691],{"class":92},[57,7521,7522],{"class":102}," commentId),\n",[57,7524,7525,7528],{"class":59,"line":361},[57,7526,7527],{"class":67},"        1",[57,7529,211],{"class":102},[57,7531,7532],{"class":59,"line":1176},[57,7533,7534],{"class":102},"      )\n",[57,7536,7537],{"class":59,"line":1197},[57,7538,150],{"emptyLinePlaceholder":22},[57,7540,7541,7543,7545,7547,7549],{"class":59,"line":1210},[57,7542,6735],{"class":102},[57,7544,6738],{"class":63},[57,7546,6741],{"class":102},[57,7548,601],{"class":71},[57,7550,7551],{"class":102},", frontmatter.value.id], newComments)\n",[57,7553,7554,7556,7559],{"class":59,"line":1223},[57,7555,6735],{"class":102},[57,7557,7558],{"class":63},"cancelQueries",[57,7560,1009],{"class":102},[57,7562,7563,7566,7568],{"class":59,"line":1228},[57,7564,7565],{"class":102},"        key: [",[57,7567,601],{"class":71},[57,7569,604],{"class":102},[57,7571,7572,7575,7577],{"class":59,"line":1253},[57,7573,7574],{"class":102},"        exact: ",[57,7576,3142],{"class":67},[57,7578,211],{"class":102},[57,7580,7581],{"class":59,"line":1258},[57,7582,7583],{"class":102},"      })\n",[57,7585,7586],{"class":59,"line":1278},[57,7587,150],{"emptyLinePlaceholder":22},[57,7589,7590,7593],{"class":59,"line":1283},[57,7591,7592],{"class":92},"      return",[57,7594,7595],{"class":102}," { oldComments }\n",[57,7597,7598],{"class":59,"line":1305},[57,7599,4904],{"class":102},[57,7601,7602,7605,7607,7610,7612,7615,7618,7621,7623,7625],{"class":59,"line":1314},[57,7603,7604],{"class":63},"    onError",[57,7606,6579],{"class":102},[57,7608,7609],{"class":106},"_",[57,7611,171],{"class":102},[57,7613,7614],{"class":106},"__",[57,7616,7617],{"class":102},", { ",[57,7619,7620],{"class":106},"oldComments",[57,7622,3074],{"class":102},[57,7624,540],{"class":92},[57,7626,467],{"class":102},[57,7628,7629,7632],{"class":59,"line":1319},[57,7630,7631],{"class":92},"      if",[57,7633,7634],{"class":102}," (oldComments) {\n",[57,7636,7637,7640,7642],{"class":59,"line":1329},[57,7638,7639],{"class":102},"        queryCache.",[57,7641,6738],{"class":63},[57,7643,6670],{"class":102},[57,7645,7646,7649,7651],{"class":59,"line":1348},[57,7647,7648],{"class":102},"          [",[57,7650,601],{"class":71},[57,7652,604],{"class":102},[57,7654,7655],{"class":59,"line":1358},[57,7656,7657],{"class":102},"          oldComments,\n",[57,7659,7660],{"class":59,"line":1364},[57,7661,7662],{"class":102},"        )\n",[57,7664,7665],{"class":59,"line":1374},[57,7666,3041],{"class":102},[57,7668,7669],{"class":59,"line":1379},[57,7670,4904],{"class":102},[57,7672,7673,7676,7678],{"class":59,"line":1396},[57,7674,7675],{"class":63},"    onSettled",[57,7677,593],{"class":102},[57,7679,614],{"class":92},[57,7681,7682,7684,7686],{"class":59,"line":1405},[57,7683,6735],{"class":102},[57,7685,3123],{"class":63},[57,7687,1009],{"class":102},[57,7689,7690,7692,7694],{"class":59,"line":1416},[57,7691,7565],{"class":102},[57,7693,601],{"class":71},[57,7695,604],{"class":102},[57,7697,7698,7700,7702],{"class":59,"line":1426},[57,7699,7574],{"class":102},[57,7701,3142],{"class":67},[57,7703,211],{"class":102},[57,7705,7706],{"class":59,"line":1437},[57,7707,7708],{"class":102},"      }),\n",[57,7710,7711],{"class":59,"line":1443},[57,7712,223],{"class":102},[57,7714,7715],{"class":59,"line":1465},[57,7716,664],{"class":102},[10,7718,7719],{},"When called, the mutation reads the current comments from the cache, removes the selected comment, and writes the new list back. The comment disappears immediately instead of waiting for the server response.",[10,7721,7722],{},"If the request fails, it restores the previous list so the comment reappears. In either case, it invalidates the query so the next result reflects the server.",[10,7724,7725,7726,7728],{},"Then, we can use this mutation in the actions of the ",[42,7727,930],{}," component:",[47,7730,7732],{"className":951,"code":7731,"filename":953,"language":954,"meta":53,"style":53},"\u003Cscript lang=\"ts\">\n\u002F\u002F ...\n\u003C\u002Fscript>\n\n\u003Cscript lang=\"ts\" setup>\nconst { mutate: deleteComment } = useDeleteComment()\n\u003C\u002Fscript>\n\n\u003Ctemplate>\n  \u003Carticle :class=\"ui.base({ class: [props.class, props.ui?.base] })\">\n    \u003C!-- ... -->\n\n    \u003Cdiv :class=\"ui.footer({ class: props.ui?.footer })\">\n      \u003C!-- ... -->\n\n      \u003Cdiv :class=\"ui.actions({ class: props.ui?.actions })\">\n        \u003C!-- ... -->\n\n        \u003Cbutton\n          v-if=\"props.comment.can.delete\"\n          @click=\"deleteComment({ commentId: props.comment.id })\"\n        >\n          Delete\n        \u003C\u002Fbutton>\n      \u003C\u002Fdiv>\n    \u003C\u002Fdiv>\n  \u003C\u002Farticle>\n\u003C\u002Ftemplate>\n",[42,7733,7734,7748,7752,7760,7764,7780,7800,7808,7812,7820,7834,7838,7842,7856,7860,7864,7878,7882,7886,7893,7903,7913,7918,7923,7931,7939,7947,7955],{"__ignoreMap":53},[57,7735,7736,7738,7740,7742,7744,7746],{"class":59,"line":60},[57,7737,579],{"class":102},[57,7739,964],{"class":963},[57,7741,967],{"class":63},[57,7743,559],{"class":102},[57,7745,972],{"class":71},[57,7747,975],{"class":102},[57,7749,7750],{"class":59,"line":119},[57,7751,3202],{"class":3201},[57,7753,7754,7756,7758],{"class":59,"line":141},[57,7755,1148],{"class":102},[57,7757,964],{"class":963},[57,7759,975],{"class":102},[57,7761,7762],{"class":59,"line":147},[57,7763,150],{"emptyLinePlaceholder":22},[57,7765,7766,7768,7770,7772,7774,7776,7778],{"class":59,"line":153},[57,7767,579],{"class":102},[57,7769,964],{"class":963},[57,7771,967],{"class":63},[57,7773,559],{"class":102},[57,7775,972],{"class":71},[57,7777,1171],{"class":63},[57,7779,975],{"class":102},[57,7781,7782,7784,7786,7788,7790,7792,7794,7796,7798],{"class":59,"line":184},[57,7783,998],{"class":92},[57,7785,550],{"class":102},[57,7787,1235],{"class":106},[57,7789,1238],{"class":102},[57,7791,1241],{"class":67},[57,7793,556],{"class":102},[57,7795,559],{"class":92},[57,7797,1248],{"class":63},[57,7799,565],{"class":102},[57,7801,7802,7804,7806],{"class":59,"line":202},[57,7803,1148],{"class":102},[57,7805,964],{"class":963},[57,7807,975],{"class":102},[57,7809,7810],{"class":59,"line":214},[57,7811,150],{"emptyLinePlaceholder":22},[57,7813,7814,7816,7818],{"class":59,"line":220},[57,7815,579],{"class":102},[57,7817,1324],{"class":963},[57,7819,975],{"class":102},[57,7821,7822,7824,7826,7828,7830,7832],{"class":59,"line":226},[57,7823,1332],{"class":102},[57,7825,1335],{"class":963},[57,7827,1338],{"class":63},[57,7829,559],{"class":102},[57,7831,1343],{"class":71},[57,7833,975],{"class":102},[57,7835,7836],{"class":59,"line":231},[57,7837,4595],{"class":3201},[57,7839,7840],{"class":59,"line":236},[57,7841,150],{"emptyLinePlaceholder":22},[57,7843,7844,7846,7848,7850,7852,7854],{"class":59,"line":265},[57,7845,1351],{"class":102},[57,7847,1384],{"class":963},[57,7849,1338],{"class":63},[57,7851,559],{"class":102},[57,7853,5503],{"class":71},[57,7855,975],{"class":102},[57,7857,7858],{"class":59,"line":284},[57,7859,4619],{"class":3201},[57,7861,7862],{"class":59,"line":294},[57,7863,150],{"emptyLinePlaceholder":22},[57,7865,7866,7868,7870,7872,7874,7876],{"class":59,"line":299},[57,7867,1399],{"class":102},[57,7869,1384],{"class":963},[57,7871,1338],{"class":63},[57,7873,559],{"class":102},[57,7875,5549],{"class":71},[57,7877,975],{"class":102},[57,7879,7880],{"class":59,"line":304},[57,7881,5524],{"class":3201},[57,7883,7884],{"class":59,"line":309},[57,7885,150],{"emptyLinePlaceholder":22},[57,7887,7888,7890],{"class":59,"line":329},[57,7889,1903],{"class":102},[57,7891,7892],{"class":963},"button\n",[57,7894,7895,7898,7900],{"class":59,"line":346},[57,7896,7897],{"class":63},"          v-if",[57,7899,559],{"class":102},[57,7901,7902],{"class":71},"\"props.comment.can.delete\"\n",[57,7904,7905,7908,7910],{"class":59,"line":356},[57,7906,7907],{"class":63},"          @click",[57,7909,559],{"class":102},[57,7911,7912],{"class":71},"\"deleteComment({ commentId: props.comment.id })\"\n",[57,7914,7915],{"class":59,"line":361},[57,7916,7917],{"class":102},"        >\n",[57,7919,7920],{"class":59,"line":1176},[57,7921,7922],{"class":102},"          Delete\n",[57,7924,7925,7927,7929],{"class":59,"line":1197},[57,7926,5576],{"class":102},[57,7928,2798],{"class":963},[57,7930,975],{"class":102},[57,7932,7933,7935,7937],{"class":59,"line":1210},[57,7934,1474],{"class":102},[57,7936,1384],{"class":963},[57,7938,975],{"class":102},[57,7940,7941,7943,7945],{"class":59,"line":1223},[57,7942,1367],{"class":102},[57,7944,1384],{"class":963},[57,7946,975],{"class":102},[57,7948,7949,7951,7953],{"class":59,"line":1228},[57,7950,1520],{"class":102},[57,7952,1335],{"class":963},[57,7954,975],{"class":102},[57,7956,7957,7959,7961],{"class":59,"line":1253},[57,7958,1148],{"class":102},[57,7960,1324],{"class":963},[57,7962,975],{"class":102},[34,7964,7966],{"id":7965},"final-thoughts","Final thoughts",[10,7968,7969],{},"That brings the series to a close. We started with the Laravel project structure and quality tooling, added GitHub authentication and a comment API, synchronized post metadata, connected the frontend and backend, and finally built the interactive comment interface.",[10,7971,7972],{},"The implementation is deliberately small, but the architecture is reusable. The same separation between API functions, queries, mutations, and components can support future features without turning one component into a place for every concern.",[10,7974,7975],{},"If you build on this example, I would love to see what you create. Possible extensions include:",[7977,7978,7979,7982,7985],"ul",{},[926,7980,7981],{},"Markdown support: Let users write comments in Markdown.",[926,7983,7984],{},"Replies: Let users respond to an existing comment.",[926,7986,7987],{},"Likes: Let users react to a comment.",[10,7989,7990],{},"Which feature would you like to see in a future series? Let me know in the comments.",[10,7992,7993],{},"Happy coding! 👨‍💻",[7995,7996,7997],"style",{},"html pre.shiki code .snPdu, html code.shiki .snPdu{--shiki-light:#6F42C1;--shiki-default:#6F42C1;--shiki-dark:#B392F0}html pre.shiki code .sBjJW, html code.shiki .sBjJW{--shiki-light:#005CC5;--shiki-default:#005CC5;--shiki-dark:#79B8FF}html pre.shiki code .sIIMD, html code.shiki .sIIMD{--shiki-light:#032F62;--shiki-default:#032F62;--shiki-dark:#9ECBFF}html .light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html.light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html pre.shiki code .s8jYJ, html code.shiki .s8jYJ{--shiki-light:#D73A49;--shiki-default:#D73A49;--shiki-dark:#F97583}html pre.shiki code .sxrX7, html code.shiki .sxrX7{--shiki-light:#24292E;--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .sP4rz, html code.shiki .sP4rz{--shiki-light:#E36209;--shiki-default:#E36209;--shiki-dark:#FFAB70}html pre.shiki code .sovSZ, html code.shiki .sovSZ{--shiki-light:#22863A;--shiki-default:#22863A;--shiki-dark:#85E89D}html pre.shiki code .sPrNH, html code.shiki .sPrNH{--shiki-light:#B31D28;--shiki-light-font-style:italic;--shiki-default:#B31D28;--shiki-default-font-style:italic;--shiki-dark:#FDAEB7;--shiki-dark-font-style:italic}html pre.shiki code .sCsY4, html code.shiki .sCsY4{--shiki-light:#6A737D;--shiki-default:#6A737D;--shiki-dark:#6A737D}",{"title":53,"searchDepth":119,"depth":119,"links":7999},[8000,8001,8002,8003,8004,8005],{"id":36,"depth":119,"text":37},{"id":504,"depth":119,"text":505},{"id":2611,"depth":119,"text":2612},{"id":4658,"depth":119,"text":4659},{"id":7254,"depth":119,"text":7255},{"id":7965,"depth":119,"text":7966},"1b2a6cc0-c10f-421a-9344-60cb1583a136","2025-02-25","Build the VitePress comment interface with Pinia Colada queries, mutations, optimistic updates, reusable Vue components, and permissions.","md",null,{},"\u002Fseries\u002Fempower-and-dynamize-our-vitepress-blog-with-a-laravel-api\u002Fsimplifying-comment-querying-and-editing-with-pinia-colada","---\ncontentId: 1b2a6cc0-c10f-421a-9344-60cb1583a136\npart: 8\ntitle: Simplifying Comment Querying and Editing with Pinia Colada\ndescription: Build the VitePress comment interface with Pinia Colada queries, mutations, optimistic updates, reusable Vue components, and permissions.\ndate: 2025-02-25\nseriesSlug: empower-and-dynamize-our-vitepress-blog-with-a-laravel-api\n---\n\nWith authentication and the API connection in place, we can now bring the comment system to the frontend.\n\nThe backend already knows how to list, create, update, and delete comments. Our task is to expose those operations through a clear set of API functions, Pinia Colada queries and mutations, and small Vue components.\n\nThere are several moving parts, but each one follows patterns introduced earlier in the series. By the end of this article, the blog will be able to display, create, edit, and delete comments.\n\n\u003Cvideo autoplay loop muted playsinline>\n  \u003Csource src=\"https:\u002F\u002Fimages.soubiran.dev\u002Fseries\u002Fempower-and-dynamize-our-vitepress-blog-with-a-laravel-api\u002Fsimplifying-comment-querying-and-editing-with-pinia-colada\u002Fdemo.mp4\" type=\"video\u002Fmp4\">\n\n  \u003Cfigcaption>\n    Here is the finished comment system we will build in this article.\n  \u003C\u002Ffigcaption>\n\u003C\u002Fvideo>\n\n## The basics\n\nThe comment system is a new frontend feature, so we will create a folder in `.vitepress\u002Ftheme` for its components, queries, mutations, and API calls.\n\n```bash [terminal]\nmkdir -p .vitepress\u002Ftheme\u002Fcomments\n```\n\nAs with the user feature, put the API calls in an `api.ts` file:\n\n```ts [.vitepress\u002Ftheme\u002Fcomments\u002Fapi.ts]\nexport function fetchComments(postId: number) {\n  return api(`api\u002Fposts\u002F${postId}\u002Fcomments`)\n}\n\nexport function postComment(postId: number, content: string) {\n  return api(`api\u002Fposts\u002F${postId}\u002Fcomments`, {\n    method: 'POST',\n    body: { content },\n  })\n}\n\nexport function putComment(commentId: number, content: string) {\n  return api(`api\u002Fcomments\u002F${commentId}`, {\n    method: 'PUT',\n    body: { content },\n  })\n}\nexport function deleteComment(commentId: number) {\n  return api(`api\u002Fcomments\u002F${commentId}`, {\n    method: 'DELETE',\n  })\n}\n```\n\nThese four functions map to the four Laravel endpoints:\n\n```php [routes\u002Fapi.php]\nRoute::get('\u002Fposts\u002F{post}\u002Fcomments', [PostCommentController::class, 'index']);\nRoute::post('\u002Fposts\u002F{post}\u002Fcomments', [PostCommentController::class, 'store']);\n\nRoute::put('\u002Fcomments\u002F{comment}', [CommentController::class, 'update']);\nRoute::delete('\u002Fcomments\u002F{comment}', [CommentController::class, 'destroy']);\n```\n\nThe first function retrieves a post's comments with `GET`, the second creates a comment with `POST`, the third updates a comment with `PUT`, and the last deletes one with `DELETE`.\n\nAs explained in the previous article, query functions start with `fetch`, while mutation functions start with the HTTP verb. This naming convention makes their purpose clear.\n\nDefine the comment type next. It mirrors the resource returned by the Laravel API.\n\n```ts [.vitepress\u002Ftheme\u002Fcomments\u002Ftypes\u002Fcomment.ts]\nimport type { User } from '@\u002Fuser\u002Ftypes\u002Fuser'\n\nexport interface Comment {\n  id: number\n  content: string\n  author: User\n}\n```\n\n## Showing comments\n\nWith the API functions and type in place, create a query that retrieves the comments for the current post. We will use it in `BlogShow.vue` to display them.\n\n```ts [.vitepress\u002Ftheme\u002Fcomments\u002Fqueries.ts]\nexport const useComments = defineQuery(() => {\n  const { frontmatter } = useData()\n\n  return useQuery\u003CComment[]>({\n    key: () => ['comments', frontmatter.value.id],\n    query: () =>\n      fetchComments(frontmatter.value.id).then(response => response.data),\n    enabled: typeof document !== 'undefined',\n  })\n})\n```\n\n`defineQuery` creates a composable that runs in the Vue context. That lets us use `useData` to read the current page's frontmatter and request comments for only that post.\n\n---\n\nIn the automation article, we added an `id` property to each post's frontmatter. This unique value connects the frontend post to its backend record, so we can request comments with it.\n\n> The frontend calls this value `id`, while the database calls it `meta_id`.\n\nWhen the frontend requests `\u002Fapi\u002Fposts\u002F2\u002Fcomments`, `2` refers to `meta_id`, not the database's internal `id`. If the database record with internal ID `1` has `meta_id` `2`, default route model binding would look for internal ID `2` instead. That would return the wrong post or no post at all.\n\n::callout{icon=\"i-ph-info-duotone\" color=\"info\"}\nRoute model binding lets Laravel inject the model matching a route parameter. For `\u002Fposts\u002F{post}`, Laravel uses the parameter name and the controller argument type to determine which `Post` record to retrieve.\n::\n\nTo correct this, we need to customize the route key name in the `Post` model. This way, we can tell Laravel to use the `meta_id` column instead of the default `id` column.\n\n```php [app\u002FModels\u002FPost.php]\nfinal class Post extends Model\n{\n    \u002F**\n     * Get the route key for the model.\n     *\u002F\n    public function getRouteKeyName(): string\n    {\n        return 'meta_id';\n    }\n}\n```\n\nAdd two tests to ensure that posts are always retrieved by `meta_id`:\n\n```php [tests\u002FUnit\u002FModels\u002FPostTest.php]\ntest('route key name', function () {\n    expect((new Post())->getRouteKeyName())->toBe('meta_id');\n});\n```\n\n```php [tests\u002FHttp\u002FApi\u002FPost\u002FComment\u002FIndexTest.php]\nit('returns comments by using the post meta id', function () {\n    Comment::factory()\n        ->for(Post::factory()->create(['id' => 1, 'meta_id' => 5]))\n        ->create();\n\n    $this->getJson(route('posts.comments', ['post' => 5]))\n        ->assertJson(\n            fn (AssertableJson $json) => $json\n                ->has(\n                    'data',\n                    1,\n                )\n        );\n});\n```\n\n---\n\nNow that the query uses the correct post, display the comments in `BlogShow.vue`.\n\nCreate three components in `.vitepress\u002Ftheme\u002Fcomments\u002Fcomponents`:\n\n1. `Comment.vue`: Displays one comment.\n2. `CommentList.vue`: Displays a list of comments.\n3. `CommentSection.vue`: Displays the comment section and its list.\n\n`Comment.vue` is a presentational component. It receives a comment through its props and displays it.\n\n```vue [.vitepress\u002Ftheme\u002Fcomments\u002Fcomponents\u002FComment.vue]\n\u003Cscript lang=\"ts\">\nimport type { Comment } from '@\u002Fcomments\u002Ftypes\u002Fcomment'\n\nconst blogComment = tv({\n  slots: {\n    base: 'space-y-4',\n    content: '',\n    author: 'flex items-center gap-2 font-semibold',\n    authorAvatar: 'size-8 rounded-full',\n  },\n})\n\nexport interface BlogCommentProps {\n  comment: Comment\n  class?: any\n  ui?: Partial\u003Ctypeof blogComment.slots>\n}\nexport interface BlogCommentEmits {}\nexport interface BlogCommentSlots {}\n\u003C\u002Fscript>\n\n\u003Cscript lang=\"ts\" setup>\nconst props = defineProps\u003CBlogCommentProps>()\ndefineEmits\u003CBlogCommentEmits>()\ndefineSlots\u003CBlogCommentSlots>()\n\nconst { mutate: deleteComment } = useDeleteComment()\n\nconst update = ref(false)\n\nconst ui = computed(() => blogComment())\n\u003C\u002Fscript>\n\n\u003Ctemplate>\n  \u003Carticle :class=\"ui.base({ class: [props.class, props.ui?.base] })\">\n    \u003Cp>\n      {{ props.comment.content }}\n    \u003C\u002Fp>\n\n    \u003Cdiv :class=\"ui.author({ class: props.ui?.author })\">\n      \u003Cimg\n        v-if=\"props.comment.author.avatar\"\n        :src=\"props.comment.author.avatar\"\n        :class=\"ui.authorAvatar({ class: props.ui?.authorAvatar })\"\n      >\n      \u003Ctemplate v-if=\"props.comment.author.name\">\n        {{ props.comment.author.name }} ({{ props.comment.author.username }})\n      \u003C\u002Ftemplate>\n      \u003Ctemplate v-else>\n        {{ props.comment.author.username }}\n      \u003C\u002Ftemplate>\n    \u003C\u002Fdiv>\n  \u003C\u002Farticle>\n\u003C\u002Ftemplate>\n```\n\n`CommentList.vue` is also presentational. It receives a list and renders each item with `Comment.vue`.\n\n```vue [.vitepress\u002Ftheme\u002Fcomments\u002Fcomponents\u002FCommentList.vue]\n\u003Cscript lang=\"ts\">\nimport type { Comment } from '@\u002Fcomments\u002Ftypes\u002Fcomment'\n\nconst blogComments = tv({\n  slots: {\n    base: 'space-y-8',\n    empty: '',\n  },\n})\n\nexport interface BlogCommentsProps {\n  comments: Comment[]\n  class?: any\n  ui?: Partial\u003Ctypeof blogComments.slots>\n}\nexport interface BlogCommentsEmits {}\nexport interface BlogCommentsSlots {}\n\u003C\u002Fscript>\n\n\u003Cscript lang=\"ts\" setup>\nconst props = defineProps\u003CBlogCommentsProps>()\ndefineEmits\u003CBlogCommentsEmits>()\ndefineSlots\u003CBlogCommentsSlots>()\n\nconst ui = computed(() => blogComments())\n\u003C\u002Fscript>\n\n\u003Ctemplate>\n  \u003Col :class=\"ui.base({ class: props.ui?.base })\">\n    \u003Cli\n      v-if=\"props.comments.length === 0\"\n      :class=\"ui.empty({ class: props.ui?.empty })\"\n    >\n      No comments yet.\n    \u003C\u002Fli>\n    \u003Ctemplate v-else>\n      \u003Cli v-for=\"comment in props.comments\" :key=\"comment.id\">\n        \u003CComment :comment=\"comment\" \u002F>\n      \u003C\u002Fli>\n    \u003C\u002Ftemplate>\n  \u003C\u002Fol>\n\u003C\u002Ftemplate>\n```\n\nFinally, `CommentSection.vue` displays the titled section and fetches the comments:\n\n```vue [.vitepress\u002Ftheme\u002Fcomments\u002Fcomponents\u002FCommentSection.vue]\n\u003Cscript lang=\"ts\">\nconst blogCommentsSection = tv({\n  slots: {\n    base: 'space-y-12',\n    title: 'text-2xl font-bold',\n    list: 'space-y-8',\n  },\n})\n\nexport interface BlogCommentsSectionProps {\n  class?: any\n  ui?: Partial\u003Ctypeof blogCommentsSection.slots>\n}\nexport interface BlogCommentsSectionEmits {}\nexport interface BlogCommentsSectionSlots {}\n\u003C\u002Fscript>\n\n\u003Cscript lang=\"ts\" setup>\nconst props = defineProps\u003CBlogCommentsSectionProps>()\ndefineEmits\u003CBlogCommentsSectionEmits>()\ndefineSlots\u003CBlogCommentsSectionSlots>()\n\nconst { state: commentsState } = useComments() \u002F\u002F [!code highlight]\n\nconst ui = computed(() => blogCommentsSection())\n\u003C\u002Fscript>\n\n\u003Ctemplate>\n  \u003Csection :class=\"ui.base({ class: [props.class, props.ui?.base] })\">\n    \u003Ch2 :class=\"ui.title({ class: props.ui?.title })\">\n      Comments\n    \u003C\u002Fh2>\n\n    \u003Cdiv v-if=\"commentsState.status === 'pending'\">\n      Loading comments...\n    \u003C\u002Fdiv>\n    \u003Cdiv v-else-if=\"commentsState.status === 'error'\">\n      Error loading comments\n    \u003C\u002Fdiv>\n\n    \u003Ctemplate v-else>\n      \u003CCommentList\n        :comments=\"commentsState.data\"\n        :class=\"ui.list({ class: props.ui?.list })\"\n      \u002F>\n    \u003C\u002Ftemplate>\n  \u003C\u002Fsection>\n\u003C\u002Ftemplate>\n```\n\nUse `CommentSection` in `BlogShow.vue` to display the post's comments.\n\n```vue [.vitepress\u002Ftheme\u002FBlogShow.vue]\n\u003Cscript lang=\"ts\" setup>\nconst { frontmatter } = useData()\n\u003C\u002Fscript>\n\n\u003Ctemplate>\n  \u003CPage>\n    \u003CBlogArticle :title=\"frontmatter.title\" \u002F>\n\n    \u003CCommentSection \u002F> \u003C!-- [!code ++] -->\n\n    \u003CPageFooter :back-to=\"{ href: '\u002Fblog', label: 'Back to Blog' }\" \u002F>\n  \u003C\u002FPage>\n\u003C\u002Ftemplate>\n```\n\nSplitting the feature into focused components makes it easier to add features, change the design, fix bugs, and write tests.\n\nStart the frontend and backend with the seeded database to see the comments on a post.\n\n## Adding a comment\n\nTo add a comment, we need a form with a textarea. The form will use the `postComment` mutation.\n\nCreate a `CommentForm.vue` component for the form.\n\nStart with the template:\n\n```vue [.vitepress\u002Ftheme\u002Fcomments\u002Fcomponents\u002FCommentForm.vue]\n\u003Ctemplate>\n  \u003Cform\n    :class=\"ui.base({ class: [props.class, props.ui?.base] })\"\n    @submit.prevent=\"onSubmit\"\n  >\n    \u003Ctextarea\n      v-model=\"content\"\n      placeholder=\"Write a comment...\"\n      :class=\"ui.textarea({ class: props.ui?.textarea })\"\n    \u002F>\n\n    \u003Cspan v-if=\"error\" class=\"text-red-500\">{{ error.data.message }}\u003C\u002Fspan>\n\n    \u003CButton\n      type=\"submit\"\n      label=\"Comment\"\n      :class=\"ui.button({ class: props.ui?.button })\"\n      :disabled=\"isLoading\"\n    \u002F>\n  \u003C\u002Fform>\n\u003C\u002Ftemplate>\n```\n\nThen define the mutation in the script:\n\n```vue [.vitepress\u002Ftheme\u002Fcomments\u002Fcomponents\u002FCommentForm.vue]\n\u003Cscript lang=\"ts\" setup>\nconst { frontmatter } = useData()\nconst queryCache = useQueryCache()\n\nconst content = ref('')\n\nconst {\n  mutate: storeComment,\n  isLoading,\n  error,\n} = useMutation\u003C\n  {\n    data: Comment\n  },\n  { postId: number, content: string, parentId?: number },\n  {\n    data: {\n      message: string\n      errors: {\n        content: string[]\n      }\n    }\n  }\n>({\n  mutation: ({ postId, content }) => postComment(postId, content),\n  onSuccess: () => {\n    content.value = ''\n  },\n  onSettled: () =>\n    queryCache.invalidateQueries({\n      key: ['comments', frontmatter.value.id],\n      exact: true,\n    }),\n})\n\u003C\u002Fscript>\n```\n\nThe mutation exposes the action, loading state, and error. We can use them to show an error when the request fails and disable the button while it is in progress. A loading indicator could be added in the same place.\n\nThe error shape matches Laravel's validation response. Disabling the button prevents duplicate submissions while the request is running.\n\n::callout{icon=\"i-ph-info-duotone\" color=\"info\"}\nTo keep the example simple, the form only disables the submit button while it is busy.\n::\n\nHandle the submit event by calling the mutation:\n\n```vue [.vitepress\u002Ftheme\u002Fcomments\u002Fcomponents\u002FCommentForm.vue]\n\u003Cscript lang=\"ts\" setup>\n\u002F\u002F ...\n\nfunction onSubmit() {\n  storeComment({ postId: frontmatter.value.id, content: content.value })\n}\n\u003C\u002Fscript>\n```\n\n::callout{icon=\"i-ph-info-duotone\" color=\"info\"}\nI know this form will eventually create and edit comments, so I am designing it for both cases now. That avoids duplicated code, as the next section will demonstrate.\n::\n\nThe complete form looks like this:\n\n```vue [.vitepress\u002Ftheme\u002Fcomments\u002Fcomponents\u002FCommentForm.vue]\n\u003Cscript lang=\"ts\">\nimport type { Comment } from '@\u002Fcomments\u002Ftypes\u002Fcomment'\n\nconst commentForm = tv({\n  slots: {\n    base: 'flex flex-col gap-4',\n    textarea:\n      'border-4 border-black px-8 py-4 shadow-[4px_4px_0_black] focus:outline-none',\n    button: '',\n  },\n})\n\nexport interface CommentFormProps {\n  comment?: Comment\n  class?: any\n  ui?: Partial\u003Ctypeof commentForm.slots>\n}\nexport interface CommentFormEmits {\n  submit: [void]\n}\nexport interface CommentFormSlots {}\n\u003C\u002Fscript>\n\n\u003Cscript lang=\"ts\" setup>\nconst props = defineProps\u003CCommentFormProps>()\nconst emit = defineEmits\u003CCommentFormEmits>()\ndefineSlots\u003CCommentFormSlots>()\n\nconst { frontmatter } = useData()\nconst queryCache = useQueryCache()\n\nconst content = ref(props.comment?.content ?? '')\n\nconst {\n  mutate: storeComment,\n  isLoading,\n  error,\n} = useMutation\u003C\n  {\n    data: Comment\n  },\n  { postId: number, content: string, parentId?: number },\n  {\n    data: {\n      message: string\n      errors: {\n        content: string[]\n      }\n    }\n  }\n>({\n  mutation: ({ postId, content }) => postComment(postId, content),\n  onSuccess: () => {\n    content.value = ''\n  },\n  onSettled: () =>\n    queryCache.invalidateQueries({\n      key: ['comments', frontmatter.value.id],\n      exact: true,\n    }),\n})\n\nfunction onSubmit() {\n  storeComment({ postId: frontmatter.value.id, content: content.value })\n}\n\nconst ui = computed(() => commentForm())\n\u003C\u002Fscript>\n\n\u003Ctemplate>\n  \u003Cform\n    :class=\"ui.base({ class: [props.class, props.ui?.base] })\"\n    @submit.prevent=\"onSubmit\"\n  >\n    \u003Ctextarea\n      v-model=\"content\"\n      placeholder=\"Write a comment...\"\n      :class=\"ui.textarea({ class: props.ui?.textarea })\"\n    \u002F>\n\n    \u003Cspan v-if=\"error\" class=\"text-red-500\">{{ error.data.message }}\u003C\u002Fspan>\n\n    \u003CButton\n      type=\"submit\"\n      label=\"Comment\"\n      :class=\"ui.button({ class: props.ui?.button })\"\n      :disabled=\"isLoading\"\n    \u002F>\n  \u003C\u002Fform>\n\u003C\u002Ftemplate>\n```\n\nPlace the form in an `AddComment.vue` component with a title. Show the form only to authenticated users so visitors do not see a control they cannot use:\n\n```vue [.vitepress\u002Ftheme\u002Fcomments\u002Fcomponents\u002FAddComment.vue]\n\u003Cscript lang=\"ts\">\nconst addComment = tv({\n  slots: {\n    base: 'space-y-4',\n    header: 'flex items-center gap-2',\n    avatar: 'size-8 rounded-full',\n    title: 'text-lg font-semibold',\n  },\n})\n\nexport interface AddCommentProps {\n  class?: any\n  ui?: Partial\u003Ctypeof addComment.slots>\n}\nexport interface AddCommentEmits {}\nexport interface AddCommentSlots {}\n\u003C\u002Fscript>\n\n\u003Cscript lang=\"ts\" setup>\nconst props = defineProps\u003CAddCommentProps>()\ndefineEmits\u003CAddCommentEmits>()\ndefineSlots\u003CAddCommentSlots>()\n\nconst { state: userState } = useUser()\n\nconst loginUrl = `${import.meta.env.VITE_API_URL}\u002Fauth\u002Fgithub\u002Fredirect`\n\nconst ui = computed(() => addComment())\n\u003C\u002Fscript>\n\n\u003Ctemplate>\n  \u003Cdiv :class=\"ui.base({ class: [props.class, props.ui?.base] })\">\n    \u003Cdiv :class=\"ui.header({ class: props.ui?.header })\">\n      \u003Cimg\n        v-if=\"userState.data && userState.data.avatar\"\n        :src=\"userState.data.avatar\"\n        :class=\"ui.avatar({ class: props.ui?.avatar })\"\n      >\n      \u003Ch3 :class=\"ui.title({ class: props.ui?.title })\">\n        Add a comment\n      \u003C\u002Fh3>\n    \u003C\u002Fdiv>\n\n    \u003CCommentForm v-if=\"userState.data\" \u002F>\n    \u003Cdiv v-else class=\"flex justify-center\">\n      \u003CButton label=\"Login to comment\" :href=\"loginUrl\" \u002F>\n    \u003C\u002Fdiv>\n  \u003C\u002Fdiv>\n\u003C\u002Ftemplate>\n```\n\nUnauthenticated users see a button that redirects them to GitHub. We use `useUser` here just as we did in the header. Pinia Colada deduplicates the request and shares the result, so we do not need prop drilling or a high-level fetch far from where the data is used.\n\nFinally, use `AddComment` in `CommentSection.vue` below the list:\n\n```vue [.vitepress\u002Ftheme\u002Fcomments\u002Fcomponents\u002FCommentSection.vue]\n\u003Ctemplate>\n  \u003Csection :class=\"ui.base({ class: [props.class, props.ui?.base] })\">\n    \u003C!-- ... -->\n\n    \u003C!-- eslint-disable-next-line vue\u002Fvalid-v-else -->\n    \u003Ctemplate v-else>\n      \u003C!-- ... -->\n\n      \u003CAddComment \u002F>\n    \u003C\u002Ftemplate>\n  \u003C\u002Fsection>\n\u003C\u002Ftemplate>\n```\n\n## Editing a comment\n\nUsers should be able to edit their own comments, so we need to handle that state in the interface.\n\nHow do we know which comments the current user may edit? The backend uses `CommentPolicy` for that decision. The frontend should not display an edit button when the policy denies access.\n\nWe could duplicate the policy in the frontend, but that would create two sources of truth. Any backend policy change would then require a matching frontend change, and that duplication would become harder to maintain as the policy grows.\n\nInstead, return a `can` property with each comment. The backend can populate it by reusing the policy, giving the frontend the permissions it needs without duplicating the rules.\n\nIn the backend, we already check if the user is allowed to edit or delete a comment in the controller:\n\n```php [app\u002FHttp\u002FControllers\u002FApi\u002FCommentController.php]\nfinal class CommentController extends Controller\n{\n    public function destroy(Comment $comment): Response\n    {\n        Gate::authorize('delete', $comment); \u002F\u002F [!code highlight]\n    }\n}\n```\n\nWe also need to expose whether the user may delete the comment, so we will handle both permissions together.\n\nIn the `CommentResource`, we can create a new property called `can` that will contain the permissions of the user on the comment:\n\n```php [app\u002FHttp\u002FResources\u002FCommentResource.php]\nfinal class CommentResource extends JsonResource\n{\n    public function toArray(Request $request): array\n    {\n        return [\n            \u002F\u002F ...\n            'can' => [\n                'update' => $request->user()?->can('update', $this->resource) ?? false, \u002F\u002F [!code highlight]\n                'delete' => $request->user()?->can('delete', $this->resource) ?? false, \u002F\u002F [!code highlight]\n            ],\n        ];\n    }\n}\n```\n\nThe frontend can now check both permissions. The response will look like this:\n\n```json [Example]\n{\n  \"data\": {\n    \"id\": 1,\n    \"content\": \"This is a comment\",\n    \"author\": {\n      \"id\": 1,\n      \"name\": \"John Doe\",\n      \"username\": \"johndoe\",\n      \"avatar\": null\n    },\n    \"can\": {\n      \"update\": true, \u002F\u002F [!code highlight]\n      \"delete\": true \u002F\u002F [!code highlight]\n    }\n  }\n}\n```\n\nThe frontend can use these values in `v-if` conditions to display the appropriate actions.\n\nUpdate the tests to verify that `can` is populated correctly.\n\n```php [tests\u002FHttp\u002FApi\u002FComment\u002FUpdateTest.php]\nit('returns the comment', function () {\n    \u002F\u002F ...\n\n    $this->actingAs($user)\n        ->putJson(route('comments.update', $comment), [\n            'content' => 'Updated content',\n        ])\n        ->assertJson(\n            fn (AssertableJson $json) => $json\n                ->has(\n                    'data',\n                    fn (AssertableJson $json) => $json\n                        \u002F\u002F ...\n                        ->has(\n                            'can',\n                            fn (AssertableJson $json) => $json\n                                ->where('update', true) \u002F\u002F [!code highlight]\n                                ->where('delete', true) \u002F\u002F [!code highlight]\n                        )\n                )\n        );\n});\n```\n\n```php [tests\u002FHttp\u002FApi\u002FPost\u002FComment\u002FIndexTest.php]\nit('returns comments', function () {\n    \u002F\u002F ...\n\n    $this->getJson(route('posts.comments', $post))\n        ->assertJson(\n            fn (AssertableJson $json) => $json\n                ->has(\n                    'data',\n                    2,\n                    fn (AssertableJson $json) => $json\n                        \u002F\u002F ...\n                        ->has(\n                            'can',\n                            fn (AssertableJson $json) => $json\n                                ->where('update', false) \u002F\u002F [!code highlight]\n                                ->where('delete', false) \u002F\u002F [!code highlight]\n                        )\n                )\n        );\n});\n\n```\n\n```php [tests\u002FHttp\u002FApi\u002FPost\u002FComment\u002FIndexTest.php]\nit('returns the created comment', function () {\n    \u002F\u002F ...\n\n    $response\n        ->assertJson(\n            fn (AssertableJson $json) => $json\n                ->has(\n                    'data',\n                    fn (AssertableJson $json) => $json\n                        \u002F\u002F ...\n                        ->has(\n                            'can',\n                            fn (AssertableJson $json) => $json\n                                ->where('update', true) \u002F\u002F [!code highlight]\n                                ->where('delete', true) \u002F\u002F [!code highlight]\n                        )\n                )\n        );\n});\n```\n\nWith the API response in place, add an edit button to `Comment.vue`.\n\nBefore changing the component, update the `Comment` interface to include `can`:\n\n```ts [.vitepress\u002Ftheme\u002Fcomments\u002Ftypes\u002Fcomment.ts]\nimport type { User } from '@\u002Fuser\u002Ftypes\u002Fuser'\n\nexport interface Comment {\n  id: number\n  content: string\n  author: User\n\n  can: {\n    update: boolean\n    delete: boolean\n  }\n}\n```\n\nThe button will be displayed only when the backend grants the `update` permission.\n\n```vue [.vitepress\u002Ftheme\u002Fcomments\u002Fcomponents\u002FComment.vue]\n\u003Cscript lang=\"ts\">\nconst blogComment = tv({\n  slots: {\n    footer: 'flex items-center justify-between',\n    actions: 'flex items-center gap-2',\n  },\n})\n\u003C\u002Fscript>\n\n\u003Cscript lang=\"ts\" setup>\n\u002F\u002F ...\n\u003C\u002Fscript>\n\n\u003Ctemplate>\n  \u003Carticle :class=\"ui.base({ class: [props.class, props.ui?.base] })\">\n    \u003C!-- ... -->\n\n    \u003Cdiv :class=\"ui.footer({ class: props.ui?.footer })\">\n      \u003Cdiv :class=\"ui.author({ class: props.ui?.author })\">\n        \u003C!-- ... -->\n      \u003C\u002Fdiv>\n\n      \u003Cdiv :class=\"ui.actions({ class: props.ui?.actions })\">\n        \u003Cbutton v-if=\"props.comment.can.update\">\n          Edit\n        \u003C\u002Fbutton>\n      \u003C\u002Fdiv>\n    \u003C\u002Fdiv>\n  \u003C\u002Farticle>\n\u003C\u002Ftemplate>\n```\n\nThe backend policy now controls whether this button is shown.\n\nWhen the user clicks the button, show `CommentForm.vue` in place of the comment content so the comment can be edited inline.\n\nAdd a ref to `Comment.vue` to track edit mode:\n\n```vue [.vitepress\u002Ftheme\u002Fcomments\u002Fcomponents\u002FComment.vue]\n\u003Cscript lang=\"ts\">\n\u002F\u002F ...\n\u003C\u002Fscript>\n\n\u003Cscript lang=\"ts\" setup>\nconst update = ref(false)\n\u003C\u002Fscript>\n\n\u003Ctemplate>\n  \u003Carticle :class=\"ui.base({ class: [props.class, props.ui?.base] })\">\n    \u003CCommentForm\n      v-if=\"update\"\n      :comment=\"props.comment\"\n      @submit=\"update = false\"\n    \u002F>\n    \u003Cp v-else>\n      {{ props.comment.content }}\n    \u003C\u002Fp>\n\n    \u003Cdiv :class=\"ui.footer({ class: props.ui?.footer })\">\n      \u003C!-- ... -->\n\n      \u003Cdiv :class=\"ui.actions({ class: props.ui?.actions })\">\n        \u003Cbutton v-if=\"props.comment.can.update\" @click=\"update = !update\">\n          Edit\n        \u003C\u002Fbutton>\n      \u003C\u002Fdiv>\n    \u003C\u002Fdiv>\n  \u003C\u002Farticle>\n\u003C\u002Ftemplate>\n```\n\nFinally, update `CommentForm.vue` for edit mode. Pass the comment as a prop and initialize the textarea with its content. The presence of that prop tells the form which mode to use.\n\n```vue [.vitepress\u002Ftheme\u002Fcomments\u002Fcomponents\u002FCommentForm.vue]\n\u003Cscript lang=\"ts\">\nimport type { Comment } from '@\u002Fcomments\u002Ftypes\u002Fcomment'\n\nconst commentForm = tv({\n  slots: {\n    base: 'flex flex-col gap-4',\n    textarea:\n      'border-4 border-black px-8 py-4 shadow-[4px_4px_0_black] focus:outline-none',\n    button: '',\n  },\n})\n\nexport interface CommentFormProps {\n  comment?: Comment\n  class?: any\n  ui?: Partial\u003Ctypeof commentForm.slots>\n}\nexport interface CommentFormEmits {\n  submit: [void]\n}\nexport interface CommentFormSlots {}\n\u003C\u002Fscript>\n\n\u003Cscript lang=\"ts\" setup>\nconst props = defineProps\u003CCommentFormProps>()\nconst emit = defineEmits\u003CCommentFormEmits>()\ndefineSlots\u003CCommentFormSlots>()\n\nconst { frontmatter } = useData()\nconst queryCache = useQueryCache()\n\nconst content = ref(props.comment?.content ?? '')\n\nconst {\n  mutate: storeComment,\n  isLoading: isStoreCommentLoading,\n  error: storeCommentError,\n} = useMutation\u003C\n  {\n    data: Comment\n  },\n  { postId: number, content: string, parentId?: number },\n  {\n    data: {\n      message: string\n      errors: {\n        content: string[]\n      }\n    }\n  }\n>({\n  mutation: ({ postId, content }) => postComment(postId, content),\n  onSuccess: () => {\n    content.value = ''\n  },\n  onSettled: () =>\n    queryCache.invalidateQueries({\n      key: ['comments', frontmatter.value.id],\n      exact: true,\n    }),\n})\n\nconst {\n  mutate: updateComment,\n  isLoading: isUpdateCommentLoading,\n  error: updateCommentError,\n} = useMutation\u003C\n  {\n    data: Comment\n  },\n  { commentId: number, content: string },\n  {\n    data: {\n      message: string\n      errors: {\n        content: string[]\n      }\n    }\n  }\n>({\n  mutation: ({ commentId, content }) => putComment(commentId, content),\n  onSuccess: (data) => {\n    content.value = ''\n\n    const comments\n      = queryCache.getQueryData\u003CComment[]>(['comments', frontmatter.value.id])\n        ?? ([] as Comment[])\n\n    const index = comments.findIndex(\n      (comment: Comment) => comment.id === data.data.id,\n    )\n    if (index !== -1) {\n      comments[index] = data.data\n      queryCache.setQueryData(['comments', frontmatter.value.id], comments)\n    }\n\n    emit('submit')\n  },\n  onSettled: () =>\n    queryCache.invalidateQueries({\n      key: ['comments', frontmatter.value.id],\n      exact: true,\n    }),\n})\n\nfunction onSubmit() {\n  if (props.comment) {\n    updateComment({\n      commentId: props.comment.id,\n      content: content.value,\n    })\n  }\n  else {\n    storeComment({ postId: frontmatter.value.id, content: content.value })\n  }\n}\n\nconst error = computed(\n  () => storeCommentError.value || updateCommentError.value,\n)\nconst isLoading = computed(\n  () => isStoreCommentLoading.value || isUpdateCommentLoading.value,\n)\n\nconst ui = computed(() => commentForm())\n\u003C\u002Fscript>\n\n\u003Ctemplate>\n  \u003Cform\n    :class=\"ui.base({ class: [props.class, props.ui?.base] })\"\n    @submit.prevent=\"onSubmit\"\n  >\n    \u003Ctextarea\n      v-model=\"content\"\n      placeholder=\"Write a comment...\"\n      :class=\"ui.textarea({ class: props.ui?.textarea })\"\n    \u002F>\n\n    \u003Cspan v-if=\"error\" class=\"text-red-500\">{{ error.data.message }}\u003C\u002Fspan>\n\n    \u003CButton\n      type=\"submit\"\n      :label=\"props.comment ? 'Edit' : 'Comment'\"\n      :class=\"ui.button({ class: props.ui?.button })\"\n      :disabled=\"isLoading\"\n    \u002F>\n  \u003C\u002Fform>\n\u003C\u002Ftemplate>\n```\n\nThe textarea starts with the comment's content when the `comment` prop is set. We combine the store and update loading states so the button is disabled during either request, and combine their errors so one message can be displayed. The button label changes with the mode. On submit, the form checks whether `comment` exists and calls either `updateComment` or `storeComment`.\n\n::callout{icon=\"i-ph-lightbulb-duotone\" color=\"success\"}\nReusing `CommentForm.vue` works well here because creation and editing differ only in the initial value and the API endpoint.\n::\n\n## Deleting a comment\n\nTo delete a comment, create a `useDeleteComment` mutation. It will use an optimistic update to give immediate feedback while the request is running.\n\n```ts [.vitepress\u002Ftheme\u002Fcomments\u002Fmutations\u002Fcomments.ts]\nimport type { Comment } from '@\u002Fcomments\u002Ftypes\u002Fcomment'\n\nexport const useDeleteComment = defineMutation(() => {\n  const { frontmatter } = useData()\n\n  const queryCache = useQueryCache()\n\n  return useMutation({\n    mutation: ({ commentId }: { commentId: number }) =>\n      deleteComment(commentId),\n\n    onMutate: ({ commentId }) => {\n      const oldComments\n        = queryCache.getQueryData\u003CComment[]>([\n          'comments',\n          frontmatter.value.id,\n        ]) || ([] as Comment[])\n\n      const newComments = JSON.parse(JSON.stringify(oldComments)) as Comment[]\n      newComments.splice(\n        newComments.findIndex(c => c.id === commentId),\n        1,\n      )\n\n      queryCache.setQueryData(['comments', frontmatter.value.id], newComments)\n      queryCache.cancelQueries({\n        key: ['comments', frontmatter.value.id],\n        exact: true,\n      })\n\n      return { oldComments }\n    },\n    onError: (_, __, { oldComments }) => {\n      if (oldComments) {\n        queryCache.setQueryData(\n          ['comments', frontmatter.value.id],\n          oldComments,\n        )\n      }\n    },\n    onSettled: () =>\n      queryCache.invalidateQueries({\n        key: ['comments', frontmatter.value.id],\n        exact: true,\n      }),\n  })\n})\n```\n\nWhen called, the mutation reads the current comments from the cache, removes the selected comment, and writes the new list back. The comment disappears immediately instead of waiting for the server response.\n\nIf the request fails, it restores the previous list so the comment reappears. In either case, it invalidates the query so the next result reflects the server.\n\nThen, we can use this mutation in the actions of the `Comment.vue` component:\n\n```vue [.vitepress\u002Ftheme\u002Fcomments\u002Fcomponents\u002FComment.vue]\n\u003Cscript lang=\"ts\">\n\u002F\u002F ...\n\u003C\u002Fscript>\n\n\u003Cscript lang=\"ts\" setup>\nconst { mutate: deleteComment } = useDeleteComment()\n\u003C\u002Fscript>\n\n\u003Ctemplate>\n  \u003Carticle :class=\"ui.base({ class: [props.class, props.ui?.base] })\">\n    \u003C!-- ... -->\n\n    \u003Cdiv :class=\"ui.footer({ class: props.ui?.footer })\">\n      \u003C!-- ... -->\n\n      \u003Cdiv :class=\"ui.actions({ class: props.ui?.actions })\">\n        \u003C!-- ... -->\n\n        \u003Cbutton\n          v-if=\"props.comment.can.delete\"\n          @click=\"deleteComment({ commentId: props.comment.id })\"\n        >\n          Delete\n        \u003C\u002Fbutton>\n      \u003C\u002Fdiv>\n    \u003C\u002Fdiv>\n  \u003C\u002Farticle>\n\u003C\u002Ftemplate>\n```\n\n## Final thoughts\n\nThat brings the series to a close. We started with the Laravel project structure and quality tooling, added GitHub authentication and a comment API, synchronized post metadata, connected the frontend and backend, and finally built the interactive comment interface.\n\nThe implementation is deliberately small, but the architecture is reusable. The same separation between API functions, queries, mutations, and components can support future features without turning one component into a place for every concern.\n\nIf you build on this example, I would love to see what you create. Possible extensions include:\n\n- Markdown support: Let users write comments in Markdown.\n- Replies: Let users respond to an existing comment.\n- Likes: Let users react to a comment.\n\nWhich feature would you like to see in a future series? Let me know in the comments.\n\nHappy coding! 👨‍💻\n",{"title":5,"description":8008},"empower-and-dynamize-our-vitepress-blog-with-a-laravel-api",{"loc":8012},"series\u002Fempower-and-dynamize-our-vitepress-blog-with-a-laravel-api\u002Fsimplifying-comment-querying-and-editing-with-pinia-colada","umDbN7ul3ZG8w56PxlMu0eU0XJjvwHDo-YY8D1B76H8",{"overview":8020,"chapters":8197},{"id":8021,"title":8022,"body":8023,"contentId":8181,"date":8182,"description":8183,"extension":8009,"github":8010,"meetTheInstructor":8184,"meta":8185,"navigation":22,"part":8010,"path":8186,"rawbody":8187,"robots":8010,"schemaOrg":8010,"seo":8188,"seriesSlug":8015,"sitemap":8189,"stem":8190,"subtitle":8191,"topics":8192,"__hash__":8196},"series\u002Fseries\u002Fempower-and-dynamize-our-vitepress-blog-with-a-laravel-api.md","Empower and Enhance Your VitePress Blog with a Laravel API",{"type":7,"value":8024,"toc":8178},[8025,8028,8031,8034,8038,8049,8052,8061,8064,8067,8149,8152,8155,8158,8168,8172],[10,8026,8027],{},"Hello! 👋",[10,8029,8030],{},"After building our VitePress blog, we are ready to make it more dynamic with a Laravel API.",[10,8032,8033],{},"In the previous series, we explored VitePress from the initial project setup to deployment on Cloudflare Pages. We built a functional, automated blog with SEO metadata, Open Graph images, and a GitHub projects page. The blog handled everything at build time, so publishing content was the only task left.",[8035,8036],"callout-read-more",{"id":8037},"43c95b33-041c-4108-ab98-0d21ef60ed7f",[10,8039,8040,8041,8048],{},"This series introduces back-end development by creating a ",[8042,8043,8047],"a",{"href":8044,"rel":8045},"https:\u002F\u002Flaravel.com",[8046],"nofollow","Laravel"," API that gives our blog a few interactive features.",[10,8050,8051],{},"Until now, our blog has been mostly static. Content was generated at build time, with a small amount of data loaded dynamically, and the resulting HTML files were distributed through a CDN. By adding a Laravel API, we will let readers interact with the blog through features such as post reactions and comments.",[10,8053,8054,8055,8060],{},"Although the focus is on the back end, we will also integrate the API into our VitePress blog. We will use Vue.js and ",[8042,8056,8059],{"href":8057,"rel":8058},"https:\u002F\u002Fpinia-colada.esm.dev\u002F",[8046],"Pinia Colada"," as our data-fetching framework. VitePress is a Vue.js application, so we can extend it with the components we need.",[10,8062,8063],{},"The examples are designed to be easy to follow. Unnecessary complexity and over-engineering are neither desirable nor necessary here. We will focus on simplicity, clarity, and efficiency.",[10,8065,8066],{},"Throughout the series, we will build a Laravel API and integrate it with our VitePress blog. We will cover:",[7977,8068,8069,8076,8104,8115,8121,8131,8137,8143],{},[926,8070,8071,8075],{},[8072,8073,8074],"strong",{},"Setting up the Laravel project",": Create a new Laravel project and become familiar with its structure.",[926,8077,8078,8081,8082,171,8087,171,8092,8097,8098,8103],{},[8072,8079,8080],{},"Improving the development workflow",": Configure ",[8042,8083,8086],{"href":8084,"rel":8085},"https:\u002F\u002Flaravel.com\u002Fdocs\u002F11.x\u002Fpint",[8046],"Pint",[8042,8088,8091],{"href":8089,"rel":8090},"https:\u002F\u002Fgithub.com\u002Frectorphp\u002Frector",[8046],"Rector",[8042,8093,8096],{"href":8094,"rel":8095},"https:\u002F\u002Fgithub.com\u002Flarastan\u002Flarastan",[8046],"Larastan",", and ",[8042,8099,8102],{"href":8100,"rel":8101},"https:\u002F\u002Fpestphp.com\u002F",[8046],"Pest"," for formatting, refactoring, static analysis, and testing.",[926,8105,8106,8109,8110,417],{},[8072,8107,8108],{},"Adding social authentication",": Let users sign in with GitHub through ",[8042,8111,8114],{"href":8112,"rel":8113},"https:\u002F\u002Flaravel.com\u002Fdocs\u002F11.x\u002Fsocialite",[8046],"Laravel Socialite",[926,8116,8117,8120],{},[8072,8118,8119],{},"Connecting the applications",": Configure Sanctum, CORS, CSRF protection, and the first requests between the VitePress frontend and the Laravel API.",[926,8122,8123,8126,8127,8130],{},[8072,8124,8125],{},"Managing authentication state",": Use ",[8042,8128,8059],{"href":8057,"rel":8129},[8046]," to retrieve the current user and log out with an optimistic update.",[926,8132,8133,8136],{},[8072,8134,8135],{},"Building the comment API",": Create the models, relationships, endpoints, validation, authorization, and tests for comments.",[926,8138,8139,8142],{},[8072,8140,8141],{},"Keeping the backend in sync",": Generate post metadata from VitePress and synchronize it with the Laravel database.",[926,8144,8145,8148],{},[8072,8146,8147],{},"Building the comment interface",": Fetch, create, edit, and delete comments from the VitePress frontend.",[10,8150,8151],{},"By the end of the series, you will have a blog backed by a Laravel API. Readers will be able to sign in with GitHub and leave comments, and the architecture will be ready for additional interactive features.",[10,8153,8154],{},"Testing is part of the development process and will be included at each stage, so it does not need a dedicated article.",[10,8156,8157],{},"If you have questions, feedback, or suggestions, feel free to share them in the comments. Your input helps improve the series.",[727,8159,8160],{"color":729,"icon":730},[10,8161,8162,8163,8167],{},"This series assumes prior knowledge of TypeScript, Vue.js, and Laravel. If you are unfamiliar with any of these technologies, review the ",[8042,8164,8166],{"href":8165},"\u002Fseries\u002Fcreate-a-blog-with-vitepress-and-vue-js-from-scratch","Create a Blog with VitePress and Vue.js from Scratch"," first.",[34,8169,8171],{"id":8170},"chapters","Chapters",[8173,8174],"series-chapters-list",{"className":8175},[8176,8177],"mx-auto","max-w-5xl",{"title":53,"searchDepth":119,"depth":119,"links":8179},[8180],{"id":8170,"depth":119,"text":8171},"676d45dd-eb18-42ec-803e-b9d6b7f04b42","2024-11-19","Transform your VitePress blog into a dynamic platform with a Laravel API. Leverage backend API capabilities to create advanced features.","I create this series because I love \u003Cstrong>VitePress\u003C\u002Fstrong> and \u003Cstrong>Laravel\u003C\u002Fstrong>. I truly believe that combining the two results in a simple yet \u003Cstrong>powerful solution\u003C\u002Fstrong> for creating a blog. I want to empower developers to enhance their VitePress blogs with a Laravel API to create advanced features.",{},"\u002Fseries\u002Fempower-and-dynamize-our-vitepress-blog-with-a-laravel-api","---\ncontentId: 676d45dd-eb18-42ec-803e-b9d6b7f04b42\ntitle: Empower and Enhance Your VitePress Blog with a Laravel API\nsubtitle: Transform your VitePress blog into a dynamic platform with an API\ndescription: Transform your VitePress blog into a dynamic platform with a Laravel API. Leverage backend API capabilities to create advanced features.\ndate: 2024-11-19\ntopics:\n  - laravel\n  - vitepress\n  - api\nmeetTheInstructor: I create this series because I love \u003Cstrong>VitePress\u003C\u002Fstrong> and \u003Cstrong>Laravel\u003C\u002Fstrong>. I truly believe that combining the two results in a simple yet \u003Cstrong>powerful solution\u003C\u002Fstrong> for creating a blog. I want to empower developers to enhance their VitePress blogs with a Laravel API to create advanced features.\nseriesSlug: empower-and-dynamize-our-vitepress-blog-with-a-laravel-api\n---\n\nHello! 👋\n\nAfter building our VitePress blog, we are ready to make it more dynamic with a Laravel API.\n\nIn the previous series, we explored VitePress from the initial project setup to deployment on Cloudflare Pages. We built a functional, automated blog with SEO metadata, Open Graph images, and a GitHub projects page. The blog handled everything at build time, so publishing content was the only task left.\n\n\u003CCalloutReadMore id=\"43c95b33-041c-4108-ab98-0d21ef60ed7f\" \u002F>\n\nThis series introduces back-end development by creating a [Laravel](https:\u002F\u002Flaravel.com) API that gives our blog a few interactive features.\n\nUntil now, our blog has been mostly static. Content was generated at build time, with a small amount of data loaded dynamically, and the resulting HTML files were distributed through a CDN. By adding a Laravel API, we will let readers interact with the blog through features such as post reactions and comments.\n\nAlthough the focus is on the back end, we will also integrate the API into our VitePress blog. We will use Vue.js and [Pinia Colada](https:\u002F\u002Fpinia-colada.esm.dev\u002F) as our data-fetching framework. VitePress is a Vue.js application, so we can extend it with the components we need.\n\nThe examples are designed to be easy to follow. Unnecessary complexity and over-engineering are neither desirable nor necessary here. We will focus on simplicity, clarity, and efficiency.\n\nThroughout the series, we will build a Laravel API and integrate it with our VitePress blog. We will cover:\n\n- **Setting up the Laravel project**: Create a new Laravel project and become familiar with its structure.\n- **Improving the development workflow**: Configure [Pint](https:\u002F\u002Flaravel.com\u002Fdocs\u002F11.x\u002Fpint), [Rector](https:\u002F\u002Fgithub.com\u002Frectorphp\u002Frector), [Larastan](https:\u002F\u002Fgithub.com\u002Flarastan\u002Flarastan), and [Pest](https:\u002F\u002Fpestphp.com\u002F) for formatting, refactoring, static analysis, and testing.\n- **Adding social authentication**: Let users sign in with GitHub through [Laravel Socialite](https:\u002F\u002Flaravel.com\u002Fdocs\u002F11.x\u002Fsocialite).\n- **Connecting the applications**: Configure Sanctum, CORS, CSRF protection, and the first requests between the VitePress frontend and the Laravel API.\n- **Managing authentication state**: Use [Pinia Colada](https:\u002F\u002Fpinia-colada.esm.dev\u002F) to retrieve the current user and log out with an optimistic update.\n- **Building the comment API**: Create the models, relationships, endpoints, validation, authorization, and tests for comments.\n- **Keeping the backend in sync**: Generate post metadata from VitePress and synchronize it with the Laravel database.\n- **Building the comment interface**: Fetch, create, edit, and delete comments from the VitePress frontend.\n\nBy the end of the series, you will have a blog backed by a Laravel API. Readers will be able to sign in with GitHub and leave comments, and the architecture will be ready for additional interactive features.\n\nTesting is part of the development process and will be included at each stage, so it does not need a dedicated article.\n\nIf you have questions, feedback, or suggestions, feel free to share them in the comments. Your input helps improve the series.\n\n::callout{icon=\"i-ph-info-duotone\" color=\"info\"}\nThis series assumes prior knowledge of TypeScript, Vue.js, and Laravel. If you are unfamiliar with any of these technologies, review the [Create a Blog with VitePress and Vue.js from Scratch](\u002Fseries\u002Fcreate-a-blog-with-vitepress-and-vue-js-from-scratch) first.\n::\n\n## Chapters\n\n::series-chapters-list\n---\nclass: mx-auto max-w-5xl\n---\n::\n",{"title":8022,"description":8183},{"loc":8186},"series\u002Fempower-and-dynamize-our-vitepress-blog-with-a-laravel-api","Transform your VitePress blog into a dynamic platform with an API",[8193,8194,8195],"laravel","vitepress","api","JLBtX9BKfN72BkhcYisEXraNGTvZSnT5YHM05A_uemk",[8198,8203,8208,8213,8218,8223,8228,8233],{"contentId":8199,"title":8200,"description":8201,"path":8202,"part":60,"github":8010,"topics":8010},"06469e25-715e-4a92-87b9-0db6db845a50","Setting Up Your Laravel Project Structure and Essentials","A comprehensive guide to setting up your Laravel project and understanding its structure for a better development experience.","\u002Fseries\u002Fempower-and-dynamize-our-vitepress-blog-with-a-laravel-api\u002Fsetting-up-your-laravel-project-structure-and-essentials",{"contentId":8204,"title":8205,"description":8206,"path":8207,"part":119,"github":8010,"topics":8010},"d566d5f4-3c4a-44e5-89cb-b3c547673ffa","Pint, Rector, Larastan, and Pest: Essentials for Success","Explore the four indispensable tools for maintaining code quality and consistency in Laravel projects: Pint, Rector, Larastan, and Pest.","\u002Fseries\u002Fempower-and-dynamize-our-vitepress-blog-with-a-laravel-api\u002Fpint-larastan-rector-and-pest-essential-for-success",{"contentId":8209,"title":8210,"description":8211,"path":8212,"part":141,"github":8010,"topics":8010},"3729f419-a8b6-486c-a845-ab5ba1a33172","Effortless Social Authentication with Laravel Socialite","Add GitHub authentication to Laravel with Socialite, OAuth callbacks, database synchronization, secure sessions, and test-first development.","\u002Fseries\u002Fempower-and-dynamize-our-vitepress-blog-with-a-laravel-api\u002Feffortless-social-authentication-with-laravel-socialite",{"contentId":8214,"title":8215,"description":8216,"path":8217,"part":147,"github":8010,"topics":8010},"b07ec3b5-ca56-4d14-ae2f-8c0702218293","Building a Simple Comment System for User Engagement","Build a Laravel comment API with models, migrations, resources, policies, form requests, controllers, routes, and comprehensive tests.","\u002Fseries\u002Fempower-and-dynamize-our-vitepress-blog-with-a-laravel-api\u002Fbuilding-a-simple-comment-system-for-user-engagement",{"contentId":8219,"title":8220,"description":8221,"path":8222,"part":153,"github":8010,"topics":8010},"53a607df-d10e-4423-966c-500d2885e6e0","Automating Your Backend to Stay in Sync Effortlessly","Generate frontend metadata with VitePress, synchronize posts with Laravel, and keep the backend database aligned automatically.","\u002Fseries\u002Fempower-and-dynamize-our-vitepress-blog-with-a-laravel-api\u002Fautomating-your-backend-to-stay-in-sync-effortlessly",{"contentId":8224,"title":8225,"description":8226,"path":8227,"part":184,"github":8010,"topics":8010},"e6040e0a-4997-40d6-bde8-332cbca0f307","Bridging the Gap: Connecting Your Frontend and Backend","Connect a VitePress frontend to a Laravel API with Sanctum, CORS, CSRF protection, shared credentials, and a reusable API client.","\u002Fseries\u002Fempower-and-dynamize-our-vitepress-blog-with-a-laravel-api\u002Fbridging-the-gap-connecting-your-frontend-and-backend",{"contentId":8229,"title":8230,"description":8231,"path":8232,"part":202,"github":8010,"topics":8010},"d507f8af-7c76-4660-859e-23af11c0728e","Streamlining User Authentication from Frontend to Backend","Connect frontend authentication to Laravel with a current-user query, GitHub logout flow, Pinia Colada caching, and optimistic state updates.","\u002Fseries\u002Fempower-and-dynamize-our-vitepress-blog-with-a-laravel-api\u002Fstreamlining-user-authentication-from-frontend-to-backend",{"contentId":8006,"title":5,"description":8008,"path":8012,"part":214,"github":8010,"topics":8010},1795016694120]