Fixed bug where invalid date renders in comments as loop, did not piss off lintbro
This commit is contained in:
		
							parent
							
								
									2e600cc6d2
								
							
						
					
					
						commit
						9954588913
					
				
					 1 changed files with 12 additions and 4 deletions
				
			
		| 
						 | 
					@ -7,15 +7,23 @@ export function Comment(props: { comment: PublicComment }): JSXElement {
 | 
				
			||||||
  const [content, setContent] = createSignal<string>("");
 | 
					  const [content, setContent] = createSignal<string>("");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  createEffect(() => {
 | 
					  createEffect(() => {
 | 
				
			||||||
    setCreationDate(new Date(props.comment.created_at).toDateString());
 | 
					    const date = new Date(props.comment.created_at);
 | 
				
			||||||
 | 
					    if (!isNaN(date.getTime())) {
 | 
				
			||||||
 | 
					      setCreationDate(date.toDateString());
 | 
				
			||||||
 | 
					    } else {
 | 
				
			||||||
 | 
					      // Set creation date to an empty string or any default value when the date is invalid
 | 
				
			||||||
 | 
					      setCreationDate("");
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
    setContent(props.comment.content);
 | 
					    setContent(props.comment.content);
 | 
				
			||||||
  });
 | 
					  });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  return (
 | 
					  return (
 | 
				
			||||||
    <>
 | 
					    <>
 | 
				
			||||||
      <div class="py-5">
 | 
					      {creationDate() && ( // Render creation date only if it's not an empty string
 | 
				
			||||||
        <time class="text-xs opacity-50">{creationDate()}</time>
 | 
					        <div class="py-5">
 | 
				
			||||||
      </div>
 | 
					          <time class="text-xs opacity-50">{creationDate()}</time>
 | 
				
			||||||
 | 
					        </div>
 | 
				
			||||||
 | 
					      )}
 | 
				
			||||||
      <div class="">{content()}</div>
 | 
					      <div class="">{content()}</div>
 | 
				
			||||||
      <div class="divider" />
 | 
					      <div class="divider" />
 | 
				
			||||||
    </>
 | 
					    </>
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue