The settings page had accumulated five tabs whose names no longer matched their contents, three different save models, and the whole subreddit configuration buried under a tab named after a checkbox. Structure: - Subreddits becomes its own page: a list showing each community's mode, tone, computed share of polling, and live sent/reply stats, with one subreddit edited at a time in a drawer. - Accounts becomes its own page. It is session lifecycle, not config. - Settings collapses to one scrolling page: Safety, Pacing (Monitoring and Rate limits merged), Targeting, Notifications, Advanced. - The sidebar is grouped, having gone from 9 to 11 destinations. Saving: - Every section owns its own draft, validation, risk gate and save via useConfigCard, submitting only the keys it owns. A syntax error in the advanced JSON can no longer block a rate-limit change, and enabling an autonomous policy is its own deliberate commit. - UnsavedChangesProvider restores the leave-page guard across cards that no longer share a draft. Subreddit editing: - Errors are keyed by field name instead of array index, removing the defensive invalidation that existed because row indices shifted on add and remove. Confirming an autonomous mode can no longer be attributed to the wrong row. - Weight is shown as the share it actually produces, live while editing. - Bulk actions cover start/pause polling, tone, policy and removal, because production runs 30-40 subreddits and per-row editing does not scale. Bulk policy changes name every subreddit turning autonomous, and normalise the hybrid mode's turn budget, which has no form to catch it. Physique targeting moves into its own Targeting card. It sends only reddit.physiqueTargeting, which the config route applies independently, so it cannot clobber the pacing card's fields. Turning screening on now warns that it will reduce how many posts qualify. Also surfaces the effective sending rate, since the hourly limit and the minimum delay both throttle and only the binding one matters. Legacy ?section= links redirect or resolve to anchors. Fixes found while verifying in a browser: a radio-card rule was shrinking nested number inputs; .share-preview had no styles; the throughput readout reported a rate from a blank field; and the reconcile logic warned about a server change whenever a sibling card saved. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
101 lines
4.0 KiB
TypeScript
101 lines
4.0 KiB
TypeScript
import { useEffect, useState } from 'react';
|
|
import { Link } from 'react-router-dom';
|
|
import { RedditUsernameLink } from '../../components/reddit-username-link.js';
|
|
import { useStartConversationMutation } from './conversation-queries.js';
|
|
import { useRedditAccountsQuery } from '../settings/settings-queries.js';
|
|
import { ownedConversationId } from './conversation-identity.js';
|
|
|
|
const SUCCESS_NOTICE_DISMISS_MS = 5_000;
|
|
|
|
interface StartConversationFormProps {
|
|
onStarted(conversationId: string): void;
|
|
}
|
|
|
|
export function StartConversationForm({ onStarted }: StartConversationFormProps) {
|
|
const [username, setUsername] = useState('');
|
|
const [message, setMessage] = useState('');
|
|
const accountsQuery = useRedditAccountsQuery();
|
|
const runningAccounts = (accountsQuery.data ?? []).filter((account) => account.isRunning);
|
|
const [selectedAccountId, setSelectedAccountId] = useState('');
|
|
const accountId = selectedAccountId || runningAccounts[0]?.accountId || '';
|
|
const [successUsername, setSuccessUsername] = useState<string | null>(null);
|
|
const mutation = useStartConversationMutation();
|
|
const canSubmit = accountId.length > 0 && username.trim().length > 0 && message.trim().length > 0 && !mutation.isPending;
|
|
|
|
useEffect(() => {
|
|
if (successUsername === null) return;
|
|
const timer = window.setTimeout(() => setSuccessUsername(null), SUCCESS_NOTICE_DISMISS_MS);
|
|
return () => window.clearTimeout(timer);
|
|
}, [successUsername]);
|
|
|
|
if (accountsQuery.isPending) {
|
|
return <p className="conversation-form-hint" role="status">Loading Reddit accounts…</p>;
|
|
}
|
|
if (accountsQuery.isError) {
|
|
return <div className="conversation-inline-error" role="alert">{accountsQuery.error.message}</div>;
|
|
}
|
|
if (runningAccounts.length === 0) {
|
|
return (
|
|
<p className="conversation-form-hint">
|
|
No running accounts — start one in <Link to="/accounts">Accounts</Link>.
|
|
</p>
|
|
);
|
|
}
|
|
|
|
function submit(event: React.FormEvent<HTMLFormElement>) {
|
|
event.preventDefault();
|
|
if (!canSubmit) return;
|
|
mutation.mutate(
|
|
{ accountId, username, message },
|
|
{
|
|
onSuccess(chat) {
|
|
setSuccessUsername(chat.username);
|
|
setUsername('');
|
|
setMessage('');
|
|
onStarted(ownedConversationId(chat));
|
|
},
|
|
},
|
|
);
|
|
}
|
|
|
|
return (
|
|
<form className="start-conversation-form" onSubmit={submit}>
|
|
<div className="conversation-field">
|
|
<label htmlFor="new-conversation-account">Send from account</label>
|
|
<select id="new-conversation-account" onChange={(event) => setSelectedAccountId(event.target.value)} value={accountId}>
|
|
{runningAccounts.map((account) => <option key={account.accountId} value={account.accountId}>u/{account.redditUsername}</option>)}
|
|
</select>
|
|
</div>
|
|
<div className="conversation-field">
|
|
<label htmlFor="new-conversation-username">Reddit username</label>
|
|
<input
|
|
autoComplete="off"
|
|
id="new-conversation-username"
|
|
onChange={(event) => setUsername(event.target.value)}
|
|
placeholder="username"
|
|
value={username}
|
|
/>
|
|
</div>
|
|
<div className="conversation-field">
|
|
<label htmlFor="new-conversation-message">Opening message</label>
|
|
<textarea
|
|
id="new-conversation-message"
|
|
onChange={(event) => setMessage(event.target.value)}
|
|
placeholder="Write a personal opening message"
|
|
rows={4}
|
|
value={message}
|
|
/>
|
|
</div>
|
|
{mutation.isError ? <div className="conversation-inline-error" role="alert">{mutation.error.message}</div> : null}
|
|
{successUsername ? (
|
|
<div aria-label="Conversation started" className="conversation-inline-success" role="status">
|
|
Conversation started with <RedditUsernameLink username={successUsername} />
|
|
</div>
|
|
) : null}
|
|
<button className="conversation-primary" disabled={!canSubmit} type="submit">
|
|
{mutation.isPending ? 'Starting…' : 'Start conversation'}
|
|
</button>
|
|
</form>
|
|
);
|
|
}
|