Added active render of amount of comments on post
This commit is contained in:
		
							parent
							
								
									85c2161a4d
								
							
						
					
					
						commit
						e04d588b56
					
				
					 2 changed files with 19 additions and 4 deletions
				
			
		|  | @ -1,13 +1,28 @@ | ||||||
| import { JSXElement } from "solid-js"; | import { JSXElement, createSignal, onMount } from "solid-js"; | ||||||
| 
 | 
 | ||||||
| import { CommentsIcon } from "../../Util/Icons"; | import { CommentsIcon } from "../../Util/Icons"; | ||||||
|  | import { getCommentCount } from "../../Util/api"; | ||||||
|  | 
 | ||||||
|  | export default function CommentsButton(props: { postId: string }): JSXElement { | ||||||
|  |   const [commentCount, setCommentCount] = createSignal(0); | ||||||
|  | 
 | ||||||
|  |   const handleComments = async (): Promise<void> => { | ||||||
|  |     try { | ||||||
|  |       const count = await getCommentCount(props.postId); | ||||||
|  |       setCommentCount(count); | ||||||
|  |     } catch (error) { | ||||||
|  |       console.error("Error reading comments:", error); | ||||||
|  |     } | ||||||
|  |   }; | ||||||
|  | 
 | ||||||
|  |   // Fetch comment count when the component mounts
 | ||||||
|  |   onMount(handleComments); | ||||||
| 
 | 
 | ||||||
| export default function CommentsButton(): JSXElement { |  | ||||||
|   return ( |   return ( | ||||||
|     <div class="flex p-1"> |     <div class="flex p-1"> | ||||||
|       <CommentsIcon /> |       <CommentsIcon /> | ||||||
|       <span class="text-1xl countdown px-1.5 pt-1.5 text-center"> |       <span class="text-1xl countdown px-1.5 pt-1.5 text-center"> | ||||||
|         <p style={{ "--value": 12 }} /> |         <p style={{ "--value": commentCount() }} /> | ||||||
|       </span> |       </span> | ||||||
|     </div> |     </div> | ||||||
|   ); |   ); | ||||||
|  |  | ||||||
|  | @ -36,7 +36,7 @@ export function PostSegment(props: { post: Post }): JSXElement { | ||||||
|         <div class="card-actions justify-between"> |         <div class="card-actions justify-between"> | ||||||
|           <div class="flex"> |           <div class="flex"> | ||||||
|             <EngagementButton postId={post.id} /> |             <EngagementButton postId={post.id} /> | ||||||
|             <CommentsButton /> |             <CommentsButton postId={post.id} /> | ||||||
|           </div> |           </div> | ||||||
|           <ToPostButton post={post} /> |           <ToPostButton post={post} /> | ||||||
|         </div> |         </div> | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Hollgy
						Hollgy