All files / src/components/playlist XtreamFields.tsx

70% Statements 7/10
100% Branches 4/4
57.14% Functions 4/7
70% Lines 7/10

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77                                          2x                 32x 32x   32x       32x                             32x                     32x                          
// SPDX-License-Identifier: GPL-3.0-only
// Copyright (C) 2026 Max Boksem. See NOTICE for additional terms under GPLv3 section 7.
 
import { Field } from "@/components/ui/field";
import { Input } from "@/components/ui/input";
 
interface XtreamFieldsProps {
	/**
	 * The add form is compact and names its fields with placeholders. The
	 * settings modal shows labels above smaller inputs and lets fields stay
	 * empty, since it saves more than the login.
	 */
	variant: "add" | "edit";
	url: string;
	username: string;
	password: string;
	onUrlChange: (value: string) => void;
	onUsernameChange: (value: string) => void;
	onPasswordChange: (value: string) => void;
}
 
export const XtreamFields = ({
	variant,
	url,
	username,
	password,
	onUrlChange,
	onUsernameChange,
	onPasswordChange,
}: XtreamFieldsProps) => {
	const editing = variant === "edit";
	const inputProps = editing ? { className: "h-8 text-sm" } : { required: true };
 
	return (
		<>
			<Field label="Server URL" hideLabel={!editing}>
				{(id) => (
					<Input
						id={id}
						value={url}
						onChange={(e) => onUrlChange(e.target.value)}
						placeholder={
							editing
								? "http://example.com:8080"
								: "Server URL (e.g. http://example.com:8080)"
						}
						{...inputProps}
					/>
				)}
			</Field>
			<Field label="Username" hideLabel={!editing}>
				{(id) => (
					<Input
						id={id}
						value={username}
						onChange={(e) => onUsernameChange(e.target.value)}
						placeholder="Username"
						{...inputProps}
					/>
				)}
			</Field>
			<Field label="Password" hideLabel={!editing}>
				{(id) => (
					<Input
						id={id}
						value={password}
						onChange={(e) => onPasswordChange(e.target.value)}
						placeholder="Password"
						type="password"
						{...inputProps}
					/>
				)}
			</Field>
		</>
	);
};