Skip to content

Commit

Permalink
Added a new scan type feature [#465]
Browse files Browse the repository at this point in the history
 * Removed the old feature code and adaptor methods.
 * Refactored ComicOverview to use the new feature.
  • Loading branch information
mcpierce committed Oct 12, 2020
1 parent 3164241 commit 5df13b2
Show file tree
Hide file tree
Showing 22 changed files with 703 additions and 304 deletions.
26 changes: 1 addition & 25 deletions comixed-frontend/src/app/comics/actions/comic.actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,9 @@
*/

import { Action } from '@ngrx/store';
import { Comic, ComicFormat, Page, PageType, ScanType } from 'app/comics';
import { Comic, ComicFormat, Page, PageType } from 'app/comics';

export enum ComicActionTypes {
GetScanTypes = '[COMIC] Get the set of scan types',
GotScanTypes = '[COMIC] Got the scan types',
GetScanTypesFailed = '[COMIC] Failed to get the set of scan types',
GetFormats = '[COMIC] Get the set of formats',
GotFormats = '[COMIC] Got the set of formats',
GetFormatsFailed = '[COMIC] Failed to get the set of formats',
Expand Down Expand Up @@ -61,24 +58,6 @@ export enum ComicActionTypes {
MarkAsReadFailed = '[COMIC] Changing the read state of a comic failed'
}

export class ComicGetScanTypes implements Action {
readonly type = ComicActionTypes.GetScanTypes;

constructor() {}
}

export class ComicGotScanTypes implements Action {
readonly type = ComicActionTypes.GotScanTypes;

constructor(public payload: { scanTypes: ScanType[] }) {}
}

export class ComicGetScanTypesFailed implements Action {
readonly type = ComicActionTypes.GetScanTypesFailed;

constructor() {}
}

export class ComicGetFormats implements Action {
readonly type = ComicActionTypes.GetFormats;

Expand Down Expand Up @@ -296,9 +275,6 @@ export class ComicMarkAsReadFailed implements Action {
}

export type ComicActions =
| ComicGetScanTypes
| ComicGotScanTypes
| ComicGetScanTypesFailed
| ComicGetFormats
| ComicGotFormats
| ComicGetFormatsFailed
Expand Down
33 changes: 33 additions & 0 deletions comixed-frontend/src/app/comics/actions/scan-types.actions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* ComiXed - A digital comic book library management application.
* Copyright (C) 2020, The ComiXed Project
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses>
*/

import { createAction, props } from '@ngrx/store';
import { ScanType } from 'app/comics';

export const getScanTypes = createAction(
'[Scan Types] Get the list of scan types'
);

export const scanTypesReceived = createAction(
'[Scan Types] Scan types received',
props<{ types: ScanType[] }>()
);

export const getScanTypesFailed = createAction(
'[Scan Types] Get scan types failed'
);
39 changes: 0 additions & 39 deletions comixed-frontend/src/app/comics/adaptors/comic.adaptor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,9 @@ import {
ComicGetIssue,
ComicGetIssueFailed,
ComicGetPageTypes,
ComicGetScanTypes,
ComicGotFormats,
ComicGotIssue,
ComicGotPageTypes,
ComicGotScanTypes,
ComicMarkAsRead,
ComicMarkAsReadFailed,
ComicMarkedAsRead,
Expand All @@ -59,19 +57,13 @@ import {
} from 'app/comics/models/comic-format.fixtures';
import { COMIC_1 } from 'app/comics/models/comic.fixtures';
import { FRONT_COVER } from 'app/comics/models/page-type.fixtures';
import {
SCAN_TYPE_1,
SCAN_TYPE_3,
SCAN_TYPE_5
} from 'app/comics/models/scan-type.fixtures';
import * as fromComics from 'app/comics/reducers/comic.reducer';
import { MessageService } from 'primeng/api';
import { ComicAdaptor } from './comic.adaptor';
import { LoggerModule } from '@angular-ru/logger';
import { COMIC_1_LAST_READ_DATE } from 'app/library/models/last-read-date.fixtures';

describe('ComicAdaptor', () => {
const SCAN_TYPES = [SCAN_TYPE_1, SCAN_TYPE_3, SCAN_TYPE_5];
const FORMATS = [FORMAT_1, FORMAT_3, FORMAT_5];
const COMIC = COMIC_1;
const SKIP_CACHE = false;
Expand Down Expand Up @@ -108,37 +100,6 @@ describe('ComicAdaptor', () => {
expect(adaptor).toBeTruthy();
});

describe('loading scan types', () => {
it('can load the scan types', () => {
adaptor.getScanTypes();
expect(store.dispatch).toHaveBeenCalledWith(new ComicGetScanTypes());
});

it('only retrieves the scan types once', () => {
store.dispatch(new ComicGotScanTypes({ scanTypes: SCAN_TYPES }));
adaptor.getScanTypes();
expect(store.dispatch).not.toHaveBeenCalledWith(new ComicGetScanTypes());
});

describe('when the scan types are received', () => {
beforeEach(() => {
store.dispatch(new ComicGotScanTypes({ scanTypes: SCAN_TYPES }));
});

it('provides notice when the scan types are loaded', () => {
adaptor.scanTypesLoaded$.subscribe(result =>
expect(result).toBeTruthy()
);
});

it('provides notice when the scan types are changed', () => {
adaptor.scanTypes$.subscribe(result =>
expect(result).toEqual(SCAN_TYPES)
);
});
});
});

describe('loading the comic formats', () => {
it('can load the comic formats', () => {
adaptor.getFormats();
Expand Down
33 changes: 1 addition & 32 deletions comixed-frontend/src/app/comics/adaptors/comic.adaptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,13 @@

import { Injectable } from '@angular/core';
import { Store } from '@ngrx/store';
import {
AppState,
Comic,
ComicFormat,
Page,
PageType,
ScanType
} from 'app/comics';
import { AppState, Comic, ComicFormat, Page, PageType } from 'app/comics';
import {
ComicClearMetadata,
ComicDelete,
ComicGetFormats,
ComicGetIssue,
ComicGetPageTypes,
ComicGetScanTypes,
ComicMarkAsRead,
ComicRestore,
ComicSave,
Expand All @@ -52,8 +44,6 @@ import { LoggerService } from '@angular-ru/logger';

@Injectable()
export class ComicAdaptor {
private _scanTypesLoaded$ = new BehaviorSubject<boolean>(false);
private _scanTypes$ = new BehaviorSubject<ScanType[]>([]);
private _formatsLoaded$ = new BehaviorSubject<boolean>(false);
private _formats$ = new BehaviorSubject<ComicFormat[]>([]);
private _fetchingIssue$ = new BehaviorSubject<boolean>(false);
Expand All @@ -74,12 +64,6 @@ export class ComicAdaptor {
.pipe(filter(state => !!state))
.subscribe((state: ComicState) => {
this.logger.debug('comic state updated:', state);
if (state.scanTypesLoaded !== this._scanTypesLoaded$.getValue()) {
this._scanTypesLoaded$.next(state.scanTypesLoaded);
}
if (!_.isEqual(this._scanTypes$.getValue(), state.scanTypes)) {
this._scanTypes$.next(state.scanTypes);
}
if (state.formatsLoaded !== this._formatsLoaded$.getValue()) {
this._formatsLoaded$.next(state.formatsLoaded);
}
Expand Down Expand Up @@ -122,21 +106,6 @@ export class ComicAdaptor {
});
}

getScanTypes(): void {
this.logger.debug('firing action to get scan types');
if (this._scanTypesLoaded$.getValue() === false) {
this.store.dispatch(new ComicGetScanTypes());
}
}

get scanTypesLoaded$(): Observable<boolean> {
return this._scanTypesLoaded$.asObservable();
}

get scanTypes$(): Observable<ScanType[]> {
return this._scanTypes$.asObservable();
}

getFormats(): void {
this.logger.debug('firing action to get formats');
if (this._formatsLoaded$.getValue() === false) {
Expand Down
2 changes: 1 addition & 1 deletion comixed-frontend/src/app/comics/comics.constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import { API_ROOT_URL } from 'app/app.functions';
import { COMIXED_API_ROOT } from 'app/app.constants';

export const GET_SCAN_TYPES_URL = `${API_ROOT_URL}/comics/scan_types`;
export const GET_SCAN_TYPES_URL = `${API_ROOT_URL}/comics/scantypes`;
export const GET_FORMATS_URL = `${API_ROOT_URL}/comics/formats`;
export const GET_PAGE_TYPES_URL = `${API_ROOT_URL}/pages/types`;
export const GET_COMIC_URL = `${API_ROOT_URL}/comics/\${id}`;
Expand Down
8 changes: 7 additions & 1 deletion comixed-frontend/src/app/comics/comics.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ import {
import { TableModule } from 'primeng/table';
import { ScrapingIssueCoverUrlPipe } from 'app/comics/pipes/scraping-issue-cover-url.pipe';
import * as fromComics from 'app/comics/reducers/comic.reducer';
import { COMIC_FEATURE_KEY } from 'app/comics/reducers/comic.reducer';
import { PublisherThumbnailUrlPipe } from 'app/comics/pipes/publisher-thumbnail-url.pipe';
import { PublisherPipe } from 'app/comics/pipes/publisher.pipe';
import { SeriesCollectionNamePipe } from 'app/comics/pipes/series-collection-name.pipe';
Expand All @@ -87,6 +88,9 @@ import { SCRAPE_COMIC_FEATURE_KEY } from 'app/comics/reducers/scrape-comic.reduc
import { ScrapeComicEffects } from 'app/comics/effects/scrape-comic.effects';
import * as fromScrapeMultipleComics from 'app/comics/reducers/scrape-multiple-comic.reducer';
import { SCRAPE_MULTIPLE_COMICS_STATE } from 'app/comics/reducers/scrape-multiple-comic.reducer';
import * as fromScanTypes from 'app/comics/reducers/scan-types.reducer';
import { SCAN_TYPES_FEATURE_KEY } from 'app/comics/reducers/scan-types.reducer';
import { ScanTypesEffects } from 'app/comics/effects/scan-types.effects';

@NgModule({
declarations: [
Expand Down Expand Up @@ -130,7 +134,8 @@ import { SCRAPE_MULTIPLE_COMICS_STATE } from 'app/comics/reducers/scrape-multipl
TableModule,
TabViewModule,
TranslateModule.forRoot(),
StoreModule.forFeature(fromComics.COMIC_FEATURE_KEY, fromComics.reducer),
StoreModule.forFeature(COMIC_FEATURE_KEY, fromComics.reducer),
StoreModule.forFeature(SCAN_TYPES_FEATURE_KEY, fromScanTypes.reducer),
StoreModule.forFeature(
SCRAPING_VOLUMES_FEATURE_KEY,
fromScrapingVolumes.reducer
Expand All @@ -146,6 +151,7 @@ import { SCRAPE_MULTIPLE_COMICS_STATE } from 'app/comics/reducers/scrape-multipl
),
EffectsModule.forFeature([
ComicEffects,
ScanTypesEffects,
ScrapingVolumesEffects,
ScrapingIssueEffects,
ScrapeComicEffects
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ import { TranslateModule } from '@ngx-translate/core';
import { ComicAdaptor } from 'app/comics/adaptors/comic.adaptor';
import { COMIC_1, FORMAT_3, SCAN_TYPE_1 } from 'app/comics/comics.fixtures';
import { ComicEffects } from 'app/comics/effects/comic.effects';
import { COMIC_FEATURE_KEY, reducer } from 'app/comics/reducers/comic.reducer';
import * as fromComic from 'app/comics/reducers/comic.reducer';
import { COMIC_FEATURE_KEY } from 'app/comics/reducers/comic.reducer';
import { AppState, LibraryAdaptor } from 'app/library';
import { LoggerModule } from '@angular-ru/logger';
import { Confirmation, ConfirmationService, MessageService } from 'primeng/api';
Expand All @@ -48,6 +49,10 @@ import { CollectionType } from 'app/library/models/collection-type.enum';
import { SeriesCollectionNamePipe } from 'app/comics/pipes/series-collection-name.pipe';
import { FileEntryListComponent } from 'app/comics/components/file-entry-list/file-entry-list.component';
import { TableModule } from 'primeng/table';
import { scanTypesReceived } from 'app/comics/actions/scan-types.actions';
import * as fromScanTypes from 'app/comics/reducers/scan-types.reducer';
import { SCAN_TYPES_FEATURE_KEY } from 'app/comics/reducers/scan-types.reducer';
import { ScanTypesEffects } from 'app/comics/effects/scan-types.effects';

describe('ComicOverviewComponent', () => {
const COMIC = Object.assign({}, COMIC_1);
Expand All @@ -66,9 +71,10 @@ describe('ComicOverviewComponent', () => {
LoggerModule.forRoot(),
HttpClientTestingModule,
StoreModule.forRoot({}),
StoreModule.forFeature(COMIC_FEATURE_KEY, reducer),
StoreModule.forFeature(COMIC_FEATURE_KEY, fromComic.reducer),
StoreModule.forFeature(SCAN_TYPES_FEATURE_KEY, fromScanTypes.reducer),
EffectsModule.forRoot([]),
EffectsModule.forFeature([ComicEffects]),
EffectsModule.forFeature([ComicEffects, ScanTypesEffects]),
FormsModule,
RouterTestingModule,
TranslateModule.forRoot(),
Expand Down Expand Up @@ -119,11 +125,22 @@ describe('ComicOverviewComponent', () => {
expect(component).toBeTruthy();
});

it('subscribes to the available scan types list', () => {
component.scanTypes = [SCAN_TYPE_1];
component.loadScanTypeOptions();
expect(component.scanTypeOptions.length).toEqual(2);
expect(component.scanTypeOptions[1].value).toEqual(SCAN_TYPE_1);
describe('the available scan types list', () => {
const SCAN_TYPES = [SCAN_TYPE_1];

beforeEach(() => {
component.scanTypes = [];
component.scanTypeOptions = [];
store.dispatch(scanTypesReceived({ types: SCAN_TYPES }));
});

it('loads the set of scan type options', () => {
expect(component.scanTypeOptions).not.toEqual([]);
});

it('sets the scan types reference', () => {
expect(component.scanTypes).toEqual(SCAN_TYPES);
});
});

it('subscribes to the available format list', () => {
Expand Down

0 comments on commit 5df13b2

Please sign in to comment.