"use client"; import { useEffect, useRef, useState } from "react"; import { LoaderCircle, Plus } from "lucide-react"; import { Button } from "@/components/ui/button"; import { ActorTypeaheadInput } from "@/components/ActorTypeaheadInput"; import { Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, } from "@/components/ui/dialog"; import type { StandardReaderList } from "@/lib/standardReaderListsClient"; type Props = { open: boolean; onOpenChange: (open: boolean) => void; lists: StandardReaderList[]; creatorResults: StandardReaderList[]; searching: boolean; saving: boolean; onSearchCreator: (creator: string) => Promise; onAdd: (input: string) => Promise; onCreate?: () => void; }; const inputClass = "h-10 w-full min-w-0 rounded-md border border-input bg-background px-3 text-sm focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"; export function AddStandardReaderListDialog({ open, onOpenChange, lists, creatorResults, searching, saving, onSearchCreator, onAdd, onCreate, }: Props) { const [input, setInput] = useState(""); const [creator, setCreator] = useState(""); const [searched, setSearched] = useState(false); const [error, setError] = useState(null); const [pending, setPending] = useState<"search" | "add" | null>(null); const epoch = useRef(0); useEffect( () => () => { epoch.current++; }, [], ); const changeOpen = (next: boolean) => { if (!next) epoch.current++; onOpenChange(next); }; const add = async (value: string) => { if (saving || pending || !value.trim()) return; const captured = ++epoch.current; setError(null); setPending("add"); try { await onAdd(value.trim()); if (epoch.current === captured) changeOpen(false); } catch (failure) { if (epoch.current === captured) setError( failure instanceof Error ? failure.message : "Couldn't Add This List. Try Again.", ); } finally { if (epoch.current === captured) setPending(null); } }; const search = async () => { if (searching || pending || !creator.trim()) return; const captured = ++epoch.current; setError(null); setSearched(false); setPending("search"); try { await onSearchCreator(creator.trim()); if (epoch.current === captured) setSearched(true); } catch (failure) { if (epoch.current === captured) setError( failure instanceof Error ? failure.message : "Couldn't Find This Creator's Lists. Try Again.", ); } finally { if (epoch.current === captured) setPending(null); } }; const saved = new Set(lists.map((list) => list.uri)); return ( Add List Paste a Standard Reader list URL or AT URI, or find a creator's public lists.

Saved lists are public. Saving a list does not subscribe you to its members.

{ event.preventDefault(); void add(input); }} >
{ event.preventDefault(); void search(); }} >
{ setCreator(value); setSearched(false); }} className={inputClass} required disabled={saving || pending !== null} />
{searched && !searching && pending !== "search" ? ( creatorResults.length ? (
    {creatorResults.map((list) => (
  • {list.name}

    {list.description ? (

    {list.description}

    ) : null}
  • ))}
) : (

No Public Lists Found For This Creator.

) ) : null}
{error ? (

{error}

) : null} {onCreate ? ( ) : null} }> Cancel
); }