mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-24 16:23:12 +09:00
Always show the instance player list, collapsed when empty (#1197)
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>
This commit is contained in:
1 parent
484cffc136
commit
ae707f7768
1 file changed
+18
-14
@@ -1,4 +1,5 @@
|
|||||||
import React from "react";
|
import React, { useState } from "react";
|
||||||
|
import { Collapse } from "antd";
|
||||||
|
|
||||||
import { useUsers } from "../model/user";
|
import { useUsers } from "../model/user";
|
||||||
import UsersTable from "./UsersTable";
|
import UsersTable from "./UsersTable";
|
||||||
@@ -9,23 +10,26 @@ type OnlinePlayersListProps = {
|
|||||||
|
|
||||||
export default function OnlinePlayersList({ instanceId }: OnlinePlayersListProps) {
|
export default function OnlinePlayersList({ instanceId }: OnlinePlayersListProps) {
|
||||||
const [users] = useUsers();
|
const [users] = useUsers();
|
||||||
|
// undefined until the user toggles the panel, then their choice sticks.
|
||||||
|
const [open, setOpen] = useState<boolean>();
|
||||||
|
|
||||||
// Filter users to only show those online on this specific instance
|
const onlineCount = [...users.values()].filter(user => user.instances?.has(instanceId)).length;
|
||||||
const onlineUsers = [...users.values()].filter(user => user.instances && user.instances.has(instanceId));
|
const expanded = open ?? onlineCount > 0;
|
||||||
|
|
||||||
if (onlineUsers.length === 0) {
|
return <Collapse
|
||||||
return null;
|
size="small"
|
||||||
}
|
style={{ marginTop: 16 }}
|
||||||
|
activeKey={expanded ? ["players"] : []}
|
||||||
return (
|
onChange={keys => setOpen(keys.length > 0)}
|
||||||
<div style={{ marginTop: 16 }}>
|
items={[{
|
||||||
<h4>Online Players ({onlineUsers.length})</h4>
|
key: "players",
|
||||||
<UsersTable instanceId={instanceId} onlyOnline size="small" pagination={{
|
label: `Online Players (${onlineCount})`,
|
||||||
|
children: <UsersTable instanceId={instanceId} onlyOnline size="small" pagination={{
|
||||||
defaultPageSize: 10,
|
defaultPageSize: 10,
|
||||||
showSizeChanger: true,
|
showSizeChanger: true,
|
||||||
pageSizeOptions: ["10", "20", "50", "100", "200"],
|
pageSizeOptions: ["10", "20", "50", "100", "200"],
|
||||||
showTotal: (total: number) => `${total} Users`,
|
showTotal: (total: number) => `${total} Users`,
|
||||||
}} />
|
}} />,
|
||||||
</div>
|
}]}
|
||||||
);
|
/>;
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user