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
Show file tree
Hide file tree
Changes from all 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
52 changes: 24 additions & 28 deletions components/Footer.tsx
Original file line number Diff line number Diff line change
@@ -1,37 +1,38 @@
"use client";
'use client';

import Image from 'next/image';
import Link from 'next/link';
import { usePathname, useRouter } from 'next/navigation';
import { useEffect } from 'react';
import { usePathname } from 'next/navigation';

export default function Footer() {
const router = useRouter();
const path = usePathname();

useEffect(() => {
if (typeof window !== 'undefined' && path === '/' && window.location.hash) {
const handleHashChange = () => {
const element = document.querySelector(window.location.hash);
if (element) {
element.scrollIntoView({ behavior: 'smooth' });
}
};

handleHashChange(); // Handle the current hash on load

window.addEventListener('hashchange', handleHashChange); // Listen for future hash changes
return () => window.removeEventListener('hashchange', handleHashChange);
}
}, [path]);

const navigation = [
{ name: 'Home', href: '/' },
// { name: 'Projects', href: '/projects' },
{ name: 'Supporters', href: '/supporters' },
{ name: 'Contact', href: '/#contact' },
{
name: 'Contact',
href: path === '/' ? '/#contact' : '/?section=contact'
},
];

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

if (path === page) {
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
}
} else {
router.push(href);
}
};

const socialLinks = [
{
name: 'YouTube',
Expand Down Expand Up @@ -76,15 +77,10 @@ export default function Footer() {
<nav className="flex flex-col space-y-3">
{navigation.map((item) => (
<Link
prefetch={false} // Disable prefetching to avoid potential conflicts
key={item.name}
href={item.href}
className="text-primary-900 hover:text-primary-600 transition-colors text-sm"
onClick={(e) => {
if (item.href.includes('#')) {
e.preventDefault();
handleNavigation(item.href);
}
}}
>
{item.name}
</Link>
Expand Down
17 changes: 16 additions & 1 deletion components/header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export default function Header(props: { fixed?: boolean }) {
{ type: "dropdown", content: "Community", items: communityItems },
{ type: "link", content: "Supporters", href: "/supporters" },
{ type: "link", content: "Timeline", href: "/timeline" },
{ type: "section", content: "Contact", id: "contact", page: "/" },
{ type: "link", content: "Contact", href: path === '/' ? '/#contact' : '/?section=contact' },
{
type: "link",
content: (
Expand All @@ -101,6 +101,21 @@ export default function Header(props: { fixed?: boolean }) {
href: "https://github.com/ohcnetwork",
},
];
useEffect(() => {
if (typeof window !== 'undefined' && path === '/' && window.location.hash) {
const handleHashChange = () => {
const element = document.querySelector(window.location.hash);
if (element) {
element.scrollIntoView({ behavior: 'smooth' });
}
};

handleHashChange(); // Handle the current hash on load

window.addEventListener('hashchange', handleHashChange); // Listen for future hash changes
return () => window.removeEventListener('hashchange', handleHashChange);
}
}, [path]);

useEffect(() => {
const handleScroll = () => setScrolled(window.scrollY > 200);
Expand Down
25 changes: 24 additions & 1 deletion pages/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable @next/next/no-img-element */
import { useState } from "react";
import { useState, useEffect } from "react";
import {
ArrowPathIcon,
ChevronRightIcon,
Expand All @@ -16,6 +16,7 @@ import Link from "next/link";
import CommitLayout from "@/components/Commit/CommitLayout";
import Header from "@/components/header";
import Footer from "@/components/Footer";
import { useRouter } from "next/router";

const primaryFeatures = [
{
Expand Down Expand Up @@ -149,6 +150,28 @@ type Banner = {
export default function Home() {

const [banner, setBanner] = useState<Banner | null>(null);
const router = useRouter();

useEffect(() => {
if (router.asPath.includes('#')) {
const elementId = router.asPath.split('#')[1];
const element = document.getElementById(elementId);
if (element) {
element.scrollIntoView({ behavior: 'smooth' });
}
}
}, [router.asPath]);

useEffect(() => {
const searchParams = new URLSearchParams(window.location.search);
const section = searchParams.get('section');
if (section === 'contact') {
const element = document.querySelector('#contact');
if (element) {
element.scrollIntoView({ behavior: 'smooth' });
}
}
}, []);

return (
<div className="bg-white">
Expand Down