-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
123 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { createActiveElement } from '@solid-primitives/active-element'; | ||
import { createContext, useContext } from 'solid-js'; | ||
import { IDS } from '~/constants/elements'; | ||
import { useInfiniteEntries } from '~/hooks/queries/use-infinite-entries'; | ||
import { useListNav } from '~/hooks/use-list-nav'; | ||
|
||
type EntriesContext = ReturnType<typeof makeEntriesContext>; | ||
export const EntriesContext = createContext<EntriesContext>(); | ||
|
||
export const useEntries = () => { | ||
const state = useContext(EntriesContext); | ||
if (!state) throw new Error('EntriesContext has not been initialized.'); | ||
return state; | ||
}; | ||
|
||
export const makeEntriesContext = () => { | ||
const data = useInfiniteEntries(); | ||
|
||
// If the user is focused within the entry content, don't respond to arrow keys | ||
const activeElement = createActiveElement(); | ||
const isFocusedWithinEntry = () => !!document.getElementById(IDS.ARTICLE)?.contains(activeElement()); | ||
|
||
// Handle arrow navigation | ||
const nav = useListNav(() => ({ | ||
enabled: !isFocusedWithinEntry(), | ||
entryUuids: data.allEntries().map(entry => entry.uuid), | ||
fetchMore: data.fetchMore, | ||
})); | ||
|
||
return { | ||
data, | ||
nav, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.