Skip to content

Commit

Permalink
Create a collection.collectionWordcloudVersion machinery and action.
Browse files Browse the repository at this point in the history
Part of #694.
  • Loading branch information
jkomoros committed Aug 4, 2024
1 parent 8e67a39 commit 3babb0a
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 2 deletions.
6 changes: 6 additions & 0 deletions src/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ 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';
export const INCREMENT_COLLECTION_WORD_CLOUD_VERSION = 'INCREMENT_COLLECTION_WORD_CLOUD_VERSION';
//Comments
export const COMMENTS_UPDATE_THREADS = 'COMMENTS_UPDATE_THREADS';
export const COMMENTS_UPDATE_MESSAGES = 'COMMENTS_UPDATE_MESSAGES';
Expand Down Expand Up @@ -432,6 +433,10 @@ type ActionClearSelectedCards = {
type: typeof CLEAR_SELECTED_CARDS
};

type ActionIncrementCollectionWordCloudVersion = {
type: typeof INCREMENT_COLLECTION_WORD_CLOUD_VERSION
};

type ActionCommentsUpdateThreads = {
type: typeof COMMENTS_UPDATE_THREADS,
threads: CommentThreads
Expand Down Expand Up @@ -1045,6 +1050,7 @@ export type SomeAction = ActionAIRequestStarted
| ActionSelectCards
| ActionUnselectCards
| ActionClearSelectedCards
| ActionIncrementCollectionWordCloudVersion
| ActionCommentsUpdateThreads
| ActionCommentsUpdateMessages
| ActionUpdateCards
Expand Down
7 changes: 7 additions & 0 deletions src/actions/collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ import {

import {
CLEAR_SELECTED_CARDS,
INCREMENT_COLLECTION_WORD_CLOUD_VERSION,
RANDOMIZE_SALT,
SELECT_CARDS,
SHOW_CARD,
Expand Down Expand Up @@ -528,4 +529,10 @@ export const clearSelectedCards = () : SomeAction => {
return {
type: CLEAR_SELECTED_CARDS
};
};

export const incrementCollectionWordCloud = () : SomeAction => {
return {
type: INCREMENT_COLLECTION_WORD_CLOUD_VERSION
};
};
3 changes: 2 additions & 1 deletion src/filters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2084,5 +2084,6 @@ export const INITIAL_STATE : CollectionState = {
activeCardID: '',
randomSalt: randomString(16),
activeRenderOffset: 0,
selectedCards: {}
selectedCards: {},
collectionWordCloudVersion: 0
};
6 changes: 6 additions & 0 deletions src/reducers/collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
SELECT_CARDS,
UNSELECT_CARDS,
CLEAR_SELECTED_CARDS,
INCREMENT_COLLECTION_WORD_CLOUD_VERSION,
} from '../actions.js';

import {
Expand Down Expand Up @@ -132,6 +133,11 @@ const app = (state : CollectionState = INITIAL_STATE, action : SomeAction) : Col
...state,
selectedCards: {}
};
case INCREMENT_COLLECTION_WORD_CLOUD_VERSION:
return {
...state,
collectionWordCloudVersion: state.collectionWordCloudVersion + 1
};
default:
return state;
}
Expand Down
1 change: 1 addition & 0 deletions src/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ export const selectFetchedCard = (state : State) => state.app.fetchedCard;
export const selectCardBeingFetched = (state : State) => state.app.cardBeingFetched;
export const selectCardsDrawerInfoExpanded = (state : State) => state.app.cardsDrawerInfoExpanded;
export const selectConfigureCollectionDialogOpen = (state : State) => state.app ? state.app.configureCollectionDialogOpen : false;
export const selectCollectionWordCloudVersion = (state : State) => state.collection ? state.collection.collectionWordCloudVersion : 0;
export const selectSuggestMissingConceptsEnabled = (state : State) => state.app.suggestMissingConceptsEnabled;

export const selectComposeOpen = (state : State) => state.prompt ? state.prompt.composeOpen : false;
Expand Down
4 changes: 3 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1245,7 +1245,9 @@ export type CollectionState = {
activeRenderOffset: number,
//This is the set of cards that are currently selected. Selection state is
//ephemeral and not persisted.
selectedCards: FilterMap
selectedCards: FilterMap,
//It's very expensive to update the collectionWordCloud, so we only update it when this is incremented.
collectionWordCloudVersion: number
}

export type CommentsState = {
Expand Down

0 comments on commit 3babb0a

Please sign in to comment.