fix/lexicographically order libraries in library service (#3193)
This commit is contained in:
@@ -70,7 +70,11 @@ export class LibraryService {
|
|||||||
|
|
||||||
private fetchLibraries(): Observable<Library[]> {
|
private fetchLibraries(): Observable<Library[]> {
|
||||||
return this.http.get<Library[]>(this.url).pipe(
|
return this.http.get<Library[]>(this.url).pipe(
|
||||||
tap(libs => this.libraryStateSubject.next({libraries: libs, loaded: true, error: null})),
|
tap(libs => this.libraryStateSubject.next({
|
||||||
|
libraries: this.sortLibraries(libs),
|
||||||
|
loaded: true,
|
||||||
|
error: null,
|
||||||
|
})),
|
||||||
catchError(err => {
|
catchError(err => {
|
||||||
const current = this.libraryStateSubject.value;
|
const current = this.libraryStateSubject.value;
|
||||||
this.libraryStateSubject.next({libraries: current.libraries, loaded: true, error: err.message});
|
this.libraryStateSubject.next({libraries: current.libraries, loaded: true, error: err.message});
|
||||||
@@ -88,7 +92,7 @@ export class LibraryService {
|
|||||||
map(created => {
|
map(created => {
|
||||||
const curr = this.libraryStateSubject.value;
|
const curr = this.libraryStateSubject.value;
|
||||||
const updated = curr.libraries ? [...curr.libraries, created] : [created];
|
const updated = curr.libraries ? [...curr.libraries, created] : [created];
|
||||||
this.libraryStateSubject.next({...curr, libraries: updated});
|
this.libraryStateSubject.next({...curr, libraries: this.sortLibraries(updated)});
|
||||||
return created;
|
return created;
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
@@ -99,7 +103,7 @@ export class LibraryService {
|
|||||||
map(updated => {
|
map(updated => {
|
||||||
const curr = this.libraryStateSubject.value;
|
const curr = this.libraryStateSubject.value;
|
||||||
const list = curr.libraries?.map(l => (l.id === updated.id ? updated : l)) || [updated];
|
const list = curr.libraries?.map(l => (l.id === updated.id ? updated : l)) || [updated];
|
||||||
this.libraryStateSubject.next({...curr, libraries: list});
|
this.libraryStateSubject.next({...curr, libraries: this.sortLibraries(list)});
|
||||||
this.bookService.refreshBooks();
|
this.bookService.refreshBooks();
|
||||||
return updated;
|
return updated;
|
||||||
})
|
})
|
||||||
@@ -139,7 +143,7 @@ export class LibraryService {
|
|||||||
map(updated => {
|
map(updated => {
|
||||||
const curr = this.libraryStateSubject.value;
|
const curr = this.libraryStateSubject.value;
|
||||||
const list = curr.libraries?.map(l => (l.id === updated.id ? updated : l)) || [updated];
|
const list = curr.libraries?.map(l => (l.id === updated.id ? updated : l)) || [updated];
|
||||||
this.libraryStateSubject.next({...curr, libraries: list});
|
this.libraryStateSubject.next({...curr, libraries: this.sortLibraries(list)});
|
||||||
return updated;
|
return updated;
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
@@ -170,4 +174,8 @@ export class LibraryService {
|
|||||||
getBookCountsByFormat(libraryId: number): Observable<Record<string, number>> {
|
getBookCountsByFormat(libraryId: number): Observable<Record<string, number>> {
|
||||||
return this.http.get<Record<string, number>>(`${this.url}/${libraryId}/format-counts`);
|
return this.http.get<Record<string, number>>(`${this.url}/${libraryId}/format-counts`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private sortLibraries(libraries: Library[]): Library[] {
|
||||||
|
return [...libraries].sort((a, b) => a.name.localeCompare(b.name));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user