Skip to content

Commit

Permalink
comments dev
Browse files Browse the repository at this point in the history
  • Loading branch information
StephenJLu committed Jan 4, 2025
1 parent d6fa8df commit abac901
Showing 1 changed file with 21 additions and 18 deletions.
39 changes: 21 additions & 18 deletions app/routes/r2-test/r2-worker-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,25 +88,17 @@ export const action = async ({ request, context }: { request: Request; context:
}
};

const formatDate = (timestamp: string) => {
const date = new Date(timestamp);
return date.toLocaleString();
};

export const R2WorkerTest = () => {
const loaderData = useLoaderData<typeof loader>();
const comments = loaderData?.comments || [];
const navigate = useNavigate();
const actionData = useActionData<ActionData>();
const [name, setName] = useState('');
const [comment, setComment] = useState('');

const formatDate = (dateString: string) => {
return new Date(dateString).toLocaleString();
};

useEffect(() => {
if (actionData?.success) {
// Refresh page to show new comments
navigate('.', { replace: true });
}
}, [actionData?.success, navigate]);

const loaderData = useLoaderData<typeof loader>();
const actionData = useActionData<ActionData>();
const comments = loaderData?.comments || [];

return (
<div data-theme="dark" style={{
Expand All @@ -121,7 +113,7 @@ export const R2WorkerTest = () => {
maxWidth: '600px',
marginTop: '2rem'
}}>
<Input
<Input
required
label="Name"
name="name"
Expand All @@ -145,7 +137,7 @@ export const R2WorkerTest = () => {
maxLength={255}
type="text"
autoComplete="off" className={undefined} style={undefined} onBlur={undefined} />
<br />
<br />
<Turnstile
theme="dark"
style={{ marginBottom: '1rem' }}
Expand All @@ -159,6 +151,17 @@ export const R2WorkerTest = () => {
</Button>
</Form>

{actionData?.success && (
<div style={{ marginTop: '1rem', color: 'green' }}>
✓ Comment submitted successfully
</div>
)}
{actionData?.errors && (
<div style={{ marginTop: '1rem', color: 'red' }}>
{Object.values(actionData.errors).filter(Boolean).join(', ')}
</div>
)}

<div style={{
width: '100%',
maxWidth: '600px',
Expand Down

0 comments on commit abac901

Please sign in to comment.