Files
RedditBot/apps/dashboard/src/features/conversations/processed-user-lookup.tsx
T

31 lines
1.7 KiB
TypeScript

import { useState } from 'react';
import { AccountOwnerBadge } from '../../components/account-owner-badge.js';
import { RedditUsernameLink, redditUsernameLabel } from '../../components/reddit-username-link.js';
import { useProcessedPostsQuery } from './conversation-queries.js';
export function ProcessedUserLookup() {
const [input, setInput] = useState('');
const [username, setUsername] = useState('');
const postsQuery = useProcessedPostsQuery(username);
return (
<section aria-labelledby="processed-user-heading" className="new-conversation-panel">
<h2 id="processed-user-heading">Processed user lookup</h2>
<form onSubmit={(event) => { event.preventDefault(); setUsername(input.trim().replace(/^u\//i, '')); }}>
<label htmlFor="processed-user">Lookup Reddit username</label>
<input id="processed-user" onChange={(event) => setInput(event.target.value)} value={input} />
<button disabled={input.trim().length === 0} type="submit">Look up user</button>
</form>
{postsQuery.isPending && username ? <p role="status">Looking up processed posts...</p> : null}
{postsQuery.isError ? <p role="alert">{postsQuery.error.message}</p> : null}
{postsQuery.data ? (
postsQuery.data.length === 0 ? <p>No processed posts found for <RedditUsernameLink username={username} />.</p> : (
<ol aria-label={`Processed posts for ${redditUsernameLabel(username)}`}>
{postsQuery.data.map((post) => <li key={`${post.owner?.accountId ?? 'legacy'}:${post.id}`}><strong>{post.title}</strong><AccountOwnerBadge owner={post.owner} /><span>r/{post.subreddit} · {post.messageSent ? 'Message sent' : post.error ?? 'Processed'}</span></li>)}
</ol>
)
) : null}
</section>
);
}