Skip to content

Commit

Permalink
A few more guards for noUncheckedIndexedAccess
Browse files Browse the repository at this point in the history
Part of #711.
  • Loading branch information
jkomoros committed Feb 17, 2025
1 parent 6577bdf commit 90699a2
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
14 changes: 10 additions & 4 deletions src/actions/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,9 @@ const waitingForCardToExistStoreUpdated = () => {
for (const cardID of Object.keys(waitingForCards)) {
const card = getCardById(store.getState() as State, cardID);
if (!card) continue;
for (const promiseResolver of waitingForCards[cardID]) {
const resolvers = waitingForCards[cardID];
if (!resolvers) continue;
for (const promiseResolver of resolvers) {
promiseResolver(card);
}
delete waitingForCards[cardID];
Expand Down Expand Up @@ -267,7 +269,9 @@ export const waitForCardToExist = (cardID : CardID) => {
if (!waitingForCards[cardID]) waitingForCards[cardID] = [];
if (!unsubscribeFromStore) unsubscribeFromStore = store.subscribe(waitingForCardToExistStoreUpdated);
const promise = new Promise<Card>((resolve) => {
waitingForCards[cardID].push(resolve);
const arr = waitingForCards[cardID];
if (!arr) throw new Error('No array');
arr.push(resolve);
});
return promise;
};
Expand Down Expand Up @@ -516,6 +520,8 @@ export const reorderCard = (cardID : CardID, otherID: CardID, isAfter : boolean)
const cards = selectCards(state);
const card = cards[cardID];

if (!card) throw new Error('No card');

modifyCardWithBatch(state, card, update, false, batch);

try {
Expand Down Expand Up @@ -797,7 +803,7 @@ export const bulkCreateWorkingNotes = (bodies : string[], flags? : CardFlags) :
sortOrder -= DEFAULT_SORT_ORDER_INCREMENT;
}

const firstID = ids[0];
const firstID = ids[0] || '';

//Tell card-view to expect a new card to be loaded, so the machinery to wait
//for the new cards works.
Expand Down Expand Up @@ -1335,7 +1341,7 @@ export const updateSections = (sections : Sections) : ThunkSomeAction => (dispat
//If the update is a single section updating and it's the one currently
//visible then we should update collections. This could happen for example
//if a new card is added, or if cards are reordered.
const currentSectionId = selectActiveSectionId(getState());
const currentSectionId = selectActiveSectionId(getState()) || '';
const force = Object.keys(sections).length == 1 && sections[currentSectionId] !== undefined;

dispatch(refreshCardSelector(force));
Expand Down
5 changes: 4 additions & 1 deletion src/actions/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -713,7 +713,10 @@ export const addImageWithURL = (src : string, uploadPath = '', index = 0) : Thun
images = getImagesFromCard(selectEditingCard(getState()));
let actualIndex = -1;
for (let i = 0; i < images.length; i++) {
if (images[i].src == src) {
const img = images[i];
//Make typescript happy that there is an object
if (!img) continue;
if (img.src == src) {
actualIndex = i;
break;
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/ai-dialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ class AIDialog extends connect(store)(DialogElement) {
if (!result || result.length == 0) result = [''];
switch(this._kindConfig.resultType) {
case 'text-block':
return html`<textarea readonly id='result' .value=${result[0]}></textarea>`;
return html`<textarea readonly id='result' .value=${result[0] || ''}></textarea>`;
case 'multi-line':
return result.map((item, index) => html`<div><input type='radio' name='result' .value=${String(index)} id=${'result-' + index} .checked=${this._selectedIndex == index} @change=${this._selectedIndexChanged}></input><label class='large' for=${'result-' + index}>${item}</label></div>`);
case 'tag-list':
Expand Down

0 comments on commit 90699a2

Please sign in to comment.