forked from Archives/Athou_commafeed
scroll only if the entry doesn't entirely fit on screen (same as commafeed v1)
This commit is contained in:
@@ -8,6 +8,8 @@ export const Constants = {
|
|||||||
mobileBreakpoint: DEFAULT_THEME.breakpoints.md,
|
mobileBreakpoint: DEFAULT_THEME.breakpoints.md,
|
||||||
headerHeight: 60,
|
headerHeight: 60,
|
||||||
sidebarWidth: 350,
|
sidebarWidth: 350,
|
||||||
|
isTopVisible: (div: HTMLDivElement) => div.getBoundingClientRect().top >= Constants.layout.headerHeight,
|
||||||
|
isBottomVisible: (div: HTMLDivElement) => div.getBoundingClientRect().bottom <= window.innerHeight,
|
||||||
},
|
},
|
||||||
dom: {
|
dom: {
|
||||||
mainScrollAreaId: "main-scroll-area-id",
|
mainScrollAreaId: "main-scroll-area-id",
|
||||||
|
|||||||
@@ -52,8 +52,7 @@ export function FeedEntries() {
|
|||||||
if (selectedEntry) {
|
if (selectedEntry) {
|
||||||
if (selectedEntry.expanded) {
|
if (selectedEntry.expanded) {
|
||||||
const ref = refs.current[selectedEntry.id]
|
const ref = refs.current[selectedEntry.id]
|
||||||
const bottomVisible = ref.getBoundingClientRect().bottom <= window.innerHeight
|
if (Constants.layout.isBottomVisible(ref)) {
|
||||||
if (bottomVisible) {
|
|
||||||
dispatch(selectNextEntry())
|
dispatch(selectNextEntry())
|
||||||
} else {
|
} else {
|
||||||
const scrollArea = document.getElementById(Constants.dom.mainScrollAreaId)
|
const scrollArea = document.getElementById(Constants.dom.mainScrollAreaId)
|
||||||
@@ -73,8 +72,7 @@ export function FeedEntries() {
|
|||||||
if (selectedEntry) {
|
if (selectedEntry) {
|
||||||
if (selectedEntry.expanded) {
|
if (selectedEntry.expanded) {
|
||||||
const ref = refs.current[selectedEntry.id]
|
const ref = refs.current[selectedEntry.id]
|
||||||
const topVisible = ref.getBoundingClientRect().top >= Constants.layout.headerHeight
|
if (Constants.layout.isTopVisible(ref)) {
|
||||||
if (topVisible) {
|
|
||||||
dispatch(selectPreviousEntry())
|
dispatch(selectPreviousEntry())
|
||||||
} else {
|
} else {
|
||||||
const scrollArea = document.getElementById(Constants.dom.mainScrollAreaId)
|
const scrollArea = document.getElementById(Constants.dom.mainScrollAreaId)
|
||||||
|
|||||||
@@ -58,6 +58,7 @@ export function FeedEntry(props: FeedEntryProps) {
|
|||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
if (!ref.current) return
|
if (!ref.current) return
|
||||||
if (!props.expanded) return
|
if (!props.expanded) return
|
||||||
|
if (Constants.layout.isTopVisible(ref.current) && Constants.layout.isBottomVisible(ref.current)) return
|
||||||
|
|
||||||
document.getElementById(Constants.dom.mainScrollAreaId)?.scrollTo({
|
document.getElementById(Constants.dom.mainScrollAreaId)?.scrollTo({
|
||||||
// having a small gap between the top of the content and the top of the page is sexier
|
// having a small gap between the top of the content and the top of the page is sexier
|
||||||
|
|||||||
Reference in New Issue
Block a user