From 766c0bc1b4a75f8146a922cb2eca8871032c1dc9 Mon Sep 17 00:00:00 2001 From: Ethan Lanting Date: Mon, 24 Feb 2025 20:17:49 -0600 Subject: [PATCH] fix: import schedule file upload button (#515) * fix: add active scale style and accept file prop * chore: improve type safety using MIMEType * fix: update FileUpload component to support multiple MIME types in accept prop * chore: run lint --------- Co-authored-by: doprz <52579214+doprz@users.noreply.github.com> --- src/shared/types/MIMEType.ts | 5 +++++ src/views/components/common/FileUpload.tsx | 16 ++++++++++++++-- src/views/components/settings/Settings.tsx | 8 +++++++- 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/src/shared/types/MIMEType.ts b/src/shared/types/MIMEType.ts index 09c1bcb7..01597bbd 100644 --- a/src/shared/types/MIMEType.ts +++ b/src/shared/types/MIMEType.ts @@ -17,4 +17,9 @@ const MIMEType = { */ export type MIMETypeKey = keyof typeof MIMEType; +/** + * Represents a value of the MIMEType object + */ +export type MIMETypeValue = (typeof MIMEType)[MIMETypeKey]; + export default MIMEType; diff --git a/src/views/components/common/FileUpload.tsx b/src/views/components/common/FileUpload.tsx index d2c1f88d..045f0c00 100644 --- a/src/views/components/common/FileUpload.tsx +++ b/src/views/components/common/FileUpload.tsx @@ -1,4 +1,5 @@ import type { Icon, IconProps } from '@phosphor-icons/react'; +import type { MIMETypeValue } from '@shared/types/MIMEType'; import type { ThemeColor } from '@shared/types/ThemeColors'; import { getThemeColorHexByName, getThemeColorRgbByName } from '@shared/util/themeColors'; import Text from '@views/components/common/Text/Text'; @@ -16,6 +17,7 @@ interface Props { disabled?: boolean; title?: string; color: ThemeColor; + accept?: MIMETypeValue | MIMETypeValue[]; } /** @@ -34,6 +36,7 @@ export default function FileUpload({ disabled, title, color, + accept, children, }: React.PropsWithChildren): JSX.Element { const Icon = icon; @@ -41,6 +44,9 @@ export default function FileUpload({ const colorHex = getThemeColorHexByName(color); const colorRgb = getThemeColorRgbByName(color)?.join(' '); + // Convert accept to a comma-separated string if it's an array + const acceptValue = Array.isArray(accept) ? accept.join(',') : accept; + return ( ); } diff --git a/src/views/components/settings/Settings.tsx b/src/views/components/settings/Settings.tsx index d045ba71..be835112 100644 --- a/src/views/components/settings/Settings.tsx +++ b/src/views/components/settings/Settings.tsx @@ -7,6 +7,7 @@ import { CalendarDots, Trash } from '@phosphor-icons/react'; import { background } from '@shared/messages'; import { initSettings, OptionsStore } from '@shared/storage/OptionsStore'; import { UserScheduleStore } from '@shared/storage/UserScheduleStore'; +import MIMEType from '@shared/types/MIMEType'; import { downloadBlob } from '@shared/util/downloadBlob'; // import { addCourseByUrl } from '@shared/util/courseUtils'; // import { getCourseColors } from '@shared/util/colors'; @@ -397,7 +398,12 @@ export default function Settings(): JSX.Element {

Import from a schedule file

- + Import Schedule