diff --git a/plugins/view-resources/src/components/list/ListCategories.svelte b/plugins/view-resources/src/components/list/ListCategories.svelte index ab7af4db69e..3ac7e29e311 100644 --- a/plugins/view-resources/src/components/list/ListCategories.svelte +++ b/plugins/view-resources/src/components/list/ListCategories.svelte @@ -228,18 +228,22 @@ if (listListCategory?.[0] == null) { return } - const obj = listListCategory[0].getLimited()[0] - listListCategory[0].expand() - select(0, obj) + const obj = listListCategory[0]?.getLimited()?.[0] + if (obj !== undefined) { + listListCategory[0]?.expand() + select(0, obj) + } return } else { if (listListCategory?.[0] == null) { return } - const g = listListCategory[categories.length - 1].getLimited() - listListCategory[categories.length - 1].expand() - const obj = g[g.length - 1] - select(0, obj) + const g = listListCategory[categories.length - 1]?.getLimited() ?? [] + if (g.length > 0) { + listListCategory[categories.length - 1].expand() + const obj = g[g.length - 1] + select(0, obj) + } return } } else { @@ -297,17 +301,21 @@ if (dir === undefined || dir === 'vertical') { if (statePos - 1 < 0 && objState >= 0) { if (objState !== 0) { - const pstateObjs = listListCategory[objState - 1].getLimited() - dispatch('select', pstateObjs[pstateObjs.length - 1]) + const pstateObjs = listListCategory[objState - 1]?.getLimited() + if (pstateObjs !== undefined) { + dispatch('select', pstateObjs[pstateObjs.length - 1]) + } } else { dispatch('select-prev', stateObjs[statePos]) } } else { const obj = stateObjs[statePos - 1] if (obj !== undefined) { - const focusDoc = listListCategory[objState]?.getLimited().find((it) => it._id === obj._id) ?? obj - if (!noScroll) scrollInto(objState, focusDoc) - dispatch('row-focus', focusDoc) + const focusDoc = listListCategory[objState]?.getLimited()?.find((it) => it._id === obj._id) ?? obj + if (focusDoc !== undefined) { + if (!noScroll) scrollInto(objState, focusDoc) + dispatch('row-focus', focusDoc) + } } } return @@ -315,7 +323,7 @@ } if (offset === 1) { if (dir === undefined || dir === 'vertical') { - const limited = listListCategory[objState].getLimited() + const limited = listListCategory[objState]?.getLimited() ?? [] if (statePos + 1 >= limited.length && objState < categories.length) { if (objState + 1 !== categories.length) { const pstateObjs = getGroupByValues(groupByDocs, categories[objState + 1]) @@ -326,18 +334,22 @@ } else { const obj = stateObjs[statePos + 1] if (obj !== undefined) { - const focusDoc = listListCategory[objState]?.getLimited().find((it) => it._id === obj._id) ?? obj - if (!noScroll) scrollInto(objState, focusDoc) - dispatch('row-focus', focusDoc) + const focusDoc = listListCategory[objState]?.getLimited()?.find((it) => it._id === obj._id) ?? obj + if (focusDoc !== undefined) { + if (!noScroll) scrollInto(objState, focusDoc) + dispatch('row-focus', focusDoc) + } } } return } } if (offset === 0) { - const focusDoc = listListCategory[objState]?.getLimited().find((it) => it._id === obj._id) ?? obj - if (!noScroll) scrollInto(objState, focusDoc) - dispatch('row-focus', focusDoc) + const focusDoc = listListCategory[objState]?.getLimited()?.find((it) => it._id === obj._id) ?? obj + if (focusDoc !== undefined) { + if (!noScroll) scrollInto(objState, focusDoc) + dispatch('row-focus', focusDoc) + } } } else { listCategory[objState]?.select(offset, of, dir, noScroll)