Update the selected highlight item when using keyboard controls

This commit is contained in:
Jackson Harper 2023-06-27 13:14:34 +08:00
parent 94286c6676
commit 976a0cb88c
2 changed files with 15 additions and 3 deletions

View file

@ -119,7 +119,9 @@ export function LibraryItemMetadata(
props: LibraryItemMetadataProps
): JSX.Element {
const highlightCount = useMemo(() => {
return props.item.highlights?.length ?? 0
return (
props.item.highlights?.filter((h) => h.type == 'HIGHLIGHT').length ?? 0
)
}, [props.item.highlights])
return (

View file

@ -205,6 +205,11 @@ export function HomeFeedContainer(): JSX.Element {
}
setActiveCardId(id)
scrollToActiveCard(id, true)
const newItem = getItem(id)
if (notebookTarget && newItem) {
setNotebookTarget(newItem)
}
},
[libraryItems]
)
@ -259,6 +264,13 @@ export function HomeFeedContainer(): JSX.Element {
return libraryItems.find((item) => item.node.id === activeCardId)
}, [libraryItems, activeCardId])
const getItem = useCallback(
(itemId) => {
return libraryItems.find((item) => item.node.id === itemId)
},
[libraryItems]
)
const activeItemIndex = useMemo(() => {
if (!activeCardId) {
return undefined
@ -276,8 +288,6 @@ export function HomeFeedContainer(): JSX.Element {
alreadyScrolled.current = true
if (activeItem) {
console.log('refreshing')
// refresh items on home feed
performActionOnItem('refresh', activeItem)
}
}