Home / File/ PostComment.tsx — astro Source File

PostComment.tsx — astro Source File

Architecture documentation for PostComment.tsx, a tsx file in the astro codebase. 4 imports, 0 dependents.

File tsx E2ETesting TestFixtures 4 imports 1 functions

Entity Profile

Dependency Diagram

graph LR
  f944bfaf_ee24_132b_6a8e_a0701c4da227["PostComment.tsx"]
  8828cc9b_aa85_f4ba_73cb_ae49780007d3["flags.ts"]
  f944bfaf_ee24_132b_6a8e_a0701c4da227 --> 8828cc9b_aa85_f4ba_73cb_ae49780007d3
  5f1e8790_3b5c_c960_cbf7_2a395bc6a2c2["createLoggerFromFlags"]
  f944bfaf_ee24_132b_6a8e_a0701c4da227 --> 5f1e8790_3b5c_c960_cbf7_2a395bc6a2c2
  58a2600d_f5df_9651_e0d8_9010ddeef24d["astro:actions"]
  f944bfaf_ee24_132b_6a8e_a0701c4da227 --> 58a2600d_f5df_9651_e0d8_9010ddeef24d
  d9988dd0_c044_f9d2_85cd_a31a0a2bdf80["react"]
  f944bfaf_ee24_132b_6a8e_a0701c4da227 --> d9988dd0_c044_f9d2_85cd_a31a0a2bdf80
  style f944bfaf_ee24_132b_6a8e_a0701c4da227 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import { actions, isInputError } from 'astro:actions';
import { useState } from 'react';
import {createLoggerFromFlags} from "../../../../../src/cli/flags.ts";

export function PostComment({
	postId,
	serverBodyError,
}: {
	postId: string;
	serverBodyError?: string;
}) {
	const [comments, setComments] = useState<{ author: string; body: string }[]>([]);
	const [bodyError, setBodyError] = useState<string | undefined>(serverBodyError);
	const [unexpectedError, setUnexpectedError] = useState<string | undefined>(undefined);

	return (
		<>
			<form
				method="POST"
				data-testid="client"
				action={actions.blog.comment.toString()}
				onSubmit={async (e) => {
					e.preventDefault();
					const form = e.target as HTMLFormElement;
					const formData = new FormData(form);
					const { data, error } = await actions.blog.comment(formData);
					if (isInputError(error)) {
						return setBodyError(error.fields.body?.join(' '));
					} else if (error) {
						return setUnexpectedError(`${error.code}: ${error.message}`);
					}
					setBodyError(undefined);
					setComments((c) => [data, ...c]);
					form.reset();
				}}
			>
				{unexpectedError && (
					<p data-error="unexpected" style={{ color: 'red' }}>
						{unexpectedError}
					</p>
				)}
				<input type="hidden" name="postId" value={postId} />
				<label htmlFor="author">Author</label>
				<input id="author" type="text" name="author" placeholder="Your name" />
				<textarea rows={10} name="body"></textarea>
				{bodyError && (
					<p data-error="body" style={{ color: 'red' }}>
						{bodyError}
					</p>
				)}
				<button type="submit">Post</button>
			</form>
			<div data-testid="client-comments">
				{comments.map((c) => (
					<article
						key={c.body}
						style={{
							border: '2px solid color-mix(in srgb, var(--accent), transparent 80%)',
							padding: '0.3rem 1rem',
							borderRadius: '0.3rem',
							marginBlock: '0.3rem',
						}}
					>
						<p>{c.body}</p>
						<p>{c.author}</p>
					</article>
				))}
			</div>
		</>
	);
}

Domain

Subdomains

Functions

Dependencies

Frequently Asked Questions

What does PostComment.tsx do?
PostComment.tsx is a source file in the astro codebase, written in tsx. It belongs to the E2ETesting domain, TestFixtures subdomain.
What functions are defined in PostComment.tsx?
PostComment.tsx defines 1 function(s): PostComment.
What does PostComment.tsx depend on?
PostComment.tsx imports 4 module(s): astro:actions, createLoggerFromFlags, flags.ts, react.
Where is PostComment.tsx in the architecture?
PostComment.tsx is located at packages/astro/e2e/fixtures/actions-blog/src/components/PostComment.tsx (domain: E2ETesting, subdomain: TestFixtures, directory: packages/astro/e2e/fixtures/actions-blog/src/components).

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free