Skip to content

Commit

Permalink
feat: upload panel fixes (#388)
Browse files Browse the repository at this point in the history
  • Loading branch information
dariaterekhova-actionengine authored Dec 5, 2024
1 parent c34bd18 commit 7e74986
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
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

0 comments on commit 7e74986

Please sign in to comment.