rename cards in preparation for future changes

This commit is contained in:
Jason Wall 2020-08-19 11:01:15 -04:00
parent b37eed2781
commit f2353a5627
5 changed files with 43 additions and 43 deletions

View File

@ -11,7 +11,7 @@ export interface AppState {
readonly displaySettings: IStorable<DisplaySettings>;
readonly pageSettings: IStorable<PageSettings>;
readonly savedPagesLoaded: boolean;
readonly cards: readonly CardItem[];
readonly currentCards: readonly CardItem[];
readonly autocomplete: readonly string[];
readonly error: Error;
readonly cardIcons: CardIcons;

View File

@ -17,7 +17,7 @@ import { CardItem, CardType } from 'src/app/models/card-state';
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class SearchPage extends SubscriberBase implements OnInit {
cards$ = this.appService.select((state) => state.cards);
cards$ = this.appService.select((state) => state.currentCards);
suggestions$ = this.appService.select((state) => state.autocomplete);
savedPagedLoaded = false;

View File

@ -3,7 +3,7 @@ import { Overlap } from '../common/bible-reference';
export const initialState: AppState = {
user: null,
cards: [],
currentCards: [],
autocomplete: [],
currentSavedPage: null,
savedPages: null,

View File

@ -29,7 +29,7 @@ describe('getNewestStorable', () => {
describe('AppService Reducer', () => {
const preState = {
user: null,
cards: [],
currentCards: [],
autocomplete: [],
currentSavedPage: {
queries: [],
@ -231,7 +231,7 @@ describe('AppService Reducer', () => {
const action1 = AppActionFactory.newAddCard(card1, null);
const testState = reducer(preState, action1);
expect(testState.cards[0]).toBe(card1, 'Failed to add first card to empty list');
expect(testState.currentCards[0]).toBe(card1, 'Failed to add first card to empty list');
const action = AppActionFactory.newUpdateCurrentPage();
const testState2 = reducer(testState, action);
@ -261,7 +261,7 @@ describe('AppService Reducer', () => {
const action1 = AppActionFactory.newAddCard(card1, null);
const testState = reducer(preState, action1);
expect(testState.cards[0]).toBe(card1, 'Failed to add first card to empty list');
expect(testState.currentCards[0]).toBe(card1, 'Failed to add first card to empty list');
const card2: CardItem = {
qry: 'G123',
@ -271,8 +271,8 @@ describe('AppService Reducer', () => {
const action2 = AppActionFactory.newAddCard(card2, null);
const testState2 = reducer(testState, action2);
expect(testState2.cards.length).toBe(2, 'Failed to add second card to list with 1 item');
expect(testState2.cards[1]).toBe(card2);
expect(testState2.currentCards.length).toBe(2, 'Failed to add second card to list with 1 item');
expect(testState2.currentCards[1]).toBe(card2);
const card3: CardItem = {
qry: 'G1234',
@ -304,8 +304,8 @@ describe('AppService Reducer', () => {
const action3 = AppActionFactory.newAddCard(card3, card2);
const testState3 = reducer(setState, action3);
expect(testState3.cards.length).toBe(3, 'Failed to add third card');
expect(testState3.cards[1]).toBe(card3, 'Failed to insert card above the second card');
expect(testState3.currentCards.length).toBe(3, 'Failed to add third card');
expect(testState3.currentCards[1]).toBe(card3, 'Failed to insert card above the second card');
// append to bottom, insert next to card
@ -331,8 +331,8 @@ describe('AppService Reducer', () => {
const action4 = AppActionFactory.newAddCard(card3, card1);
const testState4 = reducer(setState, action4);
expect(testState4.cards.length).toBe(3, 'Failed to add third card');
expect(testState4.cards[1]).toBe(card3, 'Failed to insert card below the first card');
expect(testState4.currentCards.length).toBe(3, 'Failed to add third card');
expect(testState4.currentCards[1]).toBe(card3, 'Failed to insert card below the first card');
// append to bottom, do not insert next to card
@ -358,8 +358,8 @@ describe('AppService Reducer', () => {
const action5 = AppActionFactory.newAddCard(card3, card1);
const testState5 = reducer(setState, action5);
expect(testState5.cards.length).toBe(3, 'Failed to add third card');
expect(testState5.cards[2]).toBe(card3, 'Failed to insert card at end of the list');
expect(testState5.currentCards.length).toBe(3, 'Failed to add third card');
expect(testState5.currentCards[2]).toBe(card3, 'Failed to insert card at end of the list');
// append to top, do not insert next to card
@ -385,8 +385,8 @@ describe('AppService Reducer', () => {
const action6 = AppActionFactory.newAddCard(card3, card1);
const testState6 = reducer(setState, action6);
expect(testState6.cards.length).toBe(3, 'Failed to add third card');
expect(testState6.cards[0]).toBe(card3, 'Failed to insert card at start of the list');
expect(testState6.currentCards.length).toBe(3, 'Failed to add third card');
expect(testState6.currentCards[0]).toBe(card3, 'Failed to insert card at start of the list');
});
// 'UPDATE_CARD';

View File

@ -126,7 +126,7 @@ export function reducer(state: AppState, action: AppAction): AppState {
...state,
// if the currentSavedPage was loaded, replace it with the info from the
// new savedPages array, as it might have changed.
cards: hasCurrentSavedPage ? currentSavedPage.queries : state.cards,
currentCards: hasCurrentSavedPage ? currentSavedPage.queries : state.currentCards,
currentSavedPage: hasCurrentSavedPage ? currentSavedPage : state.currentSavedPage,
savedPagesLoaded: true,
savedPages, // update the savedPages
@ -159,7 +159,7 @@ export function reducer(state: AppState, action: AppAction): AppState {
const current = {
id: state.currentSavedPage.id,
title: state.currentSavedPage.title,
queries: [...mergeCardList(state.cards, state.pageSettings.value.mergeStrategy)],
queries: [...mergeCardList(state.currentCards, state.pageSettings.value.mergeStrategy)],
};
const savedPages = new Storable<SavedPage[]>([
@ -182,7 +182,7 @@ export function reducer(state: AppState, action: AppAction): AppState {
// create a new saved page object
title: action.title,
id: UUID.UUID().toString(),
queries: [...mergeCardList(state.cards, state.pageSettings.value.mergeStrategy)],
queries: [...mergeCardList(state.currentCards, state.pageSettings.value.mergeStrategy)],
},
]);
@ -201,7 +201,7 @@ export function reducer(state: AppState, action: AppAction): AppState {
return {
...state,
currentSavedPage: page,
cards: [...page.queries],
currentCards: [...page.queries],
};
}
case 'MOVE_SAVED_PAGE_CARD': {
@ -246,33 +246,33 @@ export function reducer(state: AppState, action: AppAction): AppState {
let cards = [];
if (action.nextToItem && state.displaySettings.value.insertCardNextToItem) {
const idx = state.cards.indexOf(action.nextToItem);
const idx = state.currentCards.indexOf(action.nextToItem);
if (state.displaySettings.value.appendCardToBottom) {
const before = state.cards.slice(0, idx + 1);
const after = state.cards.slice(idx + 1);
const before = state.currentCards.slice(0, idx + 1);
const after = state.currentCards.slice(idx + 1);
cards = [...before, action.card, ...after];
} else {
const before = state.cards.slice(0, idx);
const after = state.cards.slice(idx);
const before = state.currentCards.slice(0, idx);
const after = state.currentCards.slice(idx);
cards = [...before, action.card, ...after];
}
} else {
if (state.displaySettings.value.appendCardToBottom) {
cards = [...state.cards, action.card];
cards = [...state.currentCards, action.card];
} else {
cards = [action.card, ...state.cards];
cards = [action.card, ...state.currentCards];
}
}
return {
...state,
cards,
currentCards: cards,
};
}
case 'UPDATE_CARD': {
return {
...state,
cards: state.cards.map((c) => {
currentCards: state.currentCards.map((c) => {
if (c === action.oldCard) {
return action.newCard;
}
@ -306,15 +306,15 @@ export function reducer(state: AppState, action: AppAction): AppState {
...state,
currentSavedPage,
savedPages,
cards: [...state.cards.filter((c) => c !== action.card)],
currentCards: [...state.currentCards.filter((c) => c !== action.card)],
};
}
case 'MOVE_CARD': {
const cards = moveItemUpOrDown(state.cards, action.card, action.direction);
const cards = moveItemUpOrDown(state.currentCards, action.card, action.direction);
return {
...state,
cards,
currentCards: cards,
};
}
@ -343,27 +343,27 @@ export function reducer(state: AppState, action: AppAction): AppState {
let cards = [] as CardItem[];
if (action.nextToItem && state.displaySettings.value.insertCardNextToItem) {
const idx = state.cards.indexOf(action.nextToItem);
const idx = state.currentCards.indexOf(action.nextToItem);
if (state.displaySettings.value.appendCardToBottom) {
const before = state.cards.slice(0, idx + 1);
const after = state.cards.slice(idx + 1);
const before = state.currentCards.slice(0, idx + 1);
const after = state.currentCards.slice(idx + 1);
cards = [...before, ...notes, ...after];
} else {
const before = state.cards.slice(0, idx);
const after = state.cards.slice(idx);
const before = state.currentCards.slice(0, idx);
const after = state.currentCards.slice(idx);
cards = [...before, ...notes, ...after];
}
} else {
if (state.displaySettings.value.appendCardToBottom) {
cards = [...state.cards, ...notes];
cards = [...state.currentCards, ...notes];
} else {
cards = [...notes, ...state.cards];
cards = [...notes, ...state.currentCards];
}
}
return {
...state,
cards,
currentCards: cards,
};
}
case 'GET_NOTE': {
@ -396,7 +396,7 @@ export function reducer(state: AppState, action: AppAction): AppState {
// in any of them, swap it out
const cards = [
...state.cards.map((o) => {
...state.currentCards.map((o) => {
const n = o.data as NoteItem;
if (n && n.id === action.note.id) {
return {
@ -447,7 +447,7 @@ export function reducer(state: AppState, action: AppAction): AppState {
// in any of them, remove it
const cards = [
...state.cards.filter((o) => {
...state.currentCards.filter((o) => {
const n = o.data as NoteItem;
return !n || n.id !== action.note.id;
}),
@ -468,7 +468,7 @@ export function reducer(state: AppState, action: AppAction): AppState {
]);
return {
...state,
cards,
currentCards: cards,
notes,
savedPages,
};