Skip to content

Commit bd1c91c

Browse files
committed
FileInput updates
1 parent b0fc137 commit bd1c91c

File tree

8 files changed

+19
-45
lines changed

8 files changed

+19
-45
lines changed

apps/dashboard/src/@/components/blocks/Img.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ type imgElementProps = React.DetailedHTMLProps<
1111
skeleton?: React.ReactNode;
1212
fallback?: React.ReactNode;
1313
src: string | undefined;
14+
containerClassName?: string;
1415
};
1516

1617
export function Img(props: imgElementProps) {
@@ -47,7 +48,7 @@ export function Img(props: imgElementProps) {
4748
}, []);
4849

4950
return (
50-
<div className="relative shrink-0">
51+
<div className={cn("relative shrink-0", props.containerClassName)}>
5152
<img
5253
{...restProps}
5354
// avoid setting empty src string to prevent request to the entire page

apps/dashboard/src/app/(app)/account/settings/AccountSettingsPageUI.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,11 +139,10 @@ function AccountAvatarFormControl(props: {
139139
<FileInput
140140
client={props.client}
141141
accept={{ "image/*": [] }}
142-
value={avatar}
142+
value={avatar || accountAvatarUrl}
143143
setValue={setAvatar}
144144
className="w-20 rounded-full lg:w-28"
145145
disableHelperText
146-
fileUrl={accountAvatarUrl}
147146
/>
148147
</div>
149148
</SettingsCard>

apps/dashboard/src/app/(app)/team/[team_slug]/(team)/~/settings/general/TeamGeneralSettingsPageUI.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,12 +220,11 @@ function TeamAvatarFormControl(props: {
220220
</div>
221221
<FileInput
222222
accept={{ "image/*": [] }}
223-
value={teamAvatar}
223+
value={teamAvatar || teamAvatarUrl}
224224
setValue={setTeamAvatar}
225225
className="w-20 rounded-full lg:w-28"
226226
disableHelperText
227227
client={props.client}
228-
fileUrl={teamAvatarUrl}
229228
/>
230229
</div>
231230
</SettingsCard>

apps/dashboard/src/app/(app)/team/[team_slug]/[project_slug]/(sidebar)/assets/create/_common/file-preview.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export function FilePreview(props: {
99
fallback?: React.ReactNode;
1010
className?: string;
1111
client: ThirdwebClient;
12+
imgContainerClassName?: string;
1213
}) {
1314
const [objectUrl, setObjectUrl] = useState<string>("");
1415

@@ -31,12 +32,14 @@ export function FilePreview(props: {
3132
const isImage =
3233
props.srcOrFile instanceof File &&
3334
props.srcOrFile.type.startsWith("image/");
35+
3436
if (isImage) {
3537
return (
3638
<Img
3739
src={objectUrl}
3840
className={props.className}
3941
fallback={props.fallback}
42+
containerClassName={props.imgContainerClassName}
4043
/>
4144
);
4245
}

apps/dashboard/src/app/(app)/team/[team_slug]/[project_slug]/(sidebar)/settings/ProjectGeneralSettingsPage.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -505,12 +505,11 @@ function ProjectImageSetting(props: {
505505
</div>
506506
<FileInput
507507
accept={{ "image/*": [] }}
508-
value={projectAvatar}
508+
value={projectAvatar || projectAvatarUrl}
509509
setValue={setProjectAvatar}
510510
client={props.client}
511511
className="w-20 rounded-full lg:w-28"
512512
disableHelperText
513-
fileUrl={projectAvatarUrl}
514513
/>
515514
</div>
516515
</SettingsCard>

apps/dashboard/src/app/pay/components/client/PaymentLinkForm.client.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,6 @@ export function PaymentLinkForm() {
314314
isDisabledText="Uploading..."
315315
selectOrUpload="Upload"
316316
helperText="image"
317-
fileUrl={imageUri}
318317
/>
319318
</div>
320319
</div>

apps/dashboard/src/components/embedded-wallets/Configure/index.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@ function AppImageFormControl(props: {
448448
<FileInput
449449
client={props.client}
450450
accept={{ "image/*": [] }}
451-
value={image}
451+
value={image || resolveUrl}
452452
setValue={async (v) => {
453453
try {
454454
setImage(v);
@@ -463,7 +463,6 @@ function AppImageFormControl(props: {
463463
}}
464464
className="w-24 rounded-full bg-background lg:w-28"
465465
disableHelperText
466-
fileUrl={resolveUrl}
467466
/>
468467

469468
{uploadImage.isPending && (

apps/dashboard/src/components/shared/FileInput.tsx

Lines changed: 10 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@
22
import { Button } from "@/components/ui/button";
33
import { cn } from "@/lib/utils";
44
import { FilePlusIcon, UploadIcon } from "lucide-react";
5-
import { useCallback, useEffect, useMemo, useRef } from "react";
5+
import { useCallback, useEffect, useRef } from "react";
66
import {
77
type Accept,
88
type DropEvent,
99
type FileRejection,
1010
useDropzone,
1111
} from "react-dropzone";
1212
import type { ThirdwebClient } from "thirdweb";
13-
import { MediaRenderer } from "thirdweb/react";
13+
// import { MediaRenderer } from "thirdweb/react";
14+
import { FilePreview } from "../../app/(app)/team/[team_slug]/[project_slug]/(sidebar)/assets/create/_common/file-preview";
1415

1516
interface IFileInputProps {
1617
accept?: Accept;
@@ -27,7 +28,7 @@ interface IFileInputProps {
2728
children?: React.ReactNode;
2829
className?: string;
2930
disableHelperText?: boolean;
30-
fileUrl?: string;
31+
// fileUrl?: string;
3132
client: ThirdwebClient;
3233
}
3334

@@ -46,7 +47,6 @@ export const FileInput: React.FC<IFileInputProps> = ({
4647
previewMaxWidth,
4748
client,
4849
disableHelperText,
49-
fileUrl: fileUrlFallback,
5050
}) => {
5151
const onDrop = useCallback<
5252
<T extends File>(
@@ -67,9 +67,6 @@ export const FileInput: React.FC<IFileInputProps> = ({
6767
accept,
6868
});
6969

70-
const file: File | null =
71-
typeof window !== "undefined" && value instanceof File ? value : null;
72-
7370
const helperTextOrFile = helperText
7471
? helperText
7572
: accept &&
@@ -80,22 +77,6 @@ export const FileInput: React.FC<IFileInputProps> = ({
8077

8178
const createdBlobUrl = useRef<string | null>(null);
8279

83-
const fileBlobUrl = useMemo(() => {
84-
if (!file) {
85-
return undefined;
86-
}
87-
88-
const blobUrl = fileToBlobUrl(file);
89-
// eslint-disable-next-line react-compiler/react-compiler
90-
createdBlobUrl.current = blobUrl;
91-
return blobUrl;
92-
}, [file]);
93-
94-
const fileUrl =
95-
typeof value === "string" ? value : fileBlobUrl || fileUrlFallback;
96-
97-
console.log({ fileUrl, value });
98-
9980
// eslint-disable-next-line no-restricted-syntax
10081
useEffect(() => {
10182
return () => {
@@ -144,17 +125,16 @@ export const FileInput: React.FC<IFileInputProps> = ({
144125
className={cn(
145126
"relative cursor-pointer overflow-hidden",
146127
"flex w-full items-center justify-center border border-border hover:bg-accent hover:ring-2 hover:ring-ring",
147-
// fileUrl ? "bg-transparent" : "bg-card",
128+
value ? "bg-transparent" : "bg-card",
148129
className,
149130
)}
150131
>
151-
{fileUrl ? (
152-
<MediaRenderer
153-
src={fileUrl}
132+
{value ? (
133+
<FilePreview
134+
srcOrFile={value}
154135
client={client}
155-
controls={false}
156-
requireInteraction={false}
157-
className="[&>div]:!bg-muted h-full w-full"
136+
className="h-full w-full"
137+
imgContainerClassName="h-full w-full"
158138
/>
159139
) : (
160140
<div className="flex flex-col items-center gap-2.5 text-muted-foreground">
@@ -184,8 +164,3 @@ export const FileInput: React.FC<IFileInputProps> = ({
184164
</div>
185165
);
186166
};
187-
188-
function fileToBlobUrl(file: File) {
189-
const blob = new Blob([file], { type: file.type });
190-
return URL.createObjectURL(blob);
191-
}

0 commit comments

Comments
 (0)