Skip to content

Commit 947510b

Browse files
author
Oracle Public Cloud User
committed
Preshuffle Total Recall starter deck
1 parent f1c861c commit 947510b

3 files changed

Lines changed: 1018 additions & 2 deletions

File tree

apps/total-recall/app.js

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@
8282
? sourceDefaultDeck.name.trim()
8383
: 'Starter deck';
8484

85+
const DEFAULT_INITIAL_ORDER =
86+
sourceDefaultDeck && Array.isArray(sourceDefaultDeck.initialOrder) ? sourceDefaultDeck.initialOrder : null;
87+
8588
let decks = [];
8689
let activeDeckId = '';
8790
let browserQuery = '';
@@ -219,6 +222,22 @@
219222
};
220223
}
221224

225+
function applyDefaultInitialOrder(deck) {
226+
if (!deck || deck.notes !== DEFAULT_NOTES || deck.name !== DEFAULT_DECK_NAME) {
227+
return;
228+
}
229+
230+
const initialOrder = sanitizeOrder(DEFAULT_INITIAL_ORDER, deck.entries.length);
231+
if (!initialOrder) {
232+
return;
233+
}
234+
235+
deck.state = {
236+
order: initialOrder,
237+
index: 0
238+
};
239+
}
240+
222241
function sanitizeDeck(rawDeck) {
223242
if (!rawDeck || typeof rawDeck !== 'object') {
224243
return null;
@@ -251,7 +270,11 @@
251270
const notes = typeof legacyNotes === 'string' && legacyNotes.length ? legacyNotes : DEFAULT_NOTES;
252271
const deck = createDeck(DEFAULT_DECK_NAME, notes);
253272
const legacyState = loadLegacyState();
254-
deck.state = sanitizeState(legacyState, deck.entries.length);
273+
if (legacyState) {
274+
deck.state = sanitizeState(legacyState, deck.entries.length);
275+
} else {
276+
applyDefaultInitialOrder(deck);
277+
}
255278

256279
// Clean up legacy keys so the new structure is the source of truth.
257280
safeRemoveItem(STORAGE_KEYS.legacyNotes);

0 commit comments

Comments
 (0)