MCPcopy Create free account
hub / github.com/code100x/daily-code / BlogAppbar

Function BlogAppbar

apps/web/components/BlogAppbar.tsx:22–293  ·  view source on GitHub ↗
({
  track,
  problemIndex,
}: {
  problem: Problem & { notionRecordMap: any };
  track: Track & { problems: Problem[] };
  problemIndex: number;
})

Source from the content-addressed store, hash-verified

20import CustomPagination from "./CustomPagination";
21
22export const BlogAppbar = ({
23 track,
24 problemIndex,
25}: {
26 problem: Problem & { notionRecordMap: any };
27 track: Track & { problems: Problem[] };
28 problemIndex: number;
29}) => {
30 const router = useRouter();
31 const session = useSession();
32 const user = session.data?.user;
33
34 const [isLegacyMode, setIsLegacyMode] = useRecoilState(isLegacyViewMode);
35
36 const { trackIds }: { trackIds?: string[] } = useParams();
37 const currentTrack = trackIds ? trackIds.join("/") : "";
38
39 const [isOpen, setIsOpen] = useState<boolean>(() => {
40 const storedPreference = localStorage.getItem("modeToggleIsOpen");
41 return storedPreference === "true" || false;
42 });
43 const [visible, setVisible] = useState(true);
44 const [lastScrollY, setLastScrollY] = useState(0);
45 const [scrollingDown, setScrollingDown] = useState(false);
46 const [prevScrollPos, setPrevScrollPos] = useState(0);
47
48 const toggleViewMode = () => {
49 const newViewMode = !isLegacyMode ? "legacy" : "new";
50 setIsLegacyMode(!isLegacyMode);
51 localStorage.setItem("viewMode", newViewMode);
52 };
53
54 const debounce = (func: any, delay: any) => {
55 let timeoutId: any;
56 return (...args: any) => {
57 clearTimeout(timeoutId);
58 timeoutId = setTimeout(() => {
59 func(...args);
60 }, delay);
61 };
62 };
63
64 const debouncedHandleScroll = debounce(() => {
65 const currentScrollPos = window.scrollY;
66 setVisible(prevScrollPos > currentScrollPos || currentScrollPos < 50);
67 setScrollingDown(prevScrollPos < currentScrollPos);
68 setPrevScrollPos(currentScrollPos);
69 }, 90);
70
71 const handleScroll = () => {
72 if (typeof window !== "undefined") {
73 const currentScrollY = window.scrollY;
74 if (currentScrollY > lastScrollY && currentScrollY > 100) {
75 // Scrolling down
76 setVisible(false);
77 setIsOpen(false);
78 } else {
79 // Scrolling up

Callers

nothing calls this directly

Calls 2

debounceFunction · 0.85
renderBlogAppbarFunction · 0.85

Tested by

no test coverage detected