mirror of
https://github.com/minoplhy/chhoto-url.git
synced 2024-11-22 17:26:45 +00:00
Copy shortUrl after adding to db
This commit is contained in:
parent
68ae439f5b
commit
d196c0373f
@ -75,7 +75,7 @@ public class UrlRepository {
|
|||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
return "";
|
return shortUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addHit(String shortURL) {
|
public void addHit(String shortURL) {
|
||||||
|
@ -27,13 +27,13 @@ const displayData = (data) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const addErrBox = async () => {
|
const addAlertBox = async (s, t) => {
|
||||||
const controls = document.querySelector(".pure-controls");
|
const controls = document.querySelector(".pure-controls");
|
||||||
const errBox = document.createElement("p");
|
const alertBox = document.createElement("p");
|
||||||
errBox.setAttribute("id", "errBox");
|
alertBox.setAttribute("id", "alertBox");
|
||||||
errBox.setAttribute("style", "color:red");
|
alertBox.setAttribute("style", `color:${t}`);
|
||||||
errBox.innerHTML = "Short URL not valid or already in use!";
|
alertBox.innerHTML = s;
|
||||||
controls.appendChild(errBox);
|
controls.appendChild(alertBox);
|
||||||
}
|
}
|
||||||
|
|
||||||
const TR = (row) => {
|
const TR = (row) => {
|
||||||
@ -94,17 +94,20 @@ const submitForm = () => {
|
|||||||
})
|
})
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
if (!res.ok) {
|
if (!res.ok) {
|
||||||
if (document.getElementById("errBox") == null) {
|
if (document.getElementById("alertBox") == null) {
|
||||||
addErrBox();
|
addAlertBox("Short URL not valid or already in use!", "red");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
document.getElementById("errBox")?.remove();
|
return res.text();
|
||||||
longUrl.value = "";
|
|
||||||
shortUrl.value = "";
|
|
||||||
|
|
||||||
refreshData();
|
|
||||||
}
|
}
|
||||||
|
}).then((text) => {
|
||||||
|
navigator.clipboard.writeText(`${window.location.host}/${text}`);
|
||||||
|
addAlertBox("Short URL copied to clipboard!", "green");
|
||||||
|
longUrl.value = "";
|
||||||
|
shortUrl.value = "";
|
||||||
|
|
||||||
|
refreshData();
|
||||||
});
|
});
|
||||||
|
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user