mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-20 07:43:12 +09:00
The list used to disappear when nobody was online. It is now a Collapse that opens while players are online and closes when the last one leaves. Once the user toggles it, their choice sticks for the page. Fixes #1191 Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
36 lines
1.1 KiB
TypeScript
36 lines
1.1 KiB
TypeScript
import React, { useState } from "react";
|
|
import { Collapse } from "antd";
|
|
|
|
import { useUsers } from "../model/user";
|
|
import UsersTable from "./UsersTable";
|
|
|
|
type OnlinePlayersListProps = {
|
|
instanceId: number;
|
|
};
|
|
|
|
export default function OnlinePlayersList({ instanceId }: OnlinePlayersListProps) {
|
|
const [users] = useUsers();
|
|
// undefined until the user toggles the panel, then their choice sticks.
|
|
const [open, setOpen] = useState<boolean>();
|
|
|
|
const onlineCount = [...users.values()].filter(user => user.instances?.has(instanceId)).length;
|
|
const expanded = open ?? onlineCount > 0;
|
|
|
|
return <Collapse
|
|
size="small"
|
|
style={{ marginTop: 16 }}
|
|
activeKey={expanded ? ["players"] : []}
|
|
onChange={keys => setOpen(keys.length > 0)}
|
|
items={[{
|
|
key: "players",
|
|
label: `Online Players (${onlineCount})`,
|
|
children: <UsersTable instanceId={instanceId} onlyOnline size="small" pagination={{
|
|
defaultPageSize: 10,
|
|
showSizeChanger: true,
|
|
pageSizeOptions: ["10", "20", "50", "100", "200"],
|
|
showTotal: (total: number) => `${total} Users`,
|
|
}} />,
|
|
}]}
|
|
/>;
|
|
}
|