Refactor useSettings hook, parse with zod schema

This commit is contained in:
Alex Gleason
2024-02-13 23:20:18 -06:00
parent b0a82a23d0
commit ffdb744d16
40 changed files with 108 additions and 92 deletions

View File

@ -27,14 +27,13 @@ const ScrollTopButton: React.FC<IScrollTopButton> = ({
autoloadThreshold = 50,
}) => {
const intl = useIntl();
const settings = useSettings();
const { autoloadTimelines } = useSettings();
// Whether we are scrolled past the `threshold`.
const [scrolled, setScrolled] = useState<boolean>(false);
// Whether we are scrolled above the `autoloadThreshold`.
const [scrolledTop, setScrolledTop] = useState<boolean>(false);
const autoload = settings.get('autoloadTimelines') === true;
const visible = count > 0 && scrolled;
/** Number of pixels scrolled down from the top of the page. */
@ -44,10 +43,10 @@ const ScrollTopButton: React.FC<IScrollTopButton> = ({
/** Unload feed items if scrolled to the top. */
const maybeUnload = useCallback(() => {
if (autoload && scrolledTop && count) {
if (autoloadTimelines && scrolledTop && count) {
onClick();
}
}, [autoload, scrolledTop, count, onClick]);
}, [autoloadTimelines, scrolledTop, count, onClick]);
/** Set state while scrolling. */
const handleScroll = useCallback(throttle(() => {