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

solved #20 i.e contact link is now working from other than homepage #21

Open
wants to merge 19 commits into
base: main
Choose a base branch
from
Open
Changes from 3 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
0a193e4
solved #20 i.e contact link is now working from other than homepage
thecodephilic-guy Nov 12, 2024
a24f295
fixed the improper behavior of footer in production
thecodephilic-guy Nov 13, 2024
7764dda
Merge branch 'ohcnetwork:main' into main
thecodephilic-guy Nov 17, 2024
a520c9a
removed scroll behaviour from footer and fixed contact link behaviour
thecodephilic-guy Nov 18, 2024
f99dad3
Merge branch 'ohcnetwork:main' into main
thecodephilic-guy Dec 1, 2024
6fcf2ec
Merge branch 'ohcnetwork:main' into main
thecodephilic-guy Dec 6, 2024
c7c43a3
Solved the navigation problem using Link tag
thecodephilic-guy Dec 6, 2024
848b5ee
made some changes in pages/index.js to make contact link work.
thecodephilic-guy Dec 6, 2024
c2c3008
Merge branch 'ohcnetwork:main' into main
thecodephilic-guy Dec 27, 2024
acac58d
Merge branch 'ohcnetwork:main' into main
thecodephilic-guy Dec 27, 2024
8f11131
Merge remote-tracking branch 'origin/main'
thecodephilic-guy Dec 27, 2024
c451c3f
Merge remote-tracking branch 'origin/main'
thecodephilic-guy Dec 27, 2024
ed1c38e
Merge remote-tracking branch 'origin/main'
thecodephilic-guy Dec 29, 2024
100472d
Merge remote-tracking branch 'origin/main'
thecodephilic-guy Dec 29, 2024
d363ee2
Merge remote-tracking branch 'origin/main'
thecodephilic-guy Jan 4, 2025
578df8c
Merge remote-tracking branch 'origin/main'
thecodephilic-guy Jan 4, 2025
6ec3058
Merge remote-tracking branch 'origin/main'
thecodephilic-guy Jan 4, 2025
8d41351
Merge remote-tracking branch 'origin/main'
thecodephilic-guy Jan 4, 2025
1f04d91
Merge remote-tracking branch 'origin/main'
thecodephilic-guy Jan 4, 2025
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
38 changes: 33 additions & 5 deletions components/Footer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import Image from 'next/image';
import Link from 'next/link';
import { usePathname, useRouter } from 'next/navigation';
import { useEffect } from 'react';

export default function Footer() {
const router = useRouter();
Expand All @@ -15,17 +16,44 @@ export default function Footer() {
{ name: 'Contact', href: '/#contact' },
];

useEffect(() => {
const handleScrollToHash = () => {
const hash = window.location.hash;
if (hash) {
const id = hash.replace('#', '');
const element = document.getElementById(id);
if (element) {
element.scrollIntoView({ behavior: 'smooth' });
history.replaceState(null, '', window.location.pathname);
}
}
};

// Immediately invoke the function once after navigation
handleScrollToHash();

// Cleanup logic: Only observe for initial change and then disconnect
const observer = new MutationObserver(() => {
handleScrollToHash();
observer.disconnect(); // Disconnect after one scroll to prevent repeated triggers
});

observer.observe(document.body, { attributes: true, subtree: true });
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a bit overkill for a small issue. Let's stick to just taking the user to /#contact without the scroll behaviour.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah actually it is and I have rolled my to previous one. But I am still struggling with the problem that it is not taking to the /#contact when user is on supporters page or may be care page. I tried faking the network speed during development it worked there but only for localhost. I need some more time to go to the core of the problem. I have the intuation it is just a minor one but I am not able to get it.


return () => observer.disconnect();
}, [path]);



const handleNavigation = (href: string) => {
if (href.includes('#')) {
const [page, section] = href.split('#');
const targetPage = page || '/';

if (path === page) {
if (path === targetPage) {
document.getElementById(section)?.scrollIntoView({ behavior: 'smooth' });
} else {
router.push(page);
setTimeout(() => {
document.getElementById(section)?.scrollIntoView({ behavior: 'smooth' });
}, 100); // Adding a small delay to ensure the page has navigated
router.push(targetPage + '#' + section);
}
} else {
router.push(href);
Expand Down