-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: avoid to observe external links (#1739)
* fix: avoid to observe external links * refactor: less is more * refactor: lazy health check
- Loading branch information
Showing
3 changed files
with
117 additions
and
81 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* global IntersectionObserver */ | ||
|
||
import React, { useState, useEffect, useRef } from 'react' | ||
|
||
const LazyRender = ({ onView, placeholder, options }) => { | ||
const [isVisible, setIsVisible] = useState(false) | ||
const ref = useRef(null) | ||
|
||
useEffect(() => { | ||
const { current } = ref | ||
|
||
const observer = new IntersectionObserver(([entry]) => { | ||
if (entry.isIntersecting) { | ||
setIsVisible(true) | ||
observer.disconnect() | ||
} | ||
}, options) | ||
|
||
if (current) observer.observe(current) | ||
return () => current && observer.unobserve(current) | ||
}, [options]) | ||
|
||
return <div ref={ref}>{isVisible ? onView() : placeholder()}</div> | ||
} | ||
|
||
export default LazyRender |
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 |
---|---|---|
|
@@ -4,6 +4,7 @@ import { Mail } from 'react-feather' | |
import { issueUrl } from 'helpers' | ||
import React from 'react' | ||
|
||
import IntersectionObserver from '../../elements/IntersectionObserver' | ||
import Healthcheck from '../Healthcheck/Healthcheck' | ||
|
||
import { | ||
|
@@ -35,6 +36,73 @@ const DARK_THEME = { | |
iconColor: colors.white80 | ||
} | ||
|
||
const StatusPage = ({ isDark }) => { | ||
return ( | ||
<LinkSolid | ||
isDark={isDark} | ||
data-event-location='Footer' | ||
data-event-name='Status' | ||
href='/status' | ||
css={theme({ | ||
px: 0 | ||
})} | ||
> | ||
<Text | ||
css={theme({ | ||
fontSize: [0, 0, 0, 1] | ||
})} | ||
> | ||
Status Page | ||
</Text> | ||
</LinkSolid> | ||
) | ||
} | ||
|
||
const Health = ({ isDark, textColor }) => ( | ||
<Healthcheck> | ||
{({ isHealthy, isLoading }) => { | ||
if (isLoading) return <StatusPage isDark={isDark} /> | ||
return ( | ||
<Link | ||
data-event-location='Footer' | ||
data-event-name='Status' | ||
href='/status' | ||
css={theme({ | ||
px: 0, | ||
color: colors[textColor] | ||
})} | ||
> | ||
<Text | ||
css={theme({ | ||
fontSize: [0, 0, 0, 1], | ||
pb: [3, 3, 3, 0] | ||
})} | ||
> | ||
<Choose> | ||
<Choose.When condition={isHealthy}> | ||
<Dot.Success | ||
css={theme({ | ||
mr: 2 | ||
})} | ||
/> | ||
All systems operational | ||
</Choose.When> | ||
<Choose.Otherwise> | ||
<Dot.Warning | ||
css={theme({ | ||
mr: 2 | ||
})} | ||
/> | ||
System performance degradation | ||
</Choose.Otherwise> | ||
</Choose> | ||
</Text> | ||
</Link> | ||
) | ||
}} | ||
</Healthcheck> | ||
) | ||
|
||
const Footer = ({ isDark, ...props }) => { | ||
const { background, textColor, inputIconColor } = isDark | ||
? DARK_THEME | ||
|
@@ -209,69 +277,12 @@ const Footer = ({ isDark, ...props }) => { | |
flexDirection: 'column' | ||
})} | ||
> | ||
<Healthcheck> | ||
{({ isHealthy, isLoading }) => { | ||
if (isLoading) { | ||
return ( | ||
<LinkSolid | ||
isDark={isDark} | ||
data-event-location='Footer' | ||
data-event-name='Status' | ||
href='/status' | ||
css={theme({ | ||
px: 0 | ||
})} | ||
> | ||
<Text | ||
css={theme({ | ||
fontSize: [0, 0, 0, 1] | ||
})} | ||
> | ||
Status Page | ||
</Text> | ||
</LinkSolid> | ||
) | ||
} | ||
|
||
return ( | ||
<Link | ||
data-event-location='Footer' | ||
data-event-name='Status' | ||
href='/status' | ||
css={theme({ | ||
px: 0, | ||
color: colors[textColor] | ||
})} | ||
> | ||
<Text | ||
css={theme({ | ||
fontSize: [0, 0, 0, 1], | ||
pb: [3, 3, 3, 0] | ||
})} | ||
> | ||
<Choose> | ||
<Choose.When condition={isHealthy}> | ||
<Dot.Success | ||
css={theme({ | ||
mr: 2 | ||
})} | ||
/> | ||
All systems operational | ||
</Choose.When> | ||
<Choose.Otherwise> | ||
<Dot.Warning | ||
css={theme({ | ||
mr: 2 | ||
})} | ||
/> | ||
System performance degradation | ||
</Choose.Otherwise> | ||
</Choose> | ||
</Text> | ||
</Link> | ||
) | ||
}} | ||
</Healthcheck> | ||
<IntersectionObserver | ||
placeholder={() => <StatusPage isDark={isDark} />} | ||
onView={() => ( | ||
<Health isDark={isDark} textColor={textColor} /> | ||
)} | ||
/> | ||
</Flex> | ||
</Flex> | ||
|
||
|
@@ -328,16 +339,16 @@ const Footer = ({ isDark, ...props }) => { | |
})} | ||
> | ||
{[ | ||
{ | ||
href: 'https://github.com/microlinkhq', | ||
children: 'GitHub', | ||
title: '@microlinkhq on GitHub' | ||
}, | ||
{ | ||
href: 'https://x.com/microlinkhq', | ||
children: 'X', | ||
title: '@microlinkhq on x.com' | ||
}, | ||
{ | ||
href: 'https://github.com/microlinkhq', | ||
children: 'GitHub', | ||
title: '@microlinkhq on GitHub' | ||
}, | ||
{ | ||
href: 'mailto:[email protected]', | ||
children: 'Email', | ||
|
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