This commit is contained in:
afkarxyz committed 2025-12-11 22:17:57 +07:00
1 parent 2d913d987f
commit aa87cce538
25 files changed
+3835 -1574

No files matched your search

+400 -31
View File
@@ -3,7 +3,6 @@ import { Button } from "@/components/ui/button";
import { InputWithContext } from "@/components/ui/input-with-context";
import { Label } from "@/components/ui/label";
import {
Search,
XCircle,
Calendar,
StopCircle,
@@ -19,6 +18,14 @@ import {
Info,
RotateCcw,
Trash2,
Clock,
CloudDownload,
User,
Users,
FileText,
Hourglass,
CheckCircle,
AlertCircle,
} from "lucide-react";
import { Spinner } from "@/components/ui/spinner";
import { Checkbox } from "@/components/ui/checkbox";
@@ -41,11 +48,30 @@ import { cn } from "@/lib/utils";
export type FetchMode = "public" | "private";
export type PrivateType = "bookmarks" | "likes";
export type FetchType = "single" | "multiple";
// Local storage keys for auth tokens
const PUBLIC_AUTH_TOKEN_KEY = "twitter_public_auth_token";
const PRIVATE_AUTH_TOKEN_KEY = "twitter_private_auth_token";
export interface MultipleAccount {
id: string;
username: string;
status: "pending" | "fetching" | "completed" | "incomplete" | "failed";
accountInfo?: {
name: string;
nick: string;
profile_image: string;
};
mediaCount: number;
previousMediaCount: number;
elapsedTime: number;
remainingTime: number | null;
error?: string;
showDiff?: boolean;
cursor?: string;
}
interface SearchBarProps {
username: string;
loading: boolean;
@@ -69,6 +95,22 @@ interface SearchBarProps {
onHistorySelect: (item: HistoryItem) => void;
onHistoryRemove: (id: string) => void;
hasResult: boolean;
elapsedTime?: number;
remainingTime?: number | null;
// Multiple mode props
fetchType?: FetchType;
onFetchTypeChange?: (type: FetchType) => void;
multipleAccounts?: MultipleAccount[];
onImportFile?: () => void;
onFetchAll?: () => void;
onStopAll?: () => void;
onStopAccount?: (accountId: string) => void;
onRetryAccount?: (accountId: string) => void;
isFetchingAll?: boolean;
// Mode control
mode?: FetchMode;
privateType?: PrivateType;
onModeChange?: (mode: FetchMode, privateType?: PrivateType) => void;
}
export function SearchBar({
@@ -84,14 +126,41 @@ export function SearchBar({
onHistorySelect,
onHistoryRemove,
hasResult,
elapsedTime = 0,
remainingTime = null,
fetchType = "single",
onFetchTypeChange,
multipleAccounts = [],
onImportFile,
onFetchAll,
onStopAll,
onStopAccount,
onRetryAccount,
isFetchingAll = false,
mode: externalMode,
privateType: externalPrivateType,
onModeChange,
}: SearchBarProps) {
const [useDateRange, setUseDateRange] = useState(false);
const [startDate, setStartDate] = useState("");
const [endDate, setEndDate] = useState("");
const [mediaType, setMediaType] = useState("all");
const [retweets, setRetweets] = useState(false);
const [mode, setMode] = useState<FetchMode>("public");
const [privateType, setPrivateType] = useState<PrivateType>("bookmarks");
const [mode, setMode] = useState<FetchMode>(externalMode || "public");
const [privateType, setPrivateType] = useState<PrivateType>(externalPrivateType || "bookmarks");
// Sync with external mode if provided
useEffect(() => {
if (externalMode !== undefined) {
setMode(externalMode);
}
}, [externalMode]);
useEffect(() => {
if (externalPrivateType !== undefined) {
setPrivateType(externalPrivateType);
}
}, [externalPrivateType]);
const [showAuthInput, setShowAuthInput] = useState(false);
const [showAdvanced, setShowAdvanced] = useState(false);
@@ -138,42 +207,150 @@ export function SearchBar({
const isLikesMode = mode === "private" && privateType === "likes";
const isBookmarksMode = mode === "private" && privateType === "bookmarks";
const formatTime = (seconds: number): string => {
const mins = Math.floor(seconds / 60);
const secs = seconds % 60;
return `${mins}:${String(secs).padStart(2, "0")}`;
};
return (
<div className="space-y-3">
{/* Mode Toggle */}
<div className="flex justify-center">
<div className="flex gap-1 p-1 bg-muted rounded-lg w-fit">
{/* Fetch Type and Mode Toggle (Single/Multiple and Public/Private in one line) */}
<div className="flex justify-center gap-2">
<div className="flex gap-0.5 p-0.5 bg-muted rounded-lg w-fit">
<button
type="button"
onClick={() => setMode("public")}
onClick={() => onFetchTypeChange?.("single")}
className={cn(
"flex items-center gap-2 px-4 py-2 rounded-md text-sm font-medium transition-all cursor-pointer",
mode === "public"
"flex items-center gap-1 px-2 py-1 rounded-md text-xs font-medium transition-all cursor-pointer",
fetchType === "single"
? "bg-background text-foreground shadow-sm"
: "text-muted-foreground hover:text-foreground"
)}
>
<Globe className="h-4 w-4" />
Public
<User className="h-3 w-3" />
Single
</button>
<button
type="button"
onClick={() => setMode("private")}
onClick={() => onFetchTypeChange?.("multiple")}
className={cn(
"flex items-center gap-2 px-4 py-2 rounded-md text-sm font-medium transition-all cursor-pointer",
mode === "private"
"flex items-center gap-1 px-2 py-1 rounded-md text-xs font-medium transition-all cursor-pointer",
fetchType === "multiple"
? "bg-background text-foreground shadow-sm"
: "text-muted-foreground hover:text-foreground"
)}
>
<Lock className="h-4 w-4" />
Private
<Users className="h-3 w-3" />
Multiple
</button>
</div>
{fetchType === "single" && (
<div className="flex gap-0.5 p-0.5 bg-muted rounded-lg w-fit">
<button
type="button"
onClick={() => {
setMode("public");
onModeChange?.("public");
}}
className={cn(
"flex items-center gap-1 px-2 py-1 rounded-md text-xs font-medium transition-all cursor-pointer",
mode === "public"
? "bg-background text-foreground shadow-sm"
: "text-muted-foreground hover:text-foreground"
)}
>
<Globe className="h-3 w-3" />
Public
</button>
<button
type="button"
onClick={() => {
setMode("private");
onModeChange?.("private");
}}
className={cn(
"flex items-center gap-1 px-2 py-1 rounded-md text-xs font-medium transition-all cursor-pointer",
mode === "private"
? "bg-background text-foreground shadow-sm"
: "text-muted-foreground hover:text-foreground"
)}
>
<Lock className="h-3 w-3" />
Private
</button>
</div>
)}
</div>
{/* Username Input - for public mode and likes mode */}
{(mode === "public" || isLikesMode) && (
{/* Multiple Mode UI - Import and Fetch All Buttons */}
{fetchType === "multiple" && (
<div className="space-y-2">
<div className="flex items-center gap-2">
<Label htmlFor="import-txt" className="text-sm">
Import Accounts
</Label>
<Tooltip>
<TooltipTrigger asChild>
<Info className="h-4 w-4 text-muted-foreground cursor-help" />
</TooltipTrigger>
<TooltipContent className="max-w-xs">
<p className="text-sm">
One username per line, example:
<br />
<span className="font-mono text-xs">masteraoko</span>
<br />
<span className="font-mono text-xs">xbatchdemo</span>
<br />
<span className="font-mono text-xs">takomayuyi</span>
</p>
</TooltipContent>
</Tooltip>
</div>
<div className="flex items-center gap-2">
<Button
id="import-txt"
variant="outline"
onClick={onImportFile}
className="flex items-center gap-2 flex-1"
>
<FileText className="h-4 w-4" />
Import TXT File
</Button>
<Button
variant="default"
onClick={onFetchAll}
disabled={multipleAccounts.length === 0 || isFetchingAll}
className="flex items-center gap-2 flex-1"
>
{isFetchingAll ? (
<>
<Spinner />
Fetching All...
</>
) : (
<>
<CloudDownload className="h-4 w-4" />
Fetch All
</>
)}
</Button>
{isFetchingAll && (
<Button
variant="destructive"
onClick={onStopAll}
className="flex items-center gap-2"
>
<StopCircle className="h-4 w-4" />
Stop All
</Button>
)}
</div>
</div>
)}
{/* Username Input - for public mode and likes mode, only in single mode */}
{fetchType === "single" && (mode === "public" || isLikesMode) && (
<div className="space-y-2">
<Label htmlFor="username">
{isLikesMode ? "Your Username" : "Username"}
@@ -205,10 +382,23 @@ export function SearchBar({
</div>
<div className="flex items-center gap-2">
{loading && (
<Button variant="destructive" onClick={onStopFetch}>
<StopCircle className="h-4 w-4" />
Stop
</Button>
<>
{/* Timer Display */}
{(remainingTime !== null || elapsedTime > 0) && (
<div className="flex items-center gap-1.5 px-3 py-1.5 border rounded-md bg-muted/50 text-sm w-[85px]">
<Clock className="h-3.5 w-3.5 text-muted-foreground flex-shrink-0" />
<span className="font-mono">
{remainingTime !== null && remainingTime >= 0
? `${Math.floor(remainingTime / 60)}:${String(remainingTime % 60).padStart(2, "0")}`
: `${Math.floor(elapsedTime / 60)}:${String(elapsedTime % 60).padStart(2, "0")}`}
</span>
</div>
)}
<Button variant="destructive" onClick={onStopFetch}>
<StopCircle className="h-4 w-4" />
Stop
</Button>
</>
)}
{/* Resume button - show when there's resumable data */}
{!loading && resumeInfo?.canResume && mode === "public" && (
@@ -235,7 +425,7 @@ export function SearchBar({
</>
) : (
<>
{isLikesMode ? <Heart className="h-4 w-4" /> : <Search className="h-4 w-4" />}
{isLikesMode ? <Heart className="h-4 w-4" /> : <CloudDownload className="h-4 w-4" />}
{isLikesMode ? "Fetch Likes" : "Fetch"}
</>
)}
@@ -270,11 +460,14 @@ export function SearchBar({
</button>
{/* Private Mode Options - My Bookmarks / My Likes */}
{mode === "private" && (
{mode === "private" && fetchType === "single" && (
<>
<button
type="button"
onClick={() => setPrivateType("bookmarks")}
onClick={() => {
setPrivateType("bookmarks");
onModeChange?.("private", "bookmarks");
}}
className={cn(
"flex items-center gap-2 px-4 py-2 rounded-lg border text-sm font-medium transition-all cursor-pointer",
privateType === "bookmarks"
@@ -287,7 +480,10 @@ export function SearchBar({
</button>
<button
type="button"
onClick={() => setPrivateType("likes")}
onClick={() => {
setPrivateType("likes");
onModeChange?.("private", "likes");
}}
className={cn(
"flex items-center gap-2 px-4 py-2 rounded-lg border text-sm font-medium transition-all cursor-pointer",
privateType === "likes"
@@ -305,10 +501,23 @@ export function SearchBar({
{isBookmarksMode && (
<div className="flex items-center gap-2 ml-auto">
{loading && (
<Button variant="destructive" onClick={onStopFetch}>
<StopCircle className="h-4 w-4" />
Stop
</Button>
<>
{/* Timer Display */}
{(remainingTime !== null || elapsedTime > 0) && (
<div className="flex items-center gap-1.5 px-3 py-1.5 border rounded-md bg-muted/50 text-sm w-[85px]">
<Clock className="h-3.5 w-3.5 text-muted-foreground flex-shrink-0" />
<span className="font-mono">
{remainingTime !== null && remainingTime >= 0
? `${Math.floor(remainingTime / 60)}:${String(remainingTime % 60).padStart(2, "0")}`
: `${Math.floor(elapsedTime / 60)}:${String(elapsedTime % 60).padStart(2, "0")}`}
</span>
</div>
)}
<Button variant="destructive" onClick={onStopFetch}>
<StopCircle className="h-4 w-4" />
Stop
</Button>
</>
)}
<Button onClick={handleFetch} disabled={loading || !hasAuthToken}>
{loading ? (
@@ -471,7 +680,167 @@ export function SearchBar({
</div>
)}
{!hasResult && mode === "public" && (
{/* Statistics for Multiple Fetch - below auth token and advanced settings */}
{fetchType === "multiple" && multipleAccounts.length > 0 && (
<div className="p-3 border rounded-lg bg-muted/30">
<div className="flex items-center gap-6 text-sm">
<div className="flex items-center gap-2">
<CheckCircle className="h-4 w-4 text-green-600 dark:text-green-400" />
<span className="text-muted-foreground">Completed:</span>
<span className="font-medium">
{multipleAccounts.filter((acc) => acc.status === "completed").length}
</span>
</div>
<div className="flex items-center gap-2">
<AlertCircle className="h-4 w-4 text-yellow-600 dark:text-yellow-400" />
<span className="text-muted-foreground">Incomplete:</span>
<span className="font-medium">
{multipleAccounts.filter((acc) => acc.status === "incomplete").length}
</span>
</div>
<div className="flex items-center gap-2">
<XCircle className="h-4 w-4 text-red-600 dark:text-red-400" />
<span className="text-muted-foreground">Failed:</span>
<span className="font-medium">
{multipleAccounts.filter((acc) => acc.status === "failed").length}
</span>
</div>
<div className="flex items-center gap-2 ml-auto">
<span className="text-muted-foreground">Total:</span>
<span className="font-medium">
{multipleAccounts.filter((acc) =>
acc.status === "completed" || acc.status === "incomplete" || acc.status === "failed"
).length}/{multipleAccounts.length}
</span>
</div>
</div>
</div>
)}
{/* Account List - below auth token and advanced settings */}
{fetchType === "multiple" && multipleAccounts.length > 0 && (
<div className="space-y-2">
<p className="text-sm text-muted-foreground">Accounts to Fetch ({multipleAccounts.length})</p>
<div className="space-y-2 max-h-[400px] overflow-y-auto">
{multipleAccounts.map((account) => (
<div
key={account.id}
className="p-3 border rounded-lg bg-card"
>
<div className="flex items-center gap-3">
{account.accountInfo ? (
<img
src={account.accountInfo.profile_image}
alt={account.accountInfo.nick}
className="w-10 h-10 rounded-full"
/>
) : (
<div className="w-10 h-10 rounded-full bg-muted flex items-center justify-center">
<User className="h-5 w-5 text-muted-foreground" />
</div>
)}
<div className="flex-1 min-w-0">
{account.accountInfo ? (
<>
<div className="flex items-center gap-2">
<span className="font-medium">{account.accountInfo.nick}</span>
<span className="text-sm text-muted-foreground">@{account.accountInfo.name}</span>
</div>
<div className="flex items-center gap-2 mt-1">
<span className="text-sm text-muted-foreground">
<span className="text-primary">{account.mediaCount.toLocaleString()}</span> items found
</span>
{account.showDiff && account.previousMediaCount > 0 && account.mediaCount > account.previousMediaCount && (
<span className="text-sm text-green-600 dark:text-green-400 font-medium">
+{account.mediaCount - account.previousMediaCount}
</span>
)}
</div>
</>
) : (
<div className="flex items-center gap-2">
<span className="font-medium">@{account.username}</span>
</div>
)}
</div>
<div className="flex items-center gap-2">
{account.status === "fetching" && (
<>
<div className="flex items-center gap-1.5 px-3 py-1.5 border rounded-md bg-muted/50 text-sm w-[85px]">
<Clock className="h-3.5 w-3.5 text-muted-foreground flex-shrink-0" />
<span className="font-mono">
{account.remainingTime !== null && account.remainingTime >= 0
? formatTime(account.remainingTime)
: formatTime(account.elapsedTime)}
</span>
</div>
<Button
variant="destructive"
onClick={() => onStopAccount?.(account.id)}
className="flex items-center gap-2"
>
<StopCircle className="h-4 w-4" />
Stop
</Button>
</>
)}
{account.status === "pending" && (
<span className="text-xs px-2 py-1 bg-gray-500/20 text-gray-600 dark:text-gray-400 rounded flex items-center gap-1.5">
<Hourglass className="h-3 w-3" />
Pending
</span>
)}
{account.status === "completed" && (
<span className="text-xs px-2 py-1 bg-green-500/20 text-green-600 dark:text-green-400 rounded flex items-center gap-1.5">
<CheckCircle className="h-3 w-3" />
Completed
</span>
)}
{account.status === "incomplete" && (
<>
<span className="text-xs px-2 py-1 bg-yellow-500/20 text-yellow-600 dark:text-yellow-400 rounded flex items-center gap-1.5">
<AlertCircle className="h-3 w-3" />
Incomplete
</span>
<Button
variant="outline"
size="sm"
onClick={() => onRetryAccount?.(account.id)}
disabled={isFetchingAll}
className="flex items-center gap-2"
>
<RotateCcw className="h-3.5 w-3.5" />
Retry
</Button>
</>
)}
{account.status === "failed" && (
<>
<span className="text-xs px-2 py-1 bg-red-500/20 text-red-600 dark:text-red-400 rounded flex items-center gap-1.5">
<XCircle className="h-3 w-3" />
Failed
</span>
<Button
variant="outline"
size="sm"
onClick={() => onRetryAccount?.(account.id)}
disabled={isFetchingAll}
className="flex items-center gap-2"
>
<RotateCcw className="h-3.5 w-3.5" />
Retry
</Button>
</>
)}
</div>
</div>
</div>
))}
</div>
</div>
)}
{!hasResult && mode === "public" && fetchType === "single" && (
<FetchHistory
history={history}
onSelect={onHistorySelect}