mirror of
https://github.com/eliasrenman/url-shortener.git
synced 2026-03-16 20:16:06 +01:00
feat: added basic edit form
This commit is contained in:
@@ -33,7 +33,7 @@
|
||||
};
|
||||
</script>
|
||||
|
||||
<form method="POST" on:submit={handleSubmit}>
|
||||
<form method="POST" on:submit={handleSubmit} id="form">
|
||||
<div class="flex mt-4 p-4 bg-gray-800 rounded-lg shadow-lg gap-4 flex-col">
|
||||
<div class="flex flex-row gap-2 justify-center items-center">
|
||||
<p>{window.location.origin}/</p>
|
||||
|
||||
@@ -10,6 +10,17 @@
|
||||
$mutation.mutate(row.url);
|
||||
}
|
||||
}
|
||||
|
||||
function editItem() {
|
||||
const form = document.getElementById("form") as HTMLFormElement;
|
||||
form.reset();
|
||||
for (const [key, value] of Object.entries(row)) {
|
||||
const item = form.elements.namedItem(key) as HTMLInputElement;
|
||||
if (!item) continue;
|
||||
if (key === "ttl") continue;
|
||||
item.value = value as string;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<tr class="border-t border-gray-700 hover:bg-gray-700 transition">
|
||||
@@ -25,7 +36,10 @@
|
||||
>{row.ttl ? new Date(row.ttl).toLocaleTimeString() : "Never"}</td
|
||||
>
|
||||
<td class="p-3 flex gap-3">
|
||||
<button class="text-blue-600 hover:text-blue-500 cursor-pointer transition">
|
||||
<button
|
||||
onclick={editItem}
|
||||
class="text-blue-600 hover:text-blue-500 cursor-pointer transition"
|
||||
>
|
||||
<Edit size={18} />
|
||||
</button>
|
||||
<button
|
||||
|
||||
Reference in New Issue
Block a user