Fixed API link
This commit is contained in:
@@ -92,9 +92,12 @@ function handleToast(event) {
|
|||||||
toastMessage.value = event.message;
|
toastMessage.value = event.message;
|
||||||
toastType.value = event.type;
|
toastType.value = event.type;
|
||||||
showToast.value = true;
|
showToast.value = true;
|
||||||
setTimeout(() => {
|
setTimeout(
|
||||||
|
() => {
|
||||||
showToast.value = false;
|
showToast.value = false;
|
||||||
}, event.type === "error" ? 4000 : 2000);
|
},
|
||||||
|
event.type === "error" ? 4000 : 2000
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function addGenerator() {
|
function addGenerator() {
|
||||||
|
|||||||
@@ -142,7 +142,7 @@ const props = defineProps({
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const emit = defineEmits(['show-toast']);
|
const emit = defineEmits(["show-toast"]);
|
||||||
|
|
||||||
const modern = ref(false);
|
const modern = ref(false);
|
||||||
const isLoading = ref(false);
|
const isLoading = ref(false);
|
||||||
@@ -221,7 +221,7 @@ async function generate() {
|
|||||||
try {
|
try {
|
||||||
if (modern.value) {
|
if (modern.value) {
|
||||||
// Use API for modern names
|
// Use API for modern names
|
||||||
const url = `http://localhost:8080/v1/modern/${language.value}?gender=${gender.value}`;
|
const url = `https://namegen.fernandovideira.com/v1/modern/${language.value}?gender=${gender.value}`;
|
||||||
const response = await fetch(url);
|
const response = await fetch(url);
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
@@ -237,14 +237,16 @@ async function generate() {
|
|||||||
"Failed to fetch modern names:",
|
"Failed to fetch modern names:",
|
||||||
data.message || "Unknown error"
|
data.message || "Unknown error"
|
||||||
);
|
);
|
||||||
emit('show-toast', {
|
emit("show-toast", {
|
||||||
message: `Error: ${data.message || "Failed to generate modern names"}`,
|
message: `Error: ${
|
||||||
type: 'error'
|
data.message || "Failed to generate modern names"
|
||||||
|
}`,
|
||||||
|
type: "error",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Use API for fantasy names
|
// Use API for fantasy names
|
||||||
const url = `http://localhost:8080/v1/fantasy/${race.value}-names?gender=${gender.value}`;
|
const url = `https://namegen.fernandovideira.com/v1/fantasy/${race.value}-names?gender=${gender.value}`;
|
||||||
const response = await fetch(url);
|
const response = await fetch(url);
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
@@ -260,17 +262,19 @@ async function generate() {
|
|||||||
"Failed to fetch fantasy names:",
|
"Failed to fetch fantasy names:",
|
||||||
data.message || "Unknown error"
|
data.message || "Unknown error"
|
||||||
);
|
);
|
||||||
emit('show-toast', {
|
emit("show-toast", {
|
||||||
message: `Error: ${data.message || "Failed to generate fantasy names"}`,
|
message: `Error: ${
|
||||||
type: 'error'
|
data.message || "Failed to generate fantasy names"
|
||||||
|
}`,
|
||||||
|
type: "error",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error fetching names:", error);
|
console.error("Error fetching names:", error);
|
||||||
emit('show-toast', {
|
emit("show-toast", {
|
||||||
message: `Connection error: ${error.message}`,
|
message: `Connection error: ${error.message}`,
|
||||||
type: 'error'
|
type: "error",
|
||||||
});
|
});
|
||||||
} finally {
|
} finally {
|
||||||
isLoading.value = false;
|
isLoading.value = false;
|
||||||
@@ -280,9 +284,9 @@ async function generate() {
|
|||||||
async function copyToClipboard(name) {
|
async function copyToClipboard(name) {
|
||||||
try {
|
try {
|
||||||
await navigator.clipboard.writeText(name);
|
await navigator.clipboard.writeText(name);
|
||||||
emit('show-toast', {
|
emit("show-toast", {
|
||||||
message: `"${name}" copied to clipboard!`,
|
message: `"${name}" copied to clipboard!`,
|
||||||
type: 'success'
|
type: "success",
|
||||||
});
|
});
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error("Failed to copy to clipboard:", err);
|
console.error("Failed to copy to clipboard:", err);
|
||||||
@@ -293,9 +297,9 @@ async function copyToClipboard(name) {
|
|||||||
textArea.select();
|
textArea.select();
|
||||||
document.execCommand("copy");
|
document.execCommand("copy");
|
||||||
document.body.removeChild(textArea);
|
document.body.removeChild(textArea);
|
||||||
emit('show-toast', {
|
emit("show-toast", {
|
||||||
message: `"${name}" copied to clipboard!`,
|
message: `"${name}" copied to clipboard!`,
|
||||||
type: 'success'
|
type: "success",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user