Merge pull request #18 from killer-cf/fix-page-with-lint-errors
Fix page with lint errors
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
import {
|
||||
ExternalLink,
|
||||
FileText,
|
||||
File,
|
||||
File as FileIcon,
|
||||
Upload,
|
||||
Trash2,
|
||||
Eye,
|
||||
@@ -16,7 +16,7 @@
|
||||
value?: string; // storageId
|
||||
disabled?: boolean;
|
||||
required?: boolean;
|
||||
onUpload: (file: File) => Promise<void>;
|
||||
onUpload: (file: globalThis.File) => Promise<void>;
|
||||
onRemove: () => Promise<void>;
|
||||
}
|
||||
|
||||
@@ -48,38 +48,33 @@
|
||||
"image/png",
|
||||
];
|
||||
|
||||
// Buscar URL do arquivo quando houver um storageId
|
||||
$effect(() => {
|
||||
if (value && !fileName) {
|
||||
// Tem storageId mas não é um upload recente
|
||||
loadExistingFile(value);
|
||||
}
|
||||
});
|
||||
|
||||
async function loadExistingFile(storageId: string) {
|
||||
try {
|
||||
const url = await client.storage.getUrl(storageId as any);
|
||||
if (url) {
|
||||
fileUrl = url;
|
||||
fileName = "Documento anexado";
|
||||
// Detectar tipo pelo URL ou assumir PDF
|
||||
if (url.includes(".pdf") || url.includes("application/pdf")) {
|
||||
fileType = "application/pdf";
|
||||
} else {
|
||||
fileType = "image/jpeg";
|
||||
previewUrl = url; // Para imagens, a URL serve como preview
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
console.error("Erro ao carregar arquivo existente:", err);
|
||||
}
|
||||
}
|
||||
// Buscar URL do arquivo quando houver um storageId
|
||||
$effect(() => {
|
||||
if (value && !fileName) {
|
||||
// Tem storageId mas não é um upload recente
|
||||
loadExistingFile(value);
|
||||
}
|
||||
});
|
||||
|
||||
async function loadExistingFile(storageId: string) {
|
||||
try {
|
||||
const url = await client.storage.getUrl(storageId as any);
|
||||
if (url) {
|
||||
async function handleFileSelect(event: Event) {
|
||||
const target = event.target as HTMLInputElement;
|
||||
const file = target.files?.[0];
|
||||
|
||||
if (!file) return;
|
||||
// Detectar tipo pelo URL ou assumir PDF
|
||||
if (url.includes('.pdf') || url.includes('application/pdf')) {
|
||||
fileType = 'application/pdf';
|
||||
} else {
|
||||
fileType = 'image/jpeg';
|
||||
previewUrl = url; // Para imagens, a URL serve como preview
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Erro ao carregar arquivo existente:', err);
|
||||
}
|
||||
}
|
||||
|
||||
error = null;
|
||||
|
||||
@@ -187,32 +182,22 @@
|
||||
{disabled}
|
||||
/>
|
||||
|
||||
{#if value || fileName}
|
||||
<div
|
||||
class="flex items-center gap-2 p-3 border border-base-300 rounded-lg bg-base-100"
|
||||
>
|
||||
<!-- Preview -->
|
||||
<div class="shrink-0">
|
||||
{#if previewUrl}
|
||||
<img
|
||||
src={previewUrl}
|
||||
alt="Preview"
|
||||
class="w-12 h-12 object-cover rounded"
|
||||
/>
|
||||
{:else if fileType === "application/pdf" || fileName.endsWith(".pdf")}
|
||||
<div
|
||||
class="w-12 h-12 bg-error/10 rounded flex items-center justify-center"
|
||||
>
|
||||
<FileText class="h-6 w-6 text-error" strokeWidth={2} />
|
||||
</div>
|
||||
{:else}
|
||||
<div
|
||||
class="w-12 h-12 bg-success/10 rounded flex items-center justify-center"
|
||||
>
|
||||
<File class="h-6 w-6 text-success" strokeWidth={2} />
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
{#if value || fileName}
|
||||
<div class="border-base-300 bg-base-100 flex items-center gap-2 rounded-lg border p-3">
|
||||
<!-- Preview -->
|
||||
<div class="shrink-0">
|
||||
{#if previewUrl}
|
||||
<img src={previewUrl} alt="Preview" class="h-12 w-12 rounded object-cover" />
|
||||
{:else if fileType === 'application/pdf' || fileName.endsWith('.pdf')}
|
||||
<div class="bg-error/10 flex h-12 w-12 items-center justify-center rounded">
|
||||
<FileText class="text-error h-6 w-6" strokeWidth={2} />
|
||||
</div>
|
||||
{:else}
|
||||
<div class="bg-success/10 flex h-12 w-12 items-center justify-center rounded">
|
||||
<File class="text-success h-6 w-6" strokeWidth={2} />
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<!-- File info -->
|
||||
<div class="flex-1 min-w-0">
|
||||
|
||||
@@ -366,7 +366,7 @@
|
||||
{@const isActive = currentPath.startsWith(s.link)}
|
||||
<li class="rounded-xl">
|
||||
<a
|
||||
href={s.link}
|
||||
href={resolve(s.link)}
|
||||
aria-current={isActive ? 'page' : undefined}
|
||||
class={getMenuClasses(isActive)}
|
||||
>
|
||||
|
||||
Reference in New Issue
Block a user