import React, { useState } from 'react' import { atproto, collections } from '../api/atproto.js' import { env } from '../config/env.js' export default function CommentForm({ user, agent, onCommentPosted }) { const [text, setText] = useState('') const [loading, setLoading] = useState(false) const [error, setError] = useState(null) const handleSubmit = async (e) => { e.preventDefault() if (!text.trim()) return setLoading(true) setError(null) try { const currentUrl = window.location.href const timestamp = new Date().toISOString() // Create ai.syui.log record structure (new unified format) const record = { repo: user.did, collection: env.collection, rkey: `comment-${Date.now()}`, record: { $type: env.collection, url: currentUrl, // Keep for backward compatibility post: { url: currentUrl, date: timestamp, slug: currentUrl.match(/\/posts\/([^/]+)/)?.[1] || new URL(currentUrl).pathname.split('/').pop()?.replace(/\.html$/, '') || '', tags: [], title: document.title || 'Comment', language: 'ja' }, text: text.trim(), type: 'comment', author: { did: user.did, handle: user.handle, displayName: user.displayName, avatar: user.avatar }, createdAt: timestamp } } // Post the record using the same API as ask-AI await agent.api.com.atproto.repo.putRecord({ repo: record.repo, collection: record.collection, rkey: record.rkey, record: record.record }) // キャッシュを無効化 collections.invalidateCache(env.collection) // Clear form setText('') // Notify parent component if (onCommentPosted) { onCommentPosted() } // Show success message briefly setText('✓ ') setTimeout(() => { setText('') }, 2000) } catch (err) { setError(err.message) } finally { setLoading(false) } } if (!user) { return (

atproto login

) } return (

post

url: {window.location.href}