mirror of
https://github.com/streamyfin/streamyfin.git
synced 2026-04-20 15:54:42 +01:00
Implement enhanced server switching with credential persistence and auto-login
Co-authored-by: retardgerman <78982850+retardgerman@users.noreply.github.com>
This commit is contained in:
@@ -8,6 +8,13 @@ import { ListItem } from "./list/ListItem";
|
||||
|
||||
interface Server {
|
||||
address: string;
|
||||
serverName?: string;
|
||||
serverId?: string;
|
||||
lastUsername?: string;
|
||||
savedCredentials?: {
|
||||
username: string;
|
||||
password: string;
|
||||
};
|
||||
}
|
||||
|
||||
interface PreviousServersListProps {
|
||||
@@ -26,6 +33,20 @@ export const PreviousServersList: React.FC<PreviousServersListProps> = ({
|
||||
|
||||
const { t } = useTranslation();
|
||||
|
||||
const getServerDisplayName = (server: Server) => {
|
||||
if (server.serverName) {
|
||||
return `${server.serverName}`;
|
||||
}
|
||||
return server.address;
|
||||
};
|
||||
|
||||
const getServerSubtitle = (server: Server) => {
|
||||
if (server.lastUsername) {
|
||||
return `${server.address} • ${server.lastUsername}`;
|
||||
}
|
||||
return server.address;
|
||||
};
|
||||
|
||||
if (!previousServers.length) return null;
|
||||
|
||||
return (
|
||||
@@ -35,7 +56,9 @@ export const PreviousServersList: React.FC<PreviousServersListProps> = ({
|
||||
<ListItem
|
||||
key={s.address}
|
||||
onPress={() => onServerSelect(s)}
|
||||
title={s.address}
|
||||
title={getServerDisplayName(s)}
|
||||
subtitle={getServerSubtitle(s)}
|
||||
icon={s.savedCredentials ? "key" : "server"}
|
||||
showArrow
|
||||
/>
|
||||
))}
|
||||
|
||||
@@ -10,6 +10,13 @@ import { ListItem } from "../list/ListItem";
|
||||
|
||||
interface Server {
|
||||
address: string;
|
||||
serverName?: string;
|
||||
serverId?: string;
|
||||
lastUsername?: string;
|
||||
savedCredentials?: {
|
||||
username: string;
|
||||
password: string;
|
||||
};
|
||||
}
|
||||
|
||||
interface Props extends ViewProps {}
|
||||
@@ -38,6 +45,23 @@ export const ServerSwitcher: React.FC<Props> = ({ ...props }) => {
|
||||
}
|
||||
};
|
||||
|
||||
const getServerDisplayName = (server: Server) => {
|
||||
if (server.serverName) {
|
||||
return `${server.serverName} (${server.address})`;
|
||||
}
|
||||
return server.address;
|
||||
};
|
||||
|
||||
const getServerSubtitle = (server: Server) => {
|
||||
if (server.lastUsername) {
|
||||
const hasCredentials = !!server.savedCredentials;
|
||||
return hasCredentials
|
||||
? `${server.lastUsername} • Auto-login available`
|
||||
: `Last user: ${server.lastUsername}`;
|
||||
}
|
||||
return undefined;
|
||||
};
|
||||
|
||||
if (!previousServers.length) {
|
||||
return (
|
||||
<View {...props}>
|
||||
@@ -55,7 +79,9 @@ export const ServerSwitcher: React.FC<Props> = ({ ...props }) => {
|
||||
<ListItem
|
||||
key={server.address}
|
||||
onPress={() => handleServerSwitch(server)}
|
||||
title={server.address}
|
||||
title={getServerDisplayName(server)}
|
||||
subtitle={getServerSubtitle(server)}
|
||||
icon={server.savedCredentials ? "key" : "server"}
|
||||
showArrow
|
||||
disabled={switchingServer === server.address}
|
||||
/>
|
||||
|
||||
Reference in New Issue
Block a user