Skip to content

Commit

Permalink
Merge pull request #1047 from internxt/bugfix/PB-1767-items-not-displ…
Browse files Browse the repository at this point in the history
…ay-correctly

[PB-1767]:  bugfix/Files/folders are not displayed
  • Loading branch information
CandelR authored Mar 5, 2024
2 parents 9c9bb11 + dd234d1 commit 112fca8
Show file tree
Hide file tree
Showing 10 changed files with 58 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,18 @@ const CreateFolderDialog = ({ onFolderCreated, currentFolderId, neededFolderId }
const createFolder = async () => {
if (folderName && folderName.trim().length > 0) {
setIsLoading(true);
const parentFolderId = currentFolderId ?? neededFolderId;
await dispatch(
storageThunks.createFolderThunk({
folderName,
parentFolderId: currentFolderId ? currentFolderId : neededFolderId,
parentFolderId,
}),
)
.unwrap()
.then(() => {
onFolderCreated && onFolderCreated();
dispatch(storageActions.setHasMoreDriveFolders(true));
dispatch(storageActions.setHasMoreDriveFiles(true));
dispatch(storageActions.setHasMoreDriveFolders({ folderId: parentFolderId, status: true }));
dispatch(storageActions.setHasMoreDriveFiles({ folderId: parentFolderId, status: true }));
setTimeout(() => {
dispatch(fetchSortedFolderContentThunk(currentFolderId));
setIsLoading(false);
Expand All @@ -72,7 +73,7 @@ const CreateFolderDialog = ({ onFolderCreated, currentFolderId, neededFolderId }
return e;
});
} else {
setError(translate('error.folderCannotBeEmpty') as string);
setError(translate('error.folderCannotBeEmpty'));
}
};

Expand All @@ -92,9 +93,9 @@ const CreateFolderDialog = ({ onFolderCreated, currentFolderId, neededFolderId }
<Input
disabled={isLoading}
className={`${error !== '' ? 'error' : ''}`}
label={translate('modals.newFolderModal.label') as string}
value={folderName as string}
placeholder={translate('modals.newFolderModal.placeholder') as string}
label={translate('modals.newFolderModal.label')}
value={folderName}
placeholder={translate('modals.newFolderModal.placeholder')}
onChange={(name) => {
setFolderName(name);
setError('');
Expand Down
9 changes: 6 additions & 3 deletions src/app/drive/components/DriveExplorer/DriveExplorer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ const DriveExplorer = (props: DriveExplorerProps): JSX.Element => {
const [hasMoreItems, setHasMoreItems] = useState<boolean>(true);
const [hasMoreTrashFolders, setHasMoreTrashFolders] = useState<boolean>(true);
const [isLoadingTrashItems, setIsLoadingTrashItems] = useState(false);
const hasMoreItemsToLoad = isTrash ? hasMoreItems : hasMoreFiles || hasMoreFolders;

// RIGHT CLICK MENU STATES
const [isListElementsHovered, setIsListElementsHovered] = useState<boolean>(false);
Expand Down Expand Up @@ -822,7 +823,7 @@ const DriveExplorer = (props: DriveExplorerProps): JSX.Element => {
items={items}
isLoading={isTrash ? isLoadingTrashItems : isLoading}
onEndOfScroll={fetchItems}
hasMoreItems={hasMoreItems}
hasMoreItems={hasMoreItemsToLoad}
isTrash={isTrash}
onHoverListItems={(areHovered) => {
setIsListElementsHovered(areHovered);
Expand Down Expand Up @@ -1045,6 +1046,8 @@ const dropTargetCollect: DropTargetCollector<

export default connect((state: RootState) => {
const currentFolderId: number = storageSelectors.currentFolderId(state);
const hasMoreFolders = state.storage.hasMoreDriveFolders[currentFolderId] ?? true;
const hasMoreFiles = state.storage.hasMoreDriveFiles[currentFolderId] ?? true;

return {
isAuthenticated: state.user.isAuthenticated,
Expand All @@ -1063,7 +1066,7 @@ export default connect((state: RootState) => {
planUsage: state.plan.planUsage,
folderOnTrashLength: state.storage.folderOnTrashLength,
filesOnTrashLength: state.storage.filesOnTrashLength,
hasMoreFolders: state.storage.hasMoreDriveFolders,
hasMoreFiles: state.storage.hasMoreDriveFiles,
hasMoreFolders,
hasMoreFiles,
};
})(DropTarget([NativeTypes.FILE], dropTargetSpec, dropTargetCollect)(DriveExplorer));
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,25 @@ const createDriveListItem = (item: DriveItemData, isTrash?: boolean) => (
<DriveExplorerListItem item={item} isTrash={isTrash} />
);

const resetDriveOrder = ({
dispatch,
orderType,
direction,
currentFolderId,
}: {
dispatch;
orderType: string;
direction: string;
currentFolderId: number;
}) => {
dispatch(storageActions.setDriveItemsSort(orderType));
dispatch(storageActions.setDriveItemsOrder(direction));

dispatch(storageActions.setHasMoreDriveFolders({ folderId: currentFolderId, status: true }));
dispatch(storageActions.setHasMoreDriveFiles({ folderId: currentFolderId, status: true }));
dispatch(fetchSortedFolderContentThunk(currentFolderId));
};

const DriveExplorerList: React.FC<DriveExplorerListProps> = memo((props) => {
const [isAllSelectedEnabled, setIsAllSelectedEnabled] = useState(false);
const [editNameItem, setEditNameItem] = useState<DriveItemData | null>(null);
Expand Down Expand Up @@ -143,21 +162,11 @@ const DriveExplorerList: React.FC<DriveExplorerListProps> = memo((props) => {
dispatch(storageActions.setOrder({ by: value.field, direction }));

if (value.field === 'name') {
dispatch(storageActions.setDriveItemsSort('plainName'));
dispatch(storageActions.setDriveItemsOrder(direction));

dispatch(storageActions.setHasMoreDriveFolders(true));
dispatch(storageActions.setHasMoreDriveFiles(true));
dispatch(fetchSortedFolderContentThunk(currentFolderId));
resetDriveOrder({ dispatch, orderType: 'plainName', direction, currentFolderId });
}

if (value.field === 'updatedAt') {
dispatch(storageActions.setDriveItemsSort('updatedAt'));
dispatch(storageActions.setDriveItemsOrder(direction));

dispatch(storageActions.setHasMoreDriveFolders(true));
dispatch(storageActions.setHasMoreDriveFiles(true));
dispatch(fetchSortedFolderContentThunk(currentFolderId));
resetDriveOrder({ dispatch, orderType: 'updatedAt', direction, currentFolderId });
}
};

Expand Down
2 changes: 1 addition & 1 deletion src/app/drive/views/DriveView/DriveView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ export default connect((state: RootState) => {

return {
namePath: state.storage.namePath,
isLoading: state.storage.loadingFolders[currentFolderId],
isLoading: state.storage.loadingFolders[currentFolderId] ?? true,
currentFolderId,
items: sortedItems,
};
Expand Down
17 changes: 8 additions & 9 deletions src/app/store/slices/storage/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import selectors from './storage.selectors';
import { storageExtraReducers } from '../storage/storage.thunks';
import { filtersFactory, orderFactory, StorageSetFiltersPayload, StorageState } from './storage.model';
import databaseService, { DatabaseCollection } from '../../../database/services/database.service';
import itemsListService from '../../../drive/services/items-list.service';
import { OrderDirection, OrderSettings } from '../../../core/types';
import { DriveItemData, DriveItemPatch, FileViewMode, FolderPath } from '../../../drive/types';
import { ShareLink } from '@internxt/sdk/dist/drive/share/types';
Expand All @@ -18,8 +17,8 @@ const initialState: StorageState = {
moveDialogLevels: {},
levelsFoldersLength: {},
levelsFilesLength: {},
hasMoreDriveFolders: true,
hasMoreDriveFiles: true,
hasMoreDriveFolders: {},
hasMoreDriveFiles: {},
recents: [],
isLoadingRecents: false,
isLoadingDeleted: false,
Expand Down Expand Up @@ -109,15 +108,15 @@ export const storageSlice = createSlice({
state.levelsFilesLength[action.payload.folderId] = 0;
state.levels[action.payload.folderId] = [];
},
setHasMoreDriveFolders: (state: StorageState, action: PayloadAction<boolean>) => {
state.hasMoreDriveFolders = action.payload;
setHasMoreDriveFolders: (state: StorageState, action: PayloadAction<{ folderId: number; status: boolean }>) => {
state.hasMoreDriveFolders[action.payload.folderId] = action.payload.status;
},
setHasMoreDriveFiles: (state: StorageState, action: PayloadAction<boolean>) => {
state.hasMoreDriveFiles = action.payload;
setHasMoreDriveFiles: (state: StorageState, action: PayloadAction<{ folderId: number; status: boolean }>) => {
state.hasMoreDriveFiles[action.payload.folderId] = action.payload.status;
},
resetDrivePagination: (state: StorageState) => {
state.hasMoreDriveFiles = true;
state.hasMoreDriveFolders = true;
state.hasMoreDriveFolders[state.currentPath.id] = true;
state.hasMoreDriveFiles[state.currentPath.id] = true;
},
setRecents: (state: StorageState, action: PayloadAction<DriveItemData[]>) => {
state.recents = action.payload;
Expand Down
4 changes: 2 additions & 2 deletions src/app/store/slices/storage/storage.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ export interface StorageState {
moveDialogLevels: Record<number, DriveItemData[]>;
levelsFoldersLength: Record<number, number>;
levelsFilesLength: Record<number, number>;
hasMoreDriveFolders: boolean;
hasMoreDriveFiles: boolean;
hasMoreDriveFolders: Record<number, boolean>;
hasMoreDriveFiles: Record<number, boolean>;
recents: DriveItemData[];
isLoadingRecents: boolean;
isLoadingDeleted: boolean;
Expand Down
4 changes: 2 additions & 2 deletions src/app/store/slices/storage/storage.selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ const storageSelectors = {
return this.levelItems(state)(currentFolderId);
},
hasMoreFiles(state: RootState): boolean {
return state.storage.hasMoreDriveFiles;
return state.storage.hasMoreDriveFiles[state.storage.currentPath.id];
},
hasMoreFolders(state: RootState): boolean {
return state.storage.hasMoreDriveFolders;
return state.storage.hasMoreDriveFolders[state.storage.currentPath.id];
},
levelItems(state: RootState): (folderId: number) => DriveItemData[] {
return (folderId) => state.storage.levels[folderId] || [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ export const fetchPaginatedFolderContentThunk = createAsyncThunk<void, number, {
'storage/fetchFolderContent',
async (folderId, { getState, dispatch }) => {
const storageState = getState().storage;
const hasMoreDriveFolders = storageState.hasMoreDriveFolders;
const hasMoreDriveFiles = storageState.hasMoreDriveFiles;
const hasMoreDriveFolders = storageState.hasMoreDriveFolders[folderId] ?? true;
const hasMoreDriveFiles = storageState.hasMoreDriveFiles[folderId] ?? true;

const foldersOffset = (storageState.levels[folderId] ?? []).filter(filterFolderItems).length;
const filesOffset = (storageState.levels[folderId] ?? []).filter(filterFilesItems).length;
const driveItemsSort = storageState.driveItemsSort;
Expand Down Expand Up @@ -63,10 +64,10 @@ export const fetchPaginatedFolderContentThunk = createAsyncThunk<void, number, {
dispatch(storageActions.addItems({ folderId, items: parsedItems }));

if (hasMoreDriveFolders) {
dispatch(storageActions.setHasMoreDriveFolders(!areLastItems));
dispatch(storageActions.setHasMoreDriveFolders({ folderId, status: !areLastItems }));
dispatch(storageActions.addFolderFoldersLength({ folderId, foldersLength: itemslength }));
} else {
dispatch(storageActions.setHasMoreDriveFiles(!areLastItems));
dispatch(storageActions.setHasMoreDriveFiles({ folderId, status: !areLastItems }));
dispatch(storageActions.addFolderFilesLength({ folderId, filesLength: itemslength }));
}
} catch (error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ const DEFAULT_LIMIT = 50;
export const fetchSortedFolderContentThunk = createAsyncThunk<void, number, { state: RootState }>(
'storage/fetchSortedFolderContentThunk',
async (folderId, { getState, dispatch }) => {
dispatch(storageActions.setHasMoreDriveFolders(true));
dispatch(storageActions.setHasMoreDriveFiles(true));
dispatch(storageActions.setHasMoreDriveFolders({ folderId, status: true }));
dispatch(storageActions.setHasMoreDriveFiles({ folderId, status: true }));

const storageState = getState().storage;
const hasMoreDriveFolders = storageState.hasMoreDriveFolders;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ export const goToFolderThunk = createAsyncThunk<void, FolderPath, { state: RootS
// no need to go to the same folder
return;
}

dispatch(storageActions.setHasMoreDriveFolders({ folderId: path.id, status: true }));
dispatch(storageActions.setHasMoreDriveFiles({ folderId: path.id, status: true }));
dispatch(storageActions.clearCurrentThumbnailItems({ folderId: path.id }));
const isInNamePath: boolean = storageSelectors.isFolderInNamePath(getState())(path.id);

Expand Down

0 comments on commit 112fca8

Please sign in to comment.