diff --git a/src/actions.ts b/src/actions.ts index eae924d4..94cf45a4 100644 --- a/src/actions.ts +++ b/src/actions.ts @@ -86,6 +86,9 @@ export const UPDATE_COLLECTION = 'UPDATE_COLLECTION'; export const UPDATE_RENDER_OFFSET = 'UPDATE_RENDER_OFFSET'; export const UPDATE_COLLECTION_SHAPSHOT = 'UPDATE_COLLECTION_SHAPSHOT'; export const RANDOMIZE_SALT = 'RANDOMIZE_SALT'; +export const SELECT_CARDS = 'SELECT_CARDS'; +export const UNSELECT_CARDS = 'UNSELECT_CARDS'; +export const CLEAR_SELECTED_CARDS = 'CLEAR_SELECTED_CARDS'; //Comments export const COMMENTS_UPDATE_THREADS = 'COMMENTS_UPDATE_THREADS'; export const COMMENTS_UPDATE_MESSAGES = 'COMMENTS_UPDATE_MESSAGES'; @@ -371,6 +374,20 @@ type ActionRandomizeSalt = { type: typeof RANDOMIZE_SALT }; +type ActionSelectCards = { + type: typeof SELECT_CARDS, + cards: CardID[] +}; + +type ActionUnselectCards = { + type: typeof UNSELECT_CARDS, + cards: CardID[] +}; + +type ActionClearSelectedCards = { + type: typeof CLEAR_SELECTED_CARDS +}; + type ActionCommentsUpdateThreads = { type: typeof COMMENTS_UPDATE_THREADS, threads: CommentThreads @@ -974,6 +991,9 @@ export type SomeAction = ActionAIRequestStarted | ActionUpdateRenderOffset | ActionUpdateCollectionSnapshot | ActionRandomizeSalt + | ActionSelectCards + | ActionUnselectCards + | ActionClearSelectedCards | ActionCommentsUpdateThreads | ActionCommentsUpdateMessages | ActionUpdateCards diff --git a/src/actions/collection.ts b/src/actions/collection.ts index 767a0c91..f758c325 100644 --- a/src/actions/collection.ts +++ b/src/actions/collection.ts @@ -72,9 +72,12 @@ import { } from '../types.js'; import { + CLEAR_SELECTED_CARDS, RANDOMIZE_SALT, + SELECT_CARDS, SHOW_CARD, SomeAction, + UNSELECT_CARDS, UPDATE_COLLECTION, UPDATE_COLLECTION_SHAPSHOT, UPDATE_RENDER_OFFSET @@ -493,4 +496,24 @@ export const waitForFinalCollection = async (description : CollectionDescription if (!collection) throw new Error('We somehow settled without a collection'); return collection; +}; + +export const selectCards = (cards : CardID[]) : SomeAction => { + return { + type: SELECT_CARDS, + cards + }; +}; + +export const unselectCards = (cards : CardID[]) : SomeAction => { + return { + type: UNSELECT_CARDS, + cards + }; +}; + +export const clearSelectedCards = () : SomeAction => { + return { + type: CLEAR_SELECTED_CARDS + }; }; \ No newline at end of file diff --git a/src/reducers/collection.ts b/src/reducers/collection.ts index 617cbfa6..618fada0 100644 --- a/src/reducers/collection.ts +++ b/src/reducers/collection.ts @@ -12,6 +12,9 @@ import { UPDATE_READS, UPDATE_READING_LIST, SomeAction, + SELECT_CARDS, + UNSELECT_CARDS, + CLEAR_SELECTED_CARDS, } from '../actions.js'; import { @@ -111,6 +114,24 @@ const app = (state : CollectionState = INITIAL_STATE, action : SomeAction) : Col ...state, randomSalt: randomString(16) }; + case SELECT_CARDS: + return { + ...state, + selectedCards: { + ...state.selectedCards, + ...Object.fromEntries(action.cards.map(id => [id, true])) + } + }; + case UNSELECT_CARDS: + return { + ...state, + selectedCards: Object.fromEntries(Object.entries(state.selectedCards).filter(([id, _]) => !action.cards.includes(id))) + }; + case CLEAR_SELECTED_CARDS: + return { + ...state, + selectedCards: {} + }; default: return state; }