mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-16 23:30:41 +09:00
Rename Slave to Host
The role of a slave as a host for Factorio servers is not well reflected in its name and has caused confusion among users. Rename slave to host to better reflect its role as a host of Factorio servers.
This commit is contained in:
1 parent
70ad295a89
commit
6fc3abafd5
101 files changed
+1168
-1168
No files matched your search
@@ -0,0 +1,77 @@
|
||||
import { useEffect, useContext, useState } from "react";
|
||||
import ControlContext from "../components/ControlContext";
|
||||
|
||||
import { libLink } from "@clusterio/lib";
|
||||
|
||||
|
||||
export function useHost(id) {
|
||||
let control = useContext(ControlContext);
|
||||
let [host, setHost] = useState({ loading: true });
|
||||
|
||||
function updateHost() {
|
||||
// XXX optimize by requesting only the host in question
|
||||
libLink.messages.listHosts.send(control).then(result => {
|
||||
let match = result.list.find(i => i.id === id);
|
||||
if (!match) {
|
||||
setHost({ missing: true });
|
||||
} else {
|
||||
setHost({ ...match, present: true });
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
if (!Number.isInteger(id)) {
|
||||
setHost({ missing: true });
|
||||
return undefined;
|
||||
}
|
||||
updateHost();
|
||||
|
||||
function updateHandler(newHost) {
|
||||
setHost({ ...newHost, present: true });
|
||||
}
|
||||
|
||||
control.onHostUpdate(id, updateHandler);
|
||||
return () => {
|
||||
control.offHostUpdate(id, updateHandler);
|
||||
};
|
||||
}, [id]);
|
||||
|
||||
return [host, updateHost];
|
||||
}
|
||||
|
||||
export function useHostList() {
|
||||
let control = useContext(ControlContext);
|
||||
let [hostList, setHostList] = useState([]);
|
||||
|
||||
function updateHostList() {
|
||||
libLink.messages.listHosts.send(control).then(result => {
|
||||
setHostList(result.list);
|
||||
});
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
updateHostList();
|
||||
|
||||
function updateHandler(newHost) {
|
||||
setHostList(oldList => {
|
||||
let newList = oldList.concat();
|
||||
let index = newList.findIndex(s => s.id === newHost.id);
|
||||
if (index !== -1) {
|
||||
newList[index] = newHost;
|
||||
} else {
|
||||
newList.push(newHost);
|
||||
}
|
||||
return newList;
|
||||
});
|
||||
}
|
||||
|
||||
control.onHostUpdate(null, updateHandler);
|
||||
return () => {
|
||||
control.offHostUpdate(null, updateHandler);
|
||||
};
|
||||
}, []);
|
||||
|
||||
|
||||
return [hostList];
|
||||
}
|
||||
@@ -1,77 +0,0 @@
|
||||
import { useEffect, useContext, useState } from "react";
|
||||
import ControlContext from "../components/ControlContext";
|
||||
|
||||
import { libLink } from "@clusterio/lib";
|
||||
|
||||
|
||||
export function useSlave(id) {
|
||||
let control = useContext(ControlContext);
|
||||
let [slave, setSlave] = useState({ loading: true });
|
||||
|
||||
function updateSlave() {
|
||||
// XXX optimize by requesting only the slave in question
|
||||
libLink.messages.listSlaves.send(control).then(result => {
|
||||
let match = result.list.find(i => i.id === id);
|
||||
if (!match) {
|
||||
setSlave({ missing: true });
|
||||
} else {
|
||||
setSlave({ ...match, present: true });
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
if (!Number.isInteger(id)) {
|
||||
setSlave({ missing: true });
|
||||
return undefined;
|
||||
}
|
||||
updateSlave();
|
||||
|
||||
function updateHandler(newSlave) {
|
||||
setSlave({ ...newSlave, present: true });
|
||||
}
|
||||
|
||||
control.onSlaveUpdate(id, updateHandler);
|
||||
return () => {
|
||||
control.offSlaveUpdate(id, updateHandler);
|
||||
};
|
||||
}, [id]);
|
||||
|
||||
return [slave, updateSlave];
|
||||
}
|
||||
|
||||
export function useSlaveList() {
|
||||
let control = useContext(ControlContext);
|
||||
let [slaveList, setSlaveList] = useState([]);
|
||||
|
||||
function updateSlaveList() {
|
||||
libLink.messages.listSlaves.send(control).then(result => {
|
||||
setSlaveList(result.list);
|
||||
});
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
updateSlaveList();
|
||||
|
||||
function updateHandler(newSlave) {
|
||||
setSlaveList(oldList => {
|
||||
let newList = oldList.concat();
|
||||
let index = newList.findIndex(s => s.id === newSlave.id);
|
||||
if (index !== -1) {
|
||||
newList[index] = newSlave;
|
||||
} else {
|
||||
newList.push(newSlave);
|
||||
}
|
||||
return newList;
|
||||
});
|
||||
}
|
||||
|
||||
control.onSlaveUpdate(null, updateHandler);
|
||||
return () => {
|
||||
control.offSlaveUpdate(null, updateHandler);
|
||||
};
|
||||
}, []);
|
||||
|
||||
|
||||
return [slaveList];
|
||||
}
|
||||
Reference in new issue
Block a user