Skip to content

Commit

Permalink
Added new library features for navigation [#568]
Browse files Browse the repository at this point in the history
Added selectors for publishers, series, characters, teams, locations
and stories.
  • Loading branch information
mcpierce committed Dec 27, 2020
1 parent 3e6594b commit 8b2cdc3
Show file tree
Hide file tree
Showing 9 changed files with 149 additions and 15 deletions.
7 changes: 7 additions & 0 deletions comixed-web/src/app/core/core.functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,10 @@ export function updateQueryParam(
queryParams
});
}

/** Flattens an array of arrays and returns unique elements. */
export function flattened<T>(values: T[][]): T[] {
const result = [];
values.forEach(value => value.forEach(inner => result.push(inner)));
return result.filter((entry, index, self) => self.indexOf(entry) === index);
}
1 change: 1 addition & 0 deletions comixed-web/src/app/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
} from '@app/core/reducers/busy.reducer';

export * from '@app/core/core.constants';
export * from '@app/core/core.functions';
export { SortableListItem } from '@app/core/models/ui/sortable-list-item';
export { TokenService } from '@app/core/services/token.service';
export { AlertService } from '@app/core/services/alert.service';
Expand Down
26 changes: 13 additions & 13 deletions comixed-web/src/app/library/library.fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ export const COMIC_1: Comic = {
issueNumber: '1',
sortableIssueNumber: '00001',
title: 'First Comic Title',
storyArcs: [],
storyArcs: ['story1', 'story2', 'story3'],
description: 'The description of this comic',
notes: '',
missing: false,
Expand All @@ -227,9 +227,9 @@ export const COMIC_1: Comic = {
coverDate: '2019-08-01',
yearPublished: 2019,
pageCount: 32,
characters: [],
teams: [],
locations: [],
characters: ['character1', 'character2', 'character3'],
teams: ['team1'],
locations: ['location1', 'location2'],
pages: [PAGE_1, PAGE_2, PAGE_3, PAGE_4],
blockedPageCount: 0,
deletedPageCount: 0,
Expand All @@ -251,12 +251,12 @@ export const COMIC_2: Comic = {
publisher: 'First Publisher',
imprint: null,
sortName: 'comicfile1',
series: 'First Series',
series: 'Last Series',
volume: '2015',
issueNumber: '2',
sortableIssueNumber: '00001',
title: 'First Comic Title',
storyArcs: [],
storyArcs: ['story1'],
description: 'The description of this comic',
notes: '',
missing: false,
Expand All @@ -268,9 +268,9 @@ export const COMIC_2: Comic = {
coverDate: '2018-08-01',
yearPublished: 2018,
pageCount: 32,
characters: [],
teams: [],
locations: [],
characters: ['character2', 'character3', 'character4'],
teams: ['team2'],
locations: ['location1', 'location2'],
pages: [PAGE_1],
blockedPageCount: 0,
deletedPageCount: 0,
Expand All @@ -297,7 +297,7 @@ export const COMIC_3: Comic = {
issueNumber: '3',
sortableIssueNumber: '00001',
title: 'First Comic Title',
storyArcs: [],
storyArcs: ['story1'],
description: 'The description of this comic',
notes: '',
missing: false,
Expand All @@ -309,9 +309,9 @@ export const COMIC_3: Comic = {
coverDate: '1953-08-01',
yearPublished: 1953,
pageCount: 32,
characters: [],
teams: [],
locations: [],
characters: ['character3', 'character4', 'character5'],
teams: ['team1'],
locations: ['location1', 'location2'],
pages: [PAGE_1],
blockedPageCount: 0,
deletedPageCount: 0,
Expand Down
60 changes: 58 additions & 2 deletions comixed-web/src/app/library/selectors/library.selectors.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,41 @@
import { LIBRARY_FEATURE_KEY, LibraryState } from '../reducers/library.reducer';
import {
selectAllComics,
selectCharacters,
selectComic,
selectLibraryBusy,
selectLibraryState
selectLibraryState,
selectLocations,
selectPublishers,
selectSeries,
selectStories,
selectTeams
} from './library.selectors';
import { COMIC_1, COMIC_2, COMIC_3 } from '@app/library/library.fixtures';

describe('Library Selectors', () => {
const COMIC = COMIC_1;
const COMICS = [COMIC_1, COMIC_2, COMIC_3];
const COMICS = [
COMIC_1,
{ ...COMIC_2, publisher: '' },
{ ...COMIC_3, series: '' }
];
const PUBLISHERS = [
COMIC_1.publisher,
'library.label.no-publisher',
COMIC_3.publisher
];
const SERIES = [COMIC_1.series, COMIC_2.series, 'library.label.no-series'];
const CHARACTERS = [
'character1',
'character2',
'character3',
'character4',
'character5'
];
const TEAMS = ['team1', 'team2'];
const LOCATIONS = ['location1', 'location2'];
const STORIES = ['story1', 'story2', 'story3'];

let state: LibraryState;

Expand Down Expand Up @@ -64,4 +90,34 @@ describe('Library Selectors', () => {
state.comics
);
});

it('selects the publishers', () => {
expect(selectPublishers({ [LIBRARY_FEATURE_KEY]: state })).toEqual(
PUBLISHERS
);
});

it('selects the series', () => {
expect(selectSeries({ [LIBRARY_FEATURE_KEY]: state })).toEqual(SERIES);
});

it('selects the characters', () => {
expect(selectCharacters({ [LIBRARY_FEATURE_KEY]: state })).toEqual(
CHARACTERS
);
});

it('selects the teams', () => {
expect(selectTeams({ [LIBRARY_FEATURE_KEY]: state })).toEqual(TEAMS);
});

it('selects the locations', () => {
expect(selectLocations({ [LIBRARY_FEATURE_KEY]: state })).toEqual(
LOCATIONS
);
});

it('selects the stories', () => {
expect(selectStories({ [LIBRARY_FEATURE_KEY]: state })).toEqual(STORIES);
});
});
46 changes: 46 additions & 0 deletions comixed-web/src/app/library/selectors/library.selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,69 @@

import { createFeatureSelector, createSelector } from '@ngrx/store';
import { LIBRARY_FEATURE_KEY, LibraryState } from '../reducers/library.reducer';
import { flattened } from '@app/core';

/** Selects the feature state. */
export const selectLibraryState = createFeatureSelector<LibraryState>(
LIBRARY_FEATURE_KEY
);

/** Selects the comic. */
export const selectComic = createSelector(
selectLibraryState,
state => state.comic
);

/** Selects if the feature is current busy. */
export const selectLibraryBusy = createSelector(
selectLibraryState,
state => state.loading
);

/** Selects all comics. */
export const selectAllComics = createSelector(
selectLibraryState,
state => state.comics
);

/** Selects the publishers without duplicates. */
export const selectPublishers = createSelector(selectAllComics, comics =>
comics
.map(comic =>
!!comic.publisher && comic.publisher.length > 0
? comic.publisher
: 'library.label.no-publisher'
)
.filter((publisher, index, self) => self.indexOf(publisher) === index)
);

/** Selects the series without duplicates. */
export const selectSeries = createSelector(selectAllComics, comics =>
comics
.map(comic =>
!!comic.series && comic.series.length > 0
? comic.series
: 'library.label.no-series'
)
.filter((series, index, self) => self.indexOf(series) === index)
);

/** Selects the characters without duplicates. */
export const selectCharacters = createSelector(selectAllComics, comics =>
flattened(comics.map(comic => comic.characters))
);

/** Selects the teams without duplicates. */
export const selectTeams = createSelector(selectAllComics, comics =>
flattened(comics.map(comic => comic.teams))
);

/** Selects the locations without duplicates. */
export const selectLocations = createSelector(selectAllComics, comics =>
flattened(comics.map(comic => comic.locations))
);

/** Selects the stories without duplicates. */
export const selectStories = createSelector(selectAllComics, comics =>
flattened(comics.map(comic => comic.storyArcs))
);
6 changes: 6 additions & 0 deletions comixed-web/src/assets/i18n/en/library.json
Original file line number Diff line number Diff line change
Expand Up @@ -139,5 +139,11 @@
"reject-scraping-issue": "Reject this issue.",
"select-scraping-issue": "Select this issue."
}
},
"library": {
"label": {
"no-publisher": "Unknown Publisher",
"no-series": "Unknown Series"
}
}
}
6 changes: 6 additions & 0 deletions comixed-web/src/assets/i18n/es/library.json
Original file line number Diff line number Diff line change
Expand Up @@ -139,5 +139,11 @@
"reject-scraping-issue": "Reject this issue.",
"select-scraping-issue": "Select this issue."
}
},
"library": {
"label": {
"no-publisher": "Unknown Publisher",
"no-series": "Unknown Series"
}
}
}
6 changes: 6 additions & 0 deletions comixed-web/src/assets/i18n/fr/library.json
Original file line number Diff line number Diff line change
Expand Up @@ -139,5 +139,11 @@
"reject-scraping-issue": "Reject this issue.",
"select-scraping-issue": "Select this issue."
}
},
"library": {
"label": {
"no-publisher": "Unknown Publisher",
"no-series": "Unknown Series"
}
}
}
6 changes: 6 additions & 0 deletions comixed-web/src/assets/i18n/pt/library.json
Original file line number Diff line number Diff line change
Expand Up @@ -139,5 +139,11 @@
"reject-scraping-issue": "Reject this issue.",
"select-scraping-issue": "Select this issue."
}
},
"library": {
"label": {
"no-publisher": "Unknown Publisher",
"no-series": "Unknown Series"
}
}
}

0 comments on commit 8b2cdc3

Please sign in to comment.