Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: window causes errors in SSR #256

Merged
merged 32 commits into from
Jul 19, 2024
Merged
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
ecdaf1f
fix: mobile: hide mini-toc and change margins
Jul 5, 2024
a4de78c
create SubNavigation in storybook
Jul 9, 2024
b993953
show SubNavigation and MiniToc on mobile The SubHeader was displayed …
Jul 9, 2024
6870de0
refactor components
Jul 10, 2024
fb85e37
SubNavigation slides up when scrolling the page
Jul 11, 2024
5252aea
feat: create mobile mini-toc and subnavigation
Jul 15, 2024
232bef7
fix: improve code-style in SubNavigation
Jul 16, 2024
5b4d991
fix: change subheader-height to correct
Jul 16, 2024
a5858ce
Merge branch 'diplodoc-platform:master' into master
JeikZim Jul 16, 2024
46c7649
merge mobile-ui branch
Jul 16, 2024
19c6b5b
fix: share button in docs without header
Jul 16, 2024
0aeca29
fix: Node.JS.Timeout error
Jul 16, 2024
897ba70
fix: style fixes
Jul 16, 2024
7e18af6
feat: share a page
Jul 16, 2024
aff7c91
fix: prettier errors
Jul 16, 2024
cf7d863
fix: imrove code
Jul 16, 2024
ef1025c
fix: delete unnecessary
Jul 16, 2024
f3c024a
fix: window.clearTimeout
Jul 16, 2024
8a79d8f
fix: separate business-logic from SubNavigation
Jul 16, 2024
aa445f8
fix: click outside menu broke another interectives
Jul 17, 2024
25d6305
Merge branch 'diplodoc-platform:master' into master
JeikZim Jul 17, 2024
103c98b
Merge branch 'diplodoc-platform:master' into master
JeikZim Jul 17, 2024
2a85535
fix: rename SubNavigation.scss
Jul 18, 2024
8c86c04
fix: trimEnd in SubNavigation.tsx
Jul 18, 2024
46eaa9d
update browserlist-db
Jul 18, 2024
b49e358
fix: package-lock.json
Jul 18, 2024
fb79fda
fix: add SubNavigation in index.ts export
Jul 19, 2024
2b9d2c1
Merge branch 'diplodoc-platform:master' into master
JeikZim Jul 19, 2024
1ce98c2
Merge branch 'diplodoc-platform:master' into master
JeikZim Jul 19, 2024
bcad4ea
fix: save window object for SSR
Jul 19, 2024
8e7ff8a
Merge branch 'diplodoc-platform:master' into master
JeikZim Jul 19, 2024
242c88b
prettier fix
Jul 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 19 additions & 5 deletions src/components/SubNavigation/SubNavigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
const useVisibility = (miniTocOpened: boolean, closeMiniToc: () => void) => {
const [visibility, setVisibility] = useState(true);
const [hiddingTimeout, setHiddingTimeout] = useState<number | undefined>(undefined);
const [lastScrollY, setLastScrollY] = useState(window.screenY);
const [lastScrollY, setLastScrollY] = useState(
typeof window === 'undefined' ? null : window.screenY,
);

const clickOutsideMiniToc = useCallback(
(event: MouseEvent) => {
Expand All @@ -42,16 +44,20 @@
);

const controlVisibility = useCallback(() => {
if (typeof window === 'undefined') {
return;
}

if (miniTocOpened) {
setVisibility(true);
return;
}

if (lastScrollY === 0) {
if (lastScrollY && lastScrollY === 0) {
setVisibility(true);
}

if (window.scrollY > lastScrollY) {
if (lastScrollY && window.scrollY > lastScrollY) {
if (hiddingTimeout) {
return;
}
Expand All @@ -64,7 +70,7 @@
setHiddingTimeout(undefined);
}, 300),
);
} else if (window.scrollY < lastScrollY) {
} else if (lastScrollY && window.scrollY < lastScrollY) {
setVisibility(true);
}

Expand All @@ -79,6 +85,10 @@
]);

useEffect(() => {
if (typeof window === 'undefined') {
return;
}

if (window.scrollY === 0) {
return;
}
Expand All @@ -92,6 +102,10 @@
}, []);

useEffect(() => {
if (typeof window === 'undefined') {
return () => {};
}

window.addEventListener('scroll', controlVisibility);

return () => {
Expand All @@ -114,7 +128,7 @@
const shareData = useMemo(() => {
return {
title,
url: window.location.href,
url: typeof window === 'undefined' ? undefined : window.location.href,
};
}, [title]);

Expand All @@ -123,9 +137,9 @@
navigator
.share(shareData)
.then(() => {})
.catch((error) => console.error('Error sharing', error));

Check warning on line 140 in src/components/SubNavigation/SubNavigation.tsx

View workflow job for this annotation

GitHub Actions / Verify Files

Unexpected console statement
} else {
console.log('Share not supported', shareData);

Check warning on line 142 in src/components/SubNavigation/SubNavigation.tsx

View workflow job for this annotation

GitHub Actions / Verify Files

Unexpected console statement
}
}, [shareData]);

Expand Down
Loading