Skip to content
This repository was archived by the owner on May 3, 2025. It is now read-only.

Commit 9d9c6ea

Browse files
Feature: Use updated FileUploader from evergreen (#102)
* Bump evergreen to 6.9.0 * Port over multiple upload FileUploader implementation from evergreen docs * Bump collation to 0.7.1 * Begin building out custom FileCard * Swap FileListItem component with FileCard, wire up delete + dialog * Add 'Flex' row/column components * Break out useTimeoutRender hook for getting around react-query issue, re-implement file upload * Properly handle API call per file + loading state for upload button * Reinstate border in Input style * Remove old FileUpload and FileListItem components * Break out wrapper <IconButton /> for larger spinner when loading
1 parent 6b5da45 commit 9d9c6ea

File tree

13 files changed

+560
-542
lines changed

13 files changed

+560
-542
lines changed

package-lock.json

Lines changed: 148 additions & 279 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@
1414
"dependencies": {
1515
"@octokit/rest": "18.12.0",
1616
"@supabase/supabase-js": "1.24.0",
17-
"evergreen-ui": "6.7.1",
17+
"evergreen-ui": "6.9.0",
1818
"glamor": "2.20.40",
19+
"humanize-plus": "1.8.2",
1920
"immutable": "4.0.0",
2021
"jotai": "1.5.2",
2122
"keymirror": "0.1.1",
@@ -45,6 +46,7 @@
4546
"@testing-library/user-event": "12.8.3",
4647
"@types/chalk": "2.2.0",
4748
"@types/dotenv": "8.2.0",
49+
"@types/humanize-plus": "1.8.0",
4850
"@types/jest": "26.0.24",
4951
"@types/keymirror": "0.1.1",
5052
"@types/lodash": "4.14.172",
@@ -58,7 +60,7 @@
5860
"@types/react-router-dom": "5.1.8",
5961
"@types/uuid": "8.3.1",
6062
"chalk": "4.1.2",
61-
"collation": "0.7.0",
63+
"collation": "0.7.1",
6264
"dotenv": "10.0.0",
6365
"husky": "7.0.4",
6466
"node-pg-migrate": "6.0.0",

src/components/files/file-card.tsx

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
import {
2+
majorScale,
3+
MusicIcon,
4+
Pane,
5+
FileCardProps as EvergreenFileCardProps,
6+
Paragraph,
7+
TrashIcon,
8+
CogIcon,
9+
minorScale,
10+
} from "evergreen-ui";
11+
import { useTheme } from "utils/hooks/use-theme";
12+
import humanize from "humanize-plus";
13+
import { useDeleteFile } from "utils/hooks/domain/files/use-delete-file";
14+
import { FileRecord } from "models/file-record";
15+
import { StorageProviderFileRecord } from "models/storage-provider-file-record";
16+
import { useCallback } from "react";
17+
import { useBoolean } from "utils/hooks/use-boolean";
18+
import { FileDialog } from "components/files/file-dialog";
19+
import { Flex } from "components/flex";
20+
import { IconButton } from "components/icon-button";
21+
22+
interface FileCardProps
23+
extends Omit<EvergreenFileCardProps, "name" | "type" | "sizeInBytes"> {
24+
file: FileRecord;
25+
storageProviderFile: StorageProviderFileRecord;
26+
}
27+
28+
const FileCard: React.FC<FileCardProps> = (props: FileCardProps) => {
29+
const { file, storageProviderFile } = props;
30+
const {
31+
value: isOpen,
32+
setTrue: handleOpenDialog,
33+
setFalse: handleCloseDialog,
34+
} = useBoolean(false);
35+
const { mutate, isLoading } = useDeleteFile();
36+
const handleDelete = useCallback(() => mutate(file.id), [file.id, mutate]);
37+
const { colors } = useTheme();
38+
const { name, size } = file;
39+
return (
40+
<Flex.Row
41+
alignItems="center"
42+
border={true}
43+
borderColor={colors.gray400}
44+
borderRadius={minorScale(1)}
45+
height={majorScale(8)}
46+
justifyContent="space-between"
47+
marginBottom={majorScale(2)}
48+
marginRight={majorScale(2)}
49+
maxWidth={majorScale(40)}
50+
width="100%">
51+
<Flex.Row justifyContent="flex-start">
52+
<Flex.Row alignItems="center">
53+
<Pane
54+
marginLeft={majorScale(2)}
55+
marginRight={majorScale(1)}>
56+
<Flex.Row
57+
alignItems="center"
58+
backgroundColor={colors.gray90}
59+
borderRadius={minorScale(1)}
60+
height={majorScale(5)}
61+
justifyContent="center"
62+
width={majorScale(5)}>
63+
<MusicIcon color={colors.gray600} />
64+
</Flex.Row>
65+
</Pane>
66+
</Flex.Row>
67+
<Flex.Column overflow="hidden">
68+
<Paragraph
69+
color={colors.gray800}
70+
overflow="hidden"
71+
textOverflow="ellipsis"
72+
whiteSpace="nowrap">
73+
{name}
74+
</Paragraph>
75+
{size != null && (
76+
<Paragraph color={colors.gray700} size={300}>
77+
{humanize.fileSize(size, 0)}
78+
</Paragraph>
79+
)}
80+
</Flex.Column>
81+
</Flex.Row>
82+
<Flex.Row justifyContent="flex-end">
83+
<IconButton
84+
appearance="minimal"
85+
color={colors.gray600}
86+
disabled={isLoading}
87+
icon={CogIcon}
88+
marginLeft="auto"
89+
onClick={handleOpenDialog}
90+
type="button"
91+
/>
92+
<IconButton
93+
appearance="minimal"
94+
color={colors.gray600}
95+
icon={TrashIcon}
96+
isLoading={isLoading}
97+
marginLeft="auto"
98+
marginRight={majorScale(2)}
99+
onClick={handleDelete}
100+
type="button"
101+
/>
102+
</Flex.Row>
103+
{isOpen && (
104+
<FileDialog
105+
file={file}
106+
isShown={isOpen}
107+
onCloseComplete={handleCloseDialog}
108+
storageProviderFile={storageProviderFile}
109+
/>
110+
)}
111+
</Flex.Row>
112+
);
113+
};
114+
115+
export { FileCard };

src/components/files/file-list-item.tsx

Lines changed: 0 additions & 90 deletions
This file was deleted.

src/components/files/file-list.tsx

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
import { BucketName } from "enums/bucket-name";
22
import { SortOrder } from "enums/sort-order";
3-
import { Pane } from "evergreen-ui";
43
import { useListStorageProviderFiles } from "utils/hooks/supabase/use-list-storage-provider-files";
5-
import { FileListItem } from "components/files/file-list-item";
64
import { useGlobalState } from "utils/hooks/use-global-state";
75
import { groupBy } from "utils/collection-utils";
86
import { useListFiles } from "generated/hooks/domain/files/use-list-files";
7+
import { FileCard } from "components/files/file-card";
8+
import { Flex } from "components/flex";
9+
import { useTimeoutRender } from "utils/hooks/use-timeout-render";
10+
import { Spinner } from "evergreen-ui";
11+
import React from "react";
912

1013
interface FileListProps {
1114
bucketName: BucketName;
@@ -14,33 +17,42 @@ interface FileListProps {
1417
const FileList: React.FC<FileListProps> = (props: FileListProps) => {
1518
const { bucketName } = props;
1619
const { globalState } = useGlobalState();
17-
const { resultObject: storageProviderFiles } = useListStorageProviderFiles({
20+
const {
21+
resultObject: storageProviderFiles,
22+
isLoading: isLoadingStorageProviderFiles,
23+
} = useListStorageProviderFiles({
1824
bucketName,
1925
path: globalState.userId(),
2026
sortBy: {
2127
column: "created_at",
2228
order: SortOrder.DESC,
2329
},
2430
});
25-
26-
const { resultObject: files } = useListFiles();
31+
const { resultObject: files, isLoading: isLoadingFiles } = useListFiles();
32+
useTimeoutRender();
2733

2834
const groupedFiles = groupBy(
2935
storageProviderFiles,
3036
files,
3137
(a, b) => a.id === b.id
3238
);
39+
const isLoading = isLoadingFiles || isLoadingStorageProviderFiles;
3340

3441
return (
35-
<Pane>
36-
{groupedFiles.map(({ left: storageProviderFile, right: file }) => (
37-
<FileListItem
38-
file={file}
39-
key={file.id}
40-
storageProviderFile={storageProviderFile}
41-
/>
42-
))}
43-
</Pane>
42+
<Flex.Column>
43+
<Flex.Row flexWrap="wrap" width="100%">
44+
{isLoading && <Spinner />}
45+
{groupedFiles.map(
46+
({ left: storageProviderFile, right: file }) => (
47+
<FileCard
48+
file={file}
49+
key={file.id}
50+
storageProviderFile={storageProviderFile}
51+
/>
52+
)
53+
)}
54+
</Flex.Row>
55+
</Flex.Column>
4456
);
4557
};
4658

0 commit comments

Comments
 (0)