-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfiles.tsx
43 lines (36 loc) · 1.38 KB
/
files.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import { useEffect } from "react";
import { List, showToast, Detail } from "@raycast/api";
import { usePromise } from "@raycast/utils";
import { IFile } from "@putdotio/api-client";
import { withPutioClient } from "./api/withPutioClient";
import { fetchFiles } from "./api/files";
import { FileListItem } from "./components/FileListItem";
import { localizeError, localizedErrorToToastOptions } from "./api/localizeError";
import { EmptyView } from "./components/EmptyView";
export const Files = ({ id = 0, name = "Your Files" }: { id?: IFile["id"]; name?: IFile["name"] }) => {
const { isLoading, data, error, revalidate } = usePromise(fetchFiles, [id]);
useEffect(() => {
if (error) {
showToast(localizedErrorToToastOptions(localizeError(error)));
}
}, [error]);
if (!data) {
return <List isLoading={isLoading} navigationTitle={name} />;
}
switch (data.parent.file_type) {
case "FOLDER":
return (
<List navigationTitle={name} searchBarPlaceholder={`Search in ${name}`}>
<EmptyView title={data.files.length === 0 ? "This folder is empty" : name} />
{data.files.map((file) => (
<FileListItem key={file.id} file={file} onMutate={revalidate} />
))}
</List>
);
default:
return <Detail markdown={data.parent.name} />;
}
};
export default function Command() {
return withPutioClient(<Files />);
}