Optimized pasting, fixed host naming.

This commit is contained in:
LukeGus
2025-03-23 21:16:51 -05:00
parent ea631bd023
commit 4d33613679
9 changed files with 540 additions and 414 deletions

View File

@@ -149,6 +149,27 @@ export const User = forwardRef(({ onLoginSuccess, onCreateSuccess, onDeleteSucce
if (!currentUser.current) return onFailure("Not authenticated");
try {
const existingHosts = await getAllHosts();
const duplicateNameHost = existingHosts.find(host =>
host.config.name &&
host.config.name.toLowerCase() === hostConfig.hostConfig.name.toLowerCase()
);
if (duplicateNameHost) {
return onFailure("A host with this name already exists. Please choose a different name.");
}
if (!hostConfig.hostConfig.name) {
const duplicateIpHost = existingHosts.find(host =>
host.config.ip.toLowerCase() === hostConfig.hostConfig.ip.toLowerCase()
);
if (duplicateIpHost) {
return onFailure("A host with this IP already exists. Please provide a unique name.");
}
}
const response = await new Promise((resolve) => {
socketRef.current.emit("saveHostConfig", {
userId: currentUser.current.id,
@@ -222,6 +243,18 @@ export const User = forwardRef(({ onLoginSuccess, onCreateSuccess, onDeleteSucce
if (!currentUser.current) return onFailure("Not authenticated");
try {
const existingHosts = await getAllHosts();
const duplicateNameHost = existingHosts.find(host =>
host.config.name &&
host.config.name.toLowerCase() === newHostConfig.name.toLowerCase() &&
host.config.ip.toLowerCase() !== oldHostConfig.ip.toLowerCase()
);
if (duplicateNameHost) {
return onFailure("A host with this name already exists. Please choose a different name.");
}
const response = await new Promise((resolve) => {
socketRef.current.emit("editHost", {
userId: currentUser.current.id,