Skip to content

Commit

Permalink
Allow modifying the card export order with state anda ction creators.
Browse files Browse the repository at this point in the history
Part of #688.
  • Loading branch information
jkomoros committed Apr 7, 2024
1 parent 45d1868 commit 56b6873
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 2 deletions.
7 changes: 7 additions & 0 deletions src/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ export const BULK_IMPORT_PENDING = 'BULK_IMPORT_DIALOG_PENDING';
export const BULK_IMPORT_SUCCESS = 'BULK_IMPORT_SUCCESS';
export const BULK_IMPORT_DIALOG_CLOSE = 'BULK_IMPORT_DIAOG_CLOSE';
export const BULK_IMPORT_SET_BODIES = 'BULK_IMPORT_SET_BODIES';
export const BULK_IMPORT_SET_OVERRIDE_CARD_ORDER = 'BULK_IMPORT_SET_OVERRIDE_CARD_ORDER';
//Collection.js
export const SHOW_CARD = 'SHOW_CARD';
export const UPDATE_COLLECTION = 'UPDATE_COLLECTION';
Expand Down Expand Up @@ -362,6 +363,11 @@ type ActionBulkImportPending = {
type: typeof BULK_IMPORT_PENDING
};

type ActionBulkImportDialogSetOverrideCardOrder = {
type: typeof BULK_IMPORT_SET_OVERRIDE_CARD_ORDER,
order: CardID[]
};

type ActionBulkImportSuccees = {
type: typeof BULK_IMPORT_SUCCESS
}
Expand Down Expand Up @@ -1024,6 +1030,7 @@ export type SomeAction = ActionAIRequestStarted
| ActionBulkImportSuccees
| ActionBulkImportDialogClose
| ActionBulkImportSetBodies
| ActionBulkImportDialogSetOverrideCardOrder
| ActionUpdateCollection
| ActionUpdateRenderOffset
| ActionUpdateCollectionSnapshot
Expand Down
8 changes: 8 additions & 0 deletions src/reducers/bulk-import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
BULK_IMPORT_PENDING,
BULK_IMPORT_SET_BODIES,
BULK_IMPORT_SUCCESS,
BULK_IMPORT_SET_OVERRIDE_CARD_ORDER,
SomeAction
} from '../actions.js';

Expand All @@ -15,6 +16,7 @@ const INITIAL_STATE : BulkImportState = {
open: false,
mode: 'import',
pending: false,
overrideCardOrder: null,
bodies: [],
importer: '',
importerVersion: 0
Expand All @@ -34,6 +36,7 @@ const app = (state : BulkImportState = INITIAL_STATE, action : SomeAction) : Bul
mode: action.mode,
pending: false,
bodies: [],
overrideCardOrder: null,
importer: '',
importerVersion: 0
};
Expand All @@ -55,6 +58,11 @@ const app = (state : BulkImportState = INITIAL_STATE, action : SomeAction) : Bul
importer: action.importer,
importerVersion: action.importerVersion
};
case BULK_IMPORT_SET_OVERRIDE_CARD_ORDER:
return {
...state,
overrideCardOrder: action.order
};
default:
return state;
}
Expand Down
11 changes: 9 additions & 2 deletions src/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ export const selectBulkImportPending = (state : State) => state.bulkImport ? sta
export const selectBulkImportDialogBodies = (state : State) => state.bulkImport ? state.bulkImport.bodies : [];
export const selectBulkImportDialogImporter = (state : State) => state.bulkImport ? state.bulkImport.importer : '';
export const selectBulkImportDialogImporterVersion = (state : State) => state.bulkImport ? state.bulkImport.importerVersion : 0;
export const selectBulkImportDialogOverrideCardOrder = (state : State) => state.bulkImport ? state.bulkImport.overrideCardOrder : null;

export const selectAIDialogOpen = (state : State) => state.ai ? state.ai.open : false;
export const selectAIActive = (state : State) => state.ai ? state.ai.active : false;
Expand Down Expand Up @@ -1824,9 +1825,15 @@ export const selectMultiEditCardDiff = createSelector(
export const selectBulkImportDialogExportContent = createSelector(
selectBulkImportDialogOpen,
selectBulKimportDialogMode,
selectBulkImportDialogOverrideCardOrder,
selectActiveCollectionCards,
(open, mode, cards) => {
(open, mode, cardOrder, cards) => {
if (!open || mode != 'export') return '';
return exportContentForCards(cards);
let finalCards = cards;
if (cardOrder) {
const allCards = Object.fromEntries(cards.map(card => [card.id, card]));
finalCards = cardOrder.map(id => allCards[id]);
}
return exportContentForCards(finalCards);
}
);
2 changes: 2 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1506,6 +1506,8 @@ export type BulkImportState = {
//Whether or not the import is running
pending: boolean,
bodies: string[],
//If provided, will use this order, not the implicit order of the collection.
overrideCardOrder: CardID[] | null,
importer: ImporterType | '',
importerVersion: number
};
Expand Down

0 comments on commit 56b6873

Please sign in to comment.