mirror of
https://github.com/umami-software/umami.git
synced 2026-02-10 23:57:12 +01:00
Fixed sticky header scrolling. Updated settings button.
This commit is contained in:
parent
5262d19c8b
commit
bb99b3eba5
16 changed files with 109 additions and 134 deletions
|
|
@ -1,12 +1,20 @@
|
|||
import { useApi as nextUseApi } from 'next-basics';
|
||||
import { getClientAuthToken } from 'lib/client';
|
||||
import { useRouter } from 'next/router';
|
||||
import * as reactQuery from '@tanstack/react-query';
|
||||
import { useApi as nextUseApi } from 'next-basics';
|
||||
import { getClientAuthToken } from 'lib/client';
|
||||
import { SHARE_TOKEN_HEADER } from 'lib/constants';
|
||||
import useStore from 'store/app';
|
||||
|
||||
const selector = state => state.shareToken;
|
||||
|
||||
export default function useApi() {
|
||||
const { basePath } = useRouter();
|
||||
const shareToken = useStore(selector);
|
||||
|
||||
const { get, post, put, del } = nextUseApi(getClientAuthToken(), basePath);
|
||||
const { get, post, put, del } = nextUseApi(
|
||||
{ authorization: `Bearer ${getClientAuthToken()}`, [SHARE_TOKEN_HEADER]: shareToken?.token },
|
||||
basePath,
|
||||
);
|
||||
|
||||
return { get, post, put, del, ...reactQuery };
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,25 +1,23 @@
|
|||
import { useState, useEffect, useRef } from 'react';
|
||||
|
||||
export default function useSticky({ scrollElementId, defaultSticky = false }) {
|
||||
export default function useSticky({ scrollElement = document, defaultSticky = false }) {
|
||||
const [isSticky, setIsSticky] = useState(defaultSticky);
|
||||
const ref = useRef(null);
|
||||
const initialTop = useRef(null);
|
||||
|
||||
useEffect(() => {
|
||||
const element = scrollElementId ? document.getElementById(scrollElementId) : window;
|
||||
|
||||
const handleScroll = () => {
|
||||
setIsSticky(element.scrollTop > initialTop.current);
|
||||
setIsSticky((scrollElement?.scrollTop ?? window.scrollY) > initialTop.current);
|
||||
};
|
||||
|
||||
if (initialTop.current === null) {
|
||||
initialTop.current = ref?.current?.offsetTop;
|
||||
}
|
||||
|
||||
element.addEventListener('scroll', handleScroll);
|
||||
scrollElement.addEventListener('scroll', handleScroll, true);
|
||||
|
||||
return () => {
|
||||
element.removeEventListener('scroll', handleScroll);
|
||||
scrollElement.removeEventListener('scroll', handleScroll, true);
|
||||
};
|
||||
}, [ref, setIsSticky]);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue