Skip to content

Commit ce86b90

Browse files
committed
improve ui of FIleInput when uploading
1 parent 415103f commit ce86b90

File tree

2 files changed

+21
-24
lines changed

2 files changed

+21
-24
lines changed

apps/web/components/FileInput.tsx

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"use client";
22

3-
import { Button, Input } from "@cap/ui";
3+
import { Button, Input, LoadingSpinner } from "@cap/ui";
44
import {
55
faCloudUpload,
66
faSpinner,
@@ -12,6 +12,7 @@ import type React from "react";
1212
import { useEffect, useRef, useState } from "react";
1313
import { toast } from "sonner";
1414
import { useSignedImageUrl } from "@/lib/use-signed-image-url";
15+
import { SignedImageUrl } from "./SignedImageUrl";
1516
import { Tooltip } from "./Tooltip";
1617

1718
const ALLOWED_IMAGE_TYPES = new Set(["image/jpeg", "image/png"]);
@@ -61,13 +62,6 @@ export const FileInput: React.FC<FileInputProps> = ({
6162
// Get signed URL for S3 keys
6263
const { data: signedUrl } = useSignedImageUrl(previewUrl, type);
6364

64-
function isS3Key(imageKeyOrUrl: string | null | undefined): boolean {
65-
if (!imageKeyOrUrl) return false;
66-
return (
67-
imageKeyOrUrl.startsWith("users/") ||
68-
imageKeyOrUrl.startsWith("organizations/")
69-
);
70-
}
7165
const previousPreviewRef = useRef<{
7266
url: string | null;
7367
isLocal: boolean;
@@ -235,7 +229,12 @@ export const FileInput: React.FC<FileInputProps> = ({
235229
}}
236230
>
237231
{/* Fixed height container to prevent resizing */}
238-
{previewUrl ? (
232+
{isLoading ? (
233+
<div className="flex h-full items-center gap-2 rounded-xl border border-dashed border-gray-4 bg-gray-1 px-4 py-1.5">
234+
<LoadingSpinner themeColors size={16} />
235+
<p className="truncate text-[13px] text-gray-11">Uploading...</p>
236+
</div>
237+
) : previewUrl ? (
239238
<div className="flex h-full items-center gap-2 rounded-xl border border-dashed border-gray-4 bg-gray-1 px-4 py-1.5">
240239
<div className="flex flex-1 items-center gap-1.5">
241240
<div className="flex flex-1 gap-1 items-center">
@@ -250,19 +249,13 @@ export const FileInput: React.FC<FileInputProps> = ({
250249
}}
251250
className="flex overflow-hidden relative flex-shrink-0 justify-center items-center rounded-full"
252251
>
253-
{previewUrl && (
254-
<img
255-
src={
256-
isS3Key(previewUrl) ? (signedUrl ?? "") : previewUrl
257-
}
258-
alt="File preview"
259-
width={32}
260-
height={32}
261-
loading="eager"
262-
referrerPolicy="no-referrer"
263-
className="object-cover rounded-full size-8"
264-
/>
265-
)}
252+
<SignedImageUrl
253+
image={previewUrl}
254+
name="File preview"
255+
type={type}
256+
letterClass="text-lg"
257+
className="size-full"
258+
/>
266259
</div>
267260
</div>
268261
</div>

packages/ui/src/components/LoadingSpinner.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,28 @@ export const LoadingSpinner = ({
22
size = 36,
33
color = "white",
44
borderColor = "rgba(255, 255, 255, 0.2)",
5+
themeColors = false,
56
thickness = 3,
67
speed = 1.5,
78
className,
89
}: {
910
size?: number;
1011
color?: string;
1112
borderColor?: string;
13+
themeColors?: boolean;
1214
thickness?: number;
1315
speed?: number;
1416
className?: string;
1517
}) => {
18+
const borderColorValue = themeColors ? "var(--gray-4)" : borderColor;
19+
const colorValue = themeColors ? "var(--gray-12)" : color;
1620
const spinnerStyle = {
1721
width: `${size}px`,
1822
minWidth: `${size}px`,
1923
height: `${size}px`,
2024
minHeight: `${size}px`,
21-
border: `${thickness}px solid ${borderColor}`,
22-
borderTop: `${thickness}px solid ${color}`,
25+
border: `${thickness}px solid ${borderColorValue}`,
26+
borderTop: `${thickness}px solid ${colorValue}`,
2327
borderRadius: "50%",
2428
animation: `spin ${1 / speed}s linear infinite`,
2529
};

0 commit comments

Comments
 (0)