-export const loadCollection = (uuid: string, kind: ResourceKind) =>
- (dispatch: Dispatch) => {
- dispatch(collectionPanelActions.LOAD_COLLECTION({ uuid, kind }));
- dispatch(collectionPanelFilesAction.SET_COLLECTION_FILES({ files: createTree() }));
- return collectionService
- .get(uuid)
- .then(item => {
- dispatch(collectionPanelActions.LOAD_COLLECTION_SUCCESS({ item }));
- return collectionFilesService.getFiles(item.uuid);
- })
- .then(files => {
- dispatch(collectionPanelFilesAction.SET_COLLECTION_FILES({ files }));
- });
+export const loadCollectionPanel = (uuid: string, forceReload = false) =>
+ async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
+ const { collectionPanel: { item } } = getState();
+ let collection: CollectionResource | null = null;
+ if (!item || item.uuid !== uuid || forceReload) {
+ try {
+ dispatch(progressIndicatorActions.START_WORKING(uuid + "-panel"));
+ collection = await services.collectionService.get(uuid);
+ dispatch(collectionPanelActions.SET_COLLECTION(collection));
+ dispatch(resourcesActions.SET_RESOURCES([collection]));
+ } finally {
+ dispatch(progressIndicatorActions.STOP_WORKING(uuid + "-panel"));
+ }
+ } else {
+ collection = item;
+ }
+ dispatch<any>(loadDetailsPanel(collection.uuid));
+ return collection;