Skip to content

Commit

Permalink
fix(FileOrganizer): fixed bug that skipped setting thumbnail size
Browse files Browse the repository at this point in the history
  • Loading branch information
liamross committed Nov 24, 2020
1 parent 953a352 commit c25d758
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
8 changes: 7 additions & 1 deletion src/components/FileOrganizer/FileOrganizer.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,13 @@ const Template: FC<TemplateProps> = ({
customSizedThumbnail,
}) => {
// This is the index organizing function.
const [files, setFiles] = useState<FakeFile[]>([]);
const [files, setFiles] = useState<FakeFile[]>(() => {
const newFiles = [];
for (let index = 0; index < numFiles; index++) {
newFiles.push(createFile(index));
}
return newFiles;
});
const handleOnMove = useCallback<NonNullable<FileOrganizerProps<FakeFile>['onMove']>>((fromIndex, toIndex) => {
setFiles((prev) => {
if (toIndex < 0 || toIndex >= prev.length) return prev;
Expand Down
4 changes: 2 additions & 2 deletions src/components/FileOrganizer/FileOrganizer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,8 @@ export function FileOrganizer<F extends ObjectWithId>({

// Update size when getWidth ref changes (when hasFiles changes).
useEffect(() => {
if (thumbnailSize) setSize(thumbnailSize);
if (files.length === 0) setSize(defaultSize);
if (thumbnailSize) return setSize(thumbnailSize);
if (files.length === 0) return setSize(defaultSize);
setSize((prev) => {
const { width, height } = getSize();
if (prev.width === width && prev.height === height) return prev;
Expand Down

0 comments on commit c25d758

Please sign in to comment.