mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-20 23:53:13 +09:00
Rewrite instances page
Render the table in the instances page using an antd Table component directly and feed it the data via an automatically updating list of instances.
This commit is contained in:
1 parent
0e9893fcb6
commit
82c3d27bff
4 files changed
+136
-36
No files matched your search
@@ -39,3 +39,44 @@ export function useInstance(id) {
|
||||
|
||||
return [instance, updateInstance];
|
||||
}
|
||||
|
||||
export function useInstanceList() {
|
||||
let control = useContext(ControlContext);
|
||||
let [instanceList, setInstanceList] = useState([]);
|
||||
|
||||
function updateInstanceList() {
|
||||
libLink.messages.listInstances.send(control).then(result => {
|
||||
setInstanceList(result.list);
|
||||
}).catch(err => {
|
||||
logger.error(`Failed to list instances:\n${err}`);
|
||||
});
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
updateInstanceList();
|
||||
|
||||
function updateHandler(newInstance) {
|
||||
setInstanceList(oldList => {
|
||||
let newList = oldList.concat();
|
||||
let index = newList.findIndex(s => s.id === newInstance.id);
|
||||
if (newInstance.status !== "deleted") {
|
||||
if (index !== -1) {
|
||||
newList[index] = newInstance;
|
||||
} else {
|
||||
newList.push(newInstance);
|
||||
}
|
||||
} else if (index !== -1) {
|
||||
newList.splice(index, 1);
|
||||
}
|
||||
return newList;
|
||||
});
|
||||
}
|
||||
|
||||
control.onInstanceUpdate(null, updateHandler);
|
||||
return () => {
|
||||
control.offInstanceUpdate(null, updateHandler);
|
||||
};
|
||||
}, []);
|
||||
|
||||
return [instanceList];
|
||||
}
|
||||
Reference in new issue
Block a user