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); // Only show results that belong to the current lookup; switching the // username changes the query key, which clears stale data automatically. const showResults = postsQuery.data !== undefined && !postsQuery.isFetching; return (

Processed user lookup

{ event.preventDefault(); setUsername(input.trim().replace(/^u\//i, '')); }} >
setInput(event.target.value)} value={input} />
{postsQuery.isFetching && username ?

Looking up processed posts...

: null} {postsQuery.isError ?

{postsQuery.error.message}

: null} {showResults && postsQuery.data ? ( postsQuery.data.length === 0 ?

No processed posts found for .

: (
    {postsQuery.data.map((post) =>
  1. {post.title}r/{post.subreddit} ยท {post.messageSent ? 'Message sent' : post.error ?? 'Processed'}
  2. )}
) ) : null}
); }