import type { Api } from "@jellyfin/sdk"; import type { UserDto } from "@jellyfin/sdk/lib/generated-client"; import { getUserApi } from "@jellyfin/sdk/lib/utils/api/user-api"; import { queryOptions } from "@tanstack/react-query"; import React, { useState } from "react"; import { useApiInContext } from "@/utils/store/api"; /** Public (listed) users of the current server; shared by the login pages. */ export const getPublicUsersQueryOptions = (api: Api | null | undefined) => queryOptions({ queryKey: ["login", "public-users"], queryFn: async () => api ? (await getUserApi(api).getPublicUsers()).data : [], enabled: Boolean(api), }); type ProfileAvatarProps = { userId: string; name: string; imageTag?: string | null; /** Shows a lock badge for password-protected profiles. */ locked?: boolean; }; /** Round profile picture, falling back to the user's initial. */ export const ProfileAvatar = ({ userId, name, imageTag, locked, }: ProfileAvatarProps) => { const api = useApiInContext((s) => s.api); const [failed, setFailed] = useState(false); const showImage = api && imageTag && !failed; return ( {showImage ? ( setFailed(true)} /> ) : ( {name.trim().charAt(0).toUpperCase() || "?"} )} {locked && ( lock )} ); }; export const isPasswordProtected = (user: UserDto | undefined) => user?.HasPassword !== false;