penambahan fitur upload
This commit is contained in:
@@ -279,9 +279,29 @@
|
||||
}
|
||||
}
|
||||
|
||||
// function get public URL for image supabase
|
||||
async function getPublicUrl(path: string): Promise<string> {
|
||||
const { data } = supabase.storage.from("villabugis").getPublicUrl(path);
|
||||
return data.publicUrl;
|
||||
}
|
||||
|
||||
async function saveProject(event: Event) {
|
||||
const formData = new FormData(event.target as HTMLFormElement);
|
||||
|
||||
// Upload image if selected
|
||||
if (selectedFile) {
|
||||
const { data, error } = await supabase.storage
|
||||
.from("villabugis")
|
||||
.upload(`project/${selectedFile.name}`, selectedFile);
|
||||
|
||||
if (error) {
|
||||
console.error("Error uploading image:", error);
|
||||
return;
|
||||
}
|
||||
|
||||
imagePreviewUrl = data?.path;
|
||||
}
|
||||
|
||||
const projectUpdate: insetProject = {
|
||||
issue_id: formData.get("issue_id") as string,
|
||||
input_by: formData.get("input_by") as string,
|
||||
@@ -439,15 +459,21 @@
|
||||
❌
|
||||
{/if}
|
||||
</td>
|
||||
{:else if col.key === "project_picture_link"}
|
||||
{:else if col.key === "picture_link"}
|
||||
<td class="px-4 py-2">
|
||||
{#if row.picture_link}
|
||||
<a
|
||||
href={row.picture_link}
|
||||
target="_blank"
|
||||
class="text-blue-600 hover:underline"
|
||||
>View Picture</a
|
||||
>
|
||||
{#await getPublicUrl(row.picture_link) then publicUrl}
|
||||
<a
|
||||
href={publicUrl}
|
||||
target="_blank"
|
||||
class="text-blue-600 hover:underline"
|
||||
>View Picture</a
|
||||
>
|
||||
{:catch}
|
||||
<span class="text-red-500"
|
||||
>Error loading image</span
|
||||
>
|
||||
{/await}
|
||||
{:else}
|
||||
No Picture
|
||||
{/if}
|
||||
@@ -556,6 +582,18 @@
|
||||
alt="Preview"
|
||||
class="mt-2 max-h-48 rounded border"
|
||||
/>
|
||||
{:else if newProjects.picture_link}
|
||||
{#await getPublicUrl(newProjects.picture_link) then url}
|
||||
<img
|
||||
src={url}
|
||||
alt="Preview"
|
||||
class="mt-2 max-h-48 rounded border"
|
||||
/>
|
||||
{/await}
|
||||
{:else}
|
||||
<p class="text-red-500 mt-2">
|
||||
No image selected or uploaded.
|
||||
</p>
|
||||
{/if}
|
||||
</div>
|
||||
{:else}
|
||||
|
||||
Reference in New Issue
Block a user