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