Skip to content
This repository was archived by the owner on Nov 28, 2024. It is now read-only.

Commit f22d564

Browse files
author
Weidows
committed
update supported file type
1 parent 7b13803 commit f22d564

3 files changed

Lines changed: 23 additions & 23 deletions

File tree

react-app/src/components/FileCard/index.tsx

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,32 +13,32 @@ import styles from "./index.module.css";
1313
import { humanizeFileSize } from "utils/humanize";
1414

1515
import Tooltip from "components/Tooltip/index";
16+
import { TableCellsIcon } from "@heroicons/react/24/solid";
1617

1718
// TODO: how to download? by open a link in browser
1819
// or as background job?
1920

20-
export type ValidFileType = ".txt" | ".pdf" | ".doc" | ".docx" | ".md";
21-
export type TabIDs = "reports-review" | "study-abroad-planning";
21+
export enum ValidFileTypeEnum {
22+
TXT = ".txt",
23+
PDF = ".pdf",
24+
DOC = ".doc",
25+
DOCX = ".docx",
26+
MD = ".md",
27+
XLS = ".xls",
28+
}
29+
export type ValidFileType = keyof ValidFileTypeEnum;
30+
2231
export enum TabIDsEnum {
2332
ReportsReview = "reports-review",
2433
StudyAbroadPlanning = "study-abroad-planning",
2534
}
2635

27-
export function GetValidFileTypeList() {
28-
return [".txt", ".pdf", ".doc", ".docx", ".md"];
29-
}
30-
export function IsValidFileType(ext: string) {
31-
if (!ext) return false;
32-
ext = ext.toLowerCase();
33-
return GetValidFileTypeList().includes(ext);
34-
}
35-
3636
export interface FileCardCommonProps {
3737
tab: TabIDsEnum;
3838

3939
className?: string;
4040

41-
filetype: ValidFileType;
41+
filetype: ValidFileTypeEnum;
4242
filesize: number;
4343
filename: string;
4444
uploadProgress: number; // percentage, i.e. 0 - 1
@@ -287,15 +287,16 @@ export function DocumentIcon({
287287
type,
288288
classNames,
289289
}: {
290-
type: ValidFileType;
290+
type: ValidFileTypeEnum;
291291
classNames?: string;
292292
}) {
293-
const mappings: Record<ValidFileType, ReactElement> = {
293+
const mappings: Record<ValidFileTypeEnum, ReactElement> = {
294294
".txt": <TxtIcon className={classNames} />,
295295
".pdf": <PdfIcon className={classNames} />,
296296
".doc": <DocIcon className={classNames} />,
297297
".docx": <DocIcon className={classNames} />,
298-
".md": <DocIcon className={classNames} />,
298+
".md": <TxtIcon className={classNames} />,
299+
".xls": <TableCellsIcon className={classNames} />,
299300
};
300301

301302
return mappings[type];

react-app/src/pages/home/index.tsx

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,18 @@ import {
2323
DocumentIcon,
2424
FileCard,
2525
FileCardProps,
26-
IsValidFileType,
2726
TabIDsEnum,
28-
ValidFileType,
27+
ValidFileTypeEnum
2928
} from "components/FileCard/index";
3029
import { Variants, motion } from "framer-motion";
3130
import { useQueryItem } from "hooks/useQueryItem";
3231
import { useNavigate, useParams, useSearchParams } from "react-router-dom";
3332
import { classNames, modulize } from "utils/classNames";
3433
import { humanizeFileSize } from "utils/humanize";
3534

35+
import { GetFileReview } from "@/api/review";
3636
import { AxiosProgressEvent } from "axios";
3737
import { historyFiles, settingsGroups } from "./static-conf";
38-
import { GetFileReview } from "@/api/review";
3938

4039
type DialogIDs = "notifications" | "help" | "settings" | "search" | null;
4140
type WorkspaceIDs = "workspace" | "file-management";
@@ -152,11 +151,11 @@ const Home = () => {
152151
// 处理文件拖拽/点击上传后的操作
153152
const processFile = (file: File) => {
154153
const ext = path.extname(file.name);
155-
if (!IsValidFileType(ext)) return;
154+
if (!(ext.slice(1).toUpperCase() in ValidFileTypeEnum)) return;
156155

157156
let fileProps: FileCardProps = {
158157
tab: currentTab,
159-
filetype: ext as ValidFileType,
158+
filetype: ext as ValidFileTypeEnum,
160159
filename: file.name,
161160
filesize: file.size,
162161
uploadProgress: 0,
@@ -199,7 +198,7 @@ const Home = () => {
199198
webkitRelativePath: "";
200199
}
201200
*/
202-
console.log(fileProps);
201+
// console.log(fileProps);
203202

204203
GetFileReview(payload, updateProgress)
205204
.then((response) => {

react-app/src/pages/home/static-conf.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import { ValidFileType } from "@/components/FileCard";
1+
import { ValidFileTypeEnum } from "@/components/FileCard";
22
import { BriefcaseIcon, Cog8ToothIcon, UserIcon, UsersIcon } from "@heroicons/react/24/outline"
33
import { People } from "@privata/types/people"
44
import { ReactNode } from "react"
55

66
interface File {
77
filename: string;
8-
ext: ValidFileType;
8+
ext: ValidFileTypeEnum;
99
size: number; // number of bytes
1010
date: number;
1111
chatId: number;

0 commit comments

Comments
 (0)