Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: upload panel fixes #388

Merged
merged 4 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/components/bookmarks-panel/bookmarks-panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -284,9 +284,11 @@ export const BookmarksPanel = ({
onEditBookmarks={onEditBookmarksClickHandler}
onClearBookmarks={onClearBookmarksClickHandler}
onUploadBookmarks={() => {
setPopoverType(
bookmarks.length ? PopoverType.uploadWarning : PopoverType.upload
);
setTimeout(() => {
setPopoverType(
bookmarks.length ? PopoverType.uploadWarning : PopoverType.upload
);
}, 1);
}}
onDownloadBookmarks={onDownloadBookmarks}
onCollapsed={onCollapsed}
Expand Down
3 changes: 2 additions & 1 deletion src/components/layers-panel/insert-panel/insert-panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,9 @@ export const InsertPanel = ({
onChange={handleInputChange}
/>
<UploadPanel
dragAndDropText={"Drag and drop your SLPK file here"}
dragAndDropText={"Drag and drop your .slpk file here"}
noPadding={true}
accept=".slpk"
onFileEvent={(files) => { handleInputChange({ target: { files, name: "URL" } }); }}
fileType={FileType.binary}
/>
Expand Down
12 changes: 11 additions & 1 deletion src/components/upload-panel/upload-panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ const FileTextItem = styled.div`

const DragAndDropFileText = styled(FileTextItem)`
color: ${({ theme }) => theme.colors.fontColor};
`;

const UploadedFileText = styled(FileTextItem)`
color: ${({ theme }) => theme.colors.fontColor};
word-break: break-all;
`;

Expand All @@ -62,6 +66,7 @@ interface UploadProps {
fileType: FileType;
multipleFiles?: boolean;
noPadding?: boolean;
accept?: string;
onCancel?: () => void;
onFileUploaded?: (fileUploaded: FileUploaded) => Promise<void> | void;
onFileEvent?: (files: FileList) => void;
Expand All @@ -73,6 +78,7 @@ export const UploadPanel = ({
fileType,
multipleFiles,
noPadding,
accept,
onCancel,
onFileUploaded,
onFileEvent,
Expand Down Expand Up @@ -117,6 +123,9 @@ export const UploadPanel = ({
e.stopPropagation();
setDragActive(false);
if (e.dataTransfer.files?.[0]) {
if (accept && !e.dataTransfer.files?.[0].name.endsWith(accept)) {
return;
}
setFileUploaded(e.dataTransfer.files[0].name);
onFileEvent?.(e.dataTransfer.files);
readFile(e.dataTransfer.files).catch(() => {
Expand Down Expand Up @@ -146,6 +155,7 @@ export const UploadPanel = ({
type="file"
multiple={multipleFiles ?? undefined}
onChange={onUploadChangeHandler}
accept={accept}
/>
<FileInteractionContainer
data-testid="upload-file-label"
Expand Down Expand Up @@ -176,7 +186,7 @@ export const UploadPanel = ({
{fileUploaded && (
<>
<UploadIcon style={{ marginBottom: "10" }} />
<DragAndDropFileText>{fileUploaded}</DragAndDropFileText>
<UploadedFileText>{fileUploaded}</UploadedFileText>
</>
)}
</FileInteractionContainer>
Expand Down
Loading