Every analytics tool wants a subscription. And your data. I built Twiligent instead. YouTube stats. Instagram stats. One dashboard. Runs locally on your machine.
feat(frontend)!: remove the Reddit account form
spacesdriveff2ce1c71dcc
diff --git a/frontend/src/features/accounts/AddAccountDialog.tsx b/frontend/src/features/accounts/AddAccountDialog.tsxindex b8d52a7..a15a19e 100644--- a/frontend/src/features/accounts/AddAccountDialog.tsx+++ b/frontend/src/features/accounts/AddAccountDialog.tsx@@ -7,7 +7,6 @@ import InstagramTesterNotice from '@/components/InstagramTesterNotice';import { PLATFORM_META } from '@/lib/accounts';import { PLATFORM_CHOICES, platformChoiceTitle } from './platformChoices';import YouTubeAccountFields from './YouTubeAccountFields';-import RedditAccountFields from './RedditAccountFields';import AddAccountFooter from './AddAccountFooter';import type { AddAccountFlow } from './useAddAccount';import type { Platform } from '@shared/types/domain.ts';@@ -29,7 +28,7 @@ const STEP_DESCRIPTION: Record<Platform, string> = {// each card moves on to its platform's step, so these are plain buttons, not radiosfunction PlatformPicker({ onSelect }: PlatformPickerProps) {return (- <div className="grid grid-cols-1 gap-3 sm:grid-cols-3" data-platform-picker>+ <div className="grid grid-cols-1 gap-3 sm:grid-cols-2" data-platform-picker>{PLATFORM_CHOICES.map(choice => (<ChoiceCardkey={choice.value}@@ -44,7 +43,7 @@ function PlatformPicker({ onSelect }: PlatformPickerProps) {}export default function AddAccountDialog({ flow }: AddAccountDialogProps) {- const { platform, channel, reddit } = flow;+ const { platform, channel } = flow;const contentRef = useRef<HTMLDivElement>(null);const firstStep = useRef(true);@@ -95,19 +94,6 @@ export default function AddAccountDialog({ flow }: AddAccountDialogProps) {</div>)}- {platform === 'reddit' && (- <RedditAccountFields- username={reddit.username}- cookie={reddit.cookie}- onUsernameChange={reddit.setUsername}- onUsernameBlur={reddit.tidyUsername}- onCookieChange={reddit.setCookie}- onSubmit={flow.redditAdd.handleAddReddit}- usernameError={flow.errorFor('username')}- cookieError={flow.errorFor('cookie')}- />- )}-{flow.submitError && (<Alert variant="destructive" role="alert"><AlertCircle />diff --git a/frontend/src/features/accounts/AddAccountFooter.tsx b/frontend/src/features/accounts/AddAccountFooter.tsxindex 4678db0..6a240eb 100644--- a/frontend/src/features/accounts/AddAccountFooter.tsx+++ b/frontend/src/features/accounts/AddAccountFooter.tsx@@ -11,10 +11,9 @@ export interface AddAccountFooterProps {// the main button stays enabled: pressing it with a field missing says which one, instead of greying out silentlyexport default function AddAccountFooter({ flow }: AddAccountFooterProps) {- const { platform, channelAdd, redditAdd, instagram } = flow;+ const { platform, channelAdd, instagram } = flow;const { adding } = channelAdd;const { connecting } = instagram;- const { addingReddit } = redditAdd;return (<DialogFooter>@@ -37,12 +36,6 @@ export default function AddAccountFooter({ flow }: AddAccountFooterProps) {{connecting ? 'Opening Instagram' : 'Continue to Instagram'}</Button>)}- {platform === 'reddit' && (- <Button type="submit" form="add-account-form" disabled={addingReddit}>- {addingReddit && <Spinner className="size-4" />}- {addingReddit ? 'Adding account' : 'Add Reddit account'}- </Button>- )}</DialogFooter>);}diff --git a/frontend/src/features/accounts/RedditAccountFields.tsx b/frontend/src/features/accounts/RedditAccountFields.tsxdeleted file mode 100644index bfe38e0..0000000--- a/frontend/src/features/accounts/RedditAccountFields.tsx+++ /dev/null@@ -1,64 +0,0 @@-import React from 'react';-import { Info } from 'lucide-react';-import { Input } from '@/components/ui/input';-import { Alert, AlertDescription } from '@/components/ui/alert';-import { FieldRow } from '@/components/DetailPanel';--export interface RedditAccountFieldsProps {- username: string;- cookie: string;- onUsernameChange: (value: string) => void;- onUsernameBlur: () => void;- onCookieChange: (value: string) => void;- onSubmit: () => void;- usernameError?: string;- cookieError?: string;-}--// a real form, so Enter submits once and the busy guard in the add step stops a second request-export default function RedditAccountFields({- username, cookie, onUsernameChange, onUsernameBlur, onCookieChange, onSubmit, usernameError, cookieError,-}: RedditAccountFieldsProps) {- return (- <form- id="add-account-form"- noValidate- onSubmit={e => { e.preventDefault(); onSubmit(); }}- className="flex flex-col gap-4"- >- <FieldRow label="Username" htmlFor="reddit-user" hint="The name, u/name or the address of the profile." error={usernameError}>- <Input- id="reddit-user"- className="h-(--control-h-lg)"- value={username}- onChange={e => onUsernameChange(e.target.value)}- onBlur={onUsernameBlur}- placeholder="u/username"- autoComplete="off"- spellCheck={false}- autoFocus- />- </FieldRow>- <FieldRow label="Session cookie" hint="Stored on the server and never shown again." htmlFor="reddit-cookie" error={cookieError}>- <Input- id="reddit-cookie"- type="password"- className="h-(--control-h-lg) font-mono"- value={cookie}- onChange={e => onCookieChange(e.target.value)}- placeholder="reddit_session value"- autoComplete="off"- />- </FieldRow>- <Alert>- <Info />- <AlertDescription>- {'Sign in to reddit.com in your browser, open DevTools (F12), go to Application, then Cookies, then https://www.reddit.com, and copy the value of '}- <strong className="font-semibold text-ink">reddit_session</strong>.- </AlertDescription>- </Alert>- {/* lets Enter in either field submit the form */}- <button type="submit" hidden aria-hidden="true" tabIndex={-1} />- </form>- );-}diff --git a/frontend/src/features/accounts/accountManagerData.ts b/frontend/src/features/accounts/accountManagerData.tsindex 0751690..f480961 100644--- a/frontend/src/features/accounts/accountManagerData.ts+++ b/frontend/src/features/accounts/accountManagerData.ts@@ -85,27 +85,13 @@ export function visibleSections(groups: Record<Platform, unknown[]>): AccountSecreturn ACCOUNT_SECTIONS.filter(section => groups[section.key].length > 0);}-// people paste "u/name", "@name" or their profile address; the Worker keeps the same name-export function redditUsername(input: string): string {- const text = input.trim();- const fromUrl = text.match(/reddit\.com\/(?:user|u)\/([^/?#\s]+)/i);- return (fromUrl ? fromUrl[1] : text).replace(/^\/?u\//i, '').replace(/^@/, '').trim();-}--export type AddAccountField = 'channel' | 'username' | 'cookie';+export type AddAccountField = 'channel';export interface AddAccountProblem {field: AddAccountField;message: string;}-// what is missing before an account can be added, or null-export function redditFieldsProblem(username: string, cookie: string): AddAccountProblem | null {- if (!redditUsername(username)) return { field: 'username', message: 'Enter the Reddit username, such as u/name.' };- if (!cookie.trim()) return { field: 'cookie', message: 'Paste the reddit_session cookie value. The steps below show where to find it.' };- return null;-}-export function channelFieldProblem(input: string): AddAccountProblem | null {return input.trim() ? null : { field: 'channel', message: 'Paste a channel link, an @handle or a channel ID that starts with UC.' };}diff --git a/frontend/src/features/accounts/platformChoices.ts b/frontend/src/features/accounts/platformChoices.tsindex 2391b66..8992087 100644--- a/frontend/src/features/accounts/platformChoices.ts+++ b/frontend/src/features/accounts/platformChoices.ts@@ -1,5 +1,5 @@import type { ComponentType } from 'react';-import { YouTubeIcon, InstagramIcon, RedditIcon } from '@/components/brand/platform-icons';+import { YouTubeIcon, InstagramIcon } from '@/components/brand/platform-icons';import type { PlatformIconProps } from '@/components/brand/platform-icons';import type { Platform } from '@shared/types/domain.ts';@@ -13,7 +13,6 @@ export interface PlatformChoice {export const PLATFORM_CHOICES: PlatformChoice[] = [{ value: 'youtube', title: 'YouTube channel', description: 'Paste a channel link, @handle or channel ID.', Icon: YouTubeIcon },{ value: 'instagram', title: 'Instagram account', description: 'Sign in with Instagram. Business or Creator accounts only.', Icon: InstagramIcon },- { value: 'reddit', title: 'Reddit account', description: 'Add a username and a session cookie from your browser.', Icon: RedditIcon },];export function platformChoiceTitle(value: Platform): string {diff --git a/frontend/src/features/accounts/useAddAccount.ts b/frontend/src/features/accounts/useAddAccount.tsindex 6d91c00..1cb65b9 100644--- a/frontend/src/features/accounts/useAddAccount.ts+++ b/frontend/src/features/accounts/useAddAccount.ts@@ -1,6 +1,6 @@import { useState } from 'react';import { api } from '../../services/api';-import { channelFieldProblem, redditFieldsProblem, redditUsername } from './accountManagerData';+import { channelFieldProblem } from './accountManagerData';import type { AddAccountField, AddAccountProblem } from './accountManagerData';import type { AppContextValue } from '../../context/AppContext';import type { Platform } from '@shared/types/domain.ts';@@ -9,7 +9,7 @@ import type { AccountActionDeps } from './useAccountDelete';type ShowToast = AppContextValue['showToast'];-const FIELD_IDS: Record<AddAccountField, string> = { channel: 'yt-channel', username: 'reddit-user', cookie: 'reddit-cookie' };+const FIELD_IDS: Record<AddAccountField, string> = { channel: 'yt-channel' };interface AddStepDeps {showToast: ShowToast;@@ -66,29 +66,6 @@ function useChannelLookup(setProblem: AddStepDeps['setProblem']) {return { input, resolving, resolved, changeInput, handleResolve, clearResolved, reset };}-function useRedditFields(setProblem: AddStepDeps['setProblem']) {- const [username, setUsernameValue] = useState('');- const [cookie, setCookieValue] = useState('');-- const setUsername = (value: string) => {- setUsernameValue(value);- setProblem(null);- };- const setCookie = (value: string) => {- setCookieValue(value);- setProblem(null);- };- // a pasted profile address or u/name is shown as the plain name once the field is left- const tidyUsername = () => setUsernameValue(current => redditUsername(current));-- const reset = () => {- setUsernameValue('');- setCookieValue('');- };-- return { username, cookie, setUsername, setCookie, tidyUsername, reset };-}-function useChannelAdd({ input, showToast, finishAdding, setProblem, setSubmitError }: AddStepDeps & { input: string }) {const [adding, setAdding] = useState(false);@@ -116,34 +93,6 @@ function useChannelAdd({ input, showToast, finishAdding, setProblem, setSubmitErreturn { adding, handleAdd };}-function useRedditAdd({ username, cookie, showToast, finishAdding, setProblem, setSubmitError }: AddStepDeps & { username: string; cookie: string }) {- const [addingReddit, setAddingReddit] = useState(false);-- const handleAddReddit = async () => {- if (addingReddit) return;- const problem = redditFieldsProblem(username, cookie);- if (problem) {- setProblem(problem);- focusProblem(problem);- return;- }- setAddingReddit(true);- setSubmitError(null);- const name = redditUsername(username);- try {- await api.addRedditAccount(name, cookie.trim());- showToast(`u/${name} added`);- finishAdding();- } catch (err) {- setSubmitError(`Couldn't add u/${name}. ${(err as Error).message}`);- } finally {- setAddingReddit(false);- }- };-- return { addingReddit, handleAddReddit };-}-function useInstagramConnect(setSubmitError: AddStepDeps['setSubmitError']) {const [connecting, setConnecting] = useState(false);@@ -170,7 +119,6 @@ export function useAddAccount({ showToast, loadAccounts }: AccountActionDeps) {const [problem, setProblem] = useState<AddAccountProblem | null>(null);const [submitError, setSubmitError] = useState<string | null>(null);const channel = useChannelLookup(setProblem);- const reddit = useRedditFields(setProblem);const setPlatform = (value: Platform | null) => {setPlatformValue(value);@@ -182,7 +130,6 @@ export function useAddAccount({ showToast, loadAccounts }: AccountActionDeps) {setDialogOpen(false);setPlatform(null);channel.reset();- reddit.reset();};const finishAdding = () => {@@ -190,7 +137,7 @@ export function useAddAccount({ showToast, loadAccounts }: AccountActionDeps) {loadAccounts();};- // back keeps typed channel and reddit fields; only platform and lookup reset+ // back keeps the typed channel; only platform and lookup resetconst goBack = () => {setPlatform(null);channel.clearResolved();@@ -203,13 +150,12 @@ export function useAddAccount({ showToast, loadAccounts }: AccountActionDeps) {const deps = { showToast, finishAdding, setProblem, setSubmitError };const channelAdd = useChannelAdd({ input: channel.input, ...deps });- const redditAdd = useRedditAdd({ username: reddit.username, cookie: reddit.cookie, ...deps });const instagram = useInstagramConnect(setSubmitError);const errorFor = (field: AddAccountField) => (problem?.field === field ? problem.message : undefined);return {dialogOpen, setDialogOpen, platform, setPlatform, closeDialog, goBack, openWithPlatform,- channel, reddit, channelAdd, redditAdd, instagram, errorFor, submitError,+ channel, channelAdd, instagram, errorFor, submitError,};}diff --git a/frontend/src/services/api.ts b/frontend/src/services/api.tsindex d0012ba..94be437 100644--- a/frontend/src/services/api.ts+++ b/frontend/src/services/api.ts@@ -162,7 +162,6 @@ export const api = {getIGContainerStatus: (containerId: string, accountId: string) => request<InstagramContainerStatusResponse>(`/ig-container/${containerId}/status?accountId=${accountId}`),publishIGContainer: (id: string, containerId: string) => request<InstagramMediaPublishResponse>(`/accounts/${id}/ig-media-publish`, { method: 'POST', body: JSON.stringify({ containerId }) }),- addRedditAccount: (username: string, cookie: string) => request<AccountResponse>('/accounts/reddit', { method: 'POST', body: JSON.stringify({ username, cookie }) }),// Overview dashboard (tracked content + per-account analytics cache)getOverview: () => request<OverviewResponse>('/overview'),diff --git a/frontend/tests/features/accounts/accountManagerData.test.ts b/frontend/tests/features/accounts/accountManagerData.test.tsindex 2be4df0..2ef84d7 100644--- a/frontend/tests/features/accounts/accountManagerData.test.ts+++ b/frontend/tests/features/accounts/accountManagerData.test.ts@@ -1,7 +1,7 @@import { test } from 'node:test';import assert from 'node:assert/strict';import {- TESTER_HINT, instagramErrorMessage, readOAuthReturn, accountMetrics, accountCardHandle, visibleSections, redditUsername, redditFieldsProblem, channelFieldProblem } from '../../../src/features/accounts/accountManagerData.ts';+ TESTER_HINT, instagramErrorMessage, readOAuthReturn, accountMetrics, accountCardHandle, visibleSections, channelFieldProblem } from '../../../src/features/accounts/accountManagerData.ts';const params = (query: string) => new URLSearchParams(query);@@ -55,16 +55,7 @@ test('only platforms with accounts get a section, in a fixed order', () => {assert.deepEqual(visibleSections(groups).map(section => section.key), ['instagram', 'reddit']);});-test('a Reddit username is taken from u/name, @name or a pasted profile address', () => {- assert.equal(redditUsername(' u/spez '), 'spez');- assert.equal(redditUsername('@spez'), 'spez');- assert.equal(redditUsername('https://www.reddit.com/user/spez/'), 'spez');-});--test('adding an account names the missing field first', () => {- assert.equal(redditFieldsProblem('u/', 'abc')?.field, 'username');- assert.equal(redditFieldsProblem('spez', ' ')?.field, 'cookie');- assert.equal(redditFieldsProblem('spez', 'abc'), null);+test('adding a channel with nothing typed points at the channel field', () => {assert.equal(channelFieldProblem(' ')?.field, 'channel');assert.equal(channelFieldProblem('@channel'), null);});