add callback test

This commit is contained in:
2025-06-19 13:57:08 +09:00
parent 1793de40c1
commit 293421b7a5
7 changed files with 162 additions and 53 deletions

View File

@ -465,7 +465,6 @@ body {
}
.user-message .message-content {
background: var(--primary);
color: white;
}

View File

@ -57,15 +57,15 @@ export default function AskAI({ adminData, user, agent, onClose }) {
<div className="user-message">
<div className="message-header">
<div className="avatar">
{entry.user?.avatar ? (
<img src={entry.user.avatar} alt={entry.user.displayName} className="profile-avatar" />
{(entry.user?.avatar || user?.avatar) ? (
<img src={entry.user?.avatar || user?.avatar} alt={entry.user?.displayName || user?.displayName} className="profile-avatar" />
) : (
'👤'
)}
</div>
<div className="user-info">
<div className="display-name">{entry.user?.displayName || 'You'}</div>
<div className="handle">@{entry.user?.handle || 'user'}</div>
<div className="display-name">{entry.user?.displayName || user?.displayName || 'You'}</div>
<div className="handle">@{entry.user?.handle || user?.handle || 'user'}</div>
<div className="timestamp">{formatTimestamp(entry.timestamp)}</div>
</div>
</div>

View File

@ -25,20 +25,20 @@ export default function AuthButton({ user, onLogin, onLogout, loading }) {
if (user) {
return (
<div style={{ display: 'flex', alignItems: 'center', gap: '8px' }}>
<div className="user-section" style={{ display: 'flex', alignItems: 'center', gap: '8px' }}>
{user.avatar && (
<img
src={user.avatar}
alt="Profile"
className="avatar"
className="user-avatar"
style={{ width: '24px', height: '24px' }}
/>
)}
<div>
<div className="display-name" style={{ fontSize: '14px', fontWeight: '700' }}>
<div className="user-display-name" style={{ fontSize: '14px', fontWeight: '700' }}>
{user.displayName}
</div>
<div className="handle" style={{ fontSize: '12px' }}>
<div className="user-handle" style={{ fontSize: '12px' }}>
@{user.handle}
</div>
</div>

View File

@ -4,19 +4,18 @@ import { env } from '../config/env.js'
export default function CommentForm({ user, agent, onCommentPosted }) {
const [text, setText] = useState('')
const [url, setUrl] = useState('')
const [loading, setLoading] = useState(false)
const [error, setError] = useState(null)
const handleSubmit = async (e) => {
e.preventDefault()
if (!text.trim() || !url.trim()) return
if (!text.trim()) return
setLoading(true)
setError(null)
try {
const currentUrl = url.trim()
const currentUrl = window.location.href
const timestamp = new Date().toISOString()
// Create ai.syui.log record structure (new unified format)
@ -30,7 +29,7 @@ export default function CommentForm({ user, agent, onCommentPosted }) {
post: {
url: currentUrl,
date: timestamp,
slug: new URL(currentUrl).pathname.split('/').pop()?.replace(/\.html$/, '') || '',
slug: currentUrl.match(/\/posts\/([^/]+)/)?.[1] || new URL(currentUrl).pathname.split('/').pop()?.replace(/\.html$/, '') || '',
tags: [],
title: document.title || 'Comment',
language: 'ja'
@ -55,7 +54,6 @@ export default function CommentForm({ user, agent, onCommentPosted }) {
// Clear form
setText('')
setUrl('')
// Notify parent component
if (onCommentPosted) {
@ -86,18 +84,8 @@ export default function CommentForm({ user, agent, onCommentPosted }) {
<h3>コメントを投稿</h3>
<form onSubmit={handleSubmit}>
<div className="form-group">
<label htmlFor="comment-url">ページURL:</label>
<input
id="comment-url"
type="url"
value={url}
onChange={(e) => setUrl(e.target.value)}
placeholder="https://syui.ai/posts/example"
required
disabled={loading}
className="form-input"
/>
<div className="form-group" style={{ marginBottom: '12px', padding: '8px', backgroundColor: 'var(--background-secondary)', borderRadius: '4px', fontSize: '0.9em' }}>
<strong>投稿先:</strong> {window.location.href}
</div>
<div className="form-group">
@ -123,7 +111,7 @@ export default function CommentForm({ user, agent, onCommentPosted }) {
<div className="form-actions">
<button
type="submit"
disabled={loading || !text.trim() || !url.trim()}
disabled={loading || !text.trim()}
className="btn btn-primary"
>
{loading ? '投稿中...' : 'コメントを投稿'}

View File

@ -20,11 +20,15 @@ export default function OAuthCallback({ onAuthSuccess }) {
}
if (code) {
setStatus('認証成功!メインページに戻ります...')
setStatus('認証成功!元のページに戻ります...')
// 少し待ってからメインページにリダイレクト
// Get the referring page or use root
const referrer = document.referrer || window.location.origin
const returnUrl = referrer.includes('/oauth/callback') ? window.location.origin : referrer
// 少し待ってから元のページにリダイレクト
setTimeout(() => {
window.location.href = '/'
window.location.href = returnUrl
}, 1500)
} else {
setStatus('認証情報が見つかりません')