Copy shortUrl after adding to db

This commit is contained in:
SinTan1729 2022-11-10 18:11:57 -06:00
parent 68ae439f5b
commit d196c0373f
2 changed files with 17 additions and 14 deletions

View File

@ -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) {

View File

@ -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();
}); });
}; };