Cache redesign part 1, and add support for alternative links

This commit is contained in:
Art Lowel
2020-12-11 14:18:44 +01:00
parent f4853972cc
commit 4e18fa35ca
522 changed files with 7537 additions and 6933 deletions

View File

@@ -2,7 +2,7 @@ import { Injectable } from '@angular/core';
import { createSelector, Store } from '@ngrx/store';
import { combineLatest as observableCombineLatest } from 'rxjs/internal/observable/combineLatest';
import { Observable, of as observableOf } from 'rxjs';
import { map, switchMap } from 'rxjs/operators';
import { map, switchMap, filter } from 'rxjs/operators';
import { AppState } from '../app.reducer';
import { CommunityDataService } from '../core/data/community-data.service';
import { FindListOptions } from '../core/data/request.models';
@@ -11,12 +11,13 @@ import { Collection } from '../core/shared/collection.model';
import { PageInfo } from '../core/shared/page-info.model';
import { hasValue, isNotEmpty } from '../shared/empty.util';
import { RemoteData } from '../core/data/remote-data';
import { PaginatedList } from '../core/data/paginated-list';
import { PaginatedList, buildPaginatedList } from '../core/data/paginated-list.model';
import { CollectionDataService } from '../core/data/collection-data.service';
import { CommunityListSaveAction } from './community-list.actions';
import { CommunityListState } from './community-list.reducer';
import { getCommunityPageRoute } from '../+community-page/community-page-routing-paths';
import { getCollectionPageRoute } from '../+collection-page/collection-page-routing-paths';
import { getFirstSucceededRemoteData, getFirstCompletedRemoteData } from '../core/shared/operators';
/**
* Each node in the tree is represented by a flatNode which contains info about the node itself and its position and
@@ -46,7 +47,8 @@ export class ShowMoreFlatNode {
// Helper method to combine an flatten an array of observables of flatNode arrays
export const combineAndFlatten = (obsList: Array<Observable<FlatNode[]>>): Observable<FlatNode[]> =>
observableCombineLatest(...obsList).pipe(
map((matrix: any[][]) => [].concat(...matrix))
map((matrix: any[][]) => [].concat(...matrix)),
filter((arr: any[]) => arr.every((e) => hasValue(e))),
);
/**
@@ -144,10 +146,13 @@ export class CommunityListService {
if (coms && coms.length > 0) {
newPageInfo = Object.assign({}, coms[0].pageInfo, { currentPage })
}
return new PaginatedList(newPageInfo, newPage);
return buildPaginatedList(newPageInfo, newPage);
})
);
return topComs$.pipe(switchMap((topComs: PaginatedList<Community>) => this.transformListOfCommunities(topComs, 0, null, expandedNodes)));
return topComs$.pipe(
switchMap((topComs: PaginatedList<Community>) => this.transformListOfCommunities(topComs, 0, null, expandedNodes)),
// distinctUntilChanged((a: FlatNode[], b: FlatNode[]) => a.length === b.length)
);
};
/**
@@ -162,6 +167,7 @@ export class CommunityListService {
direction: options.sort.direction
}
}).pipe(
getFirstSucceededRemoteData(),
map((results) => results.payload),
);
}
@@ -227,11 +233,12 @@ export class CommunityListService {
currentPage: i
})
.pipe(
getFirstCompletedRemoteData(),
switchMap((rd: RemoteData<PaginatedList<Community>>) => {
if (hasValue(rd) && hasValue(rd.payload)) {
return this.transformListOfCommunities(rd.payload, level + 1, communityFlatNode, expandedNodes);
} else {
return [];
return observableOf([]);
}
})
);
@@ -249,6 +256,7 @@ export class CommunityListService {
currentPage: i
})
.pipe(
getFirstCompletedRemoteData(),
map((rd: RemoteData<PaginatedList<Collection>>) => {
if (hasValue(rd) && hasValue(rd.payload)) {
let nodes = rd.payload.page