Skip to content

Commit 7c7c948

Browse files
authored
Merge pull request #56 from jmdotdev/add-landing-page-smooth-scroll-navigation
Add smooth scroll landing page navigation
2 parents 58ca086 + 1640fea commit 7c7c948

4 files changed

Lines changed: 31 additions & 13 deletions

File tree

eventz-ui/src/components/navbar/navbar.component.html

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@ <h1 class="text-white font-bold text-3xl md:text-4xl">EventZ</h1>
88
class="md:hidden cursor-pointer"
99
src="/assets/images/sort.svg"
1010
alt="menu"
11-
(click)="toggleNav()"
11+
(click)="this.showNav = !this.showNav"
1212
/>
1313

1414
<ul class="hidden md:flex items-center">
1515
<li
1616
class="text-white cursor-pointer px-8"
1717
*ngFor="let route of routes"
18+
(click)="toggleNav(route)"
1819
>
1920
{{ route.name }}
2021
</li>
@@ -28,7 +29,7 @@ <h1 class="text-white font-bold text-3xl md:text-4xl">EventZ</h1>
2829
<div
2930
*ngIf="showNav"
3031
class="fixed inset-0 bg-black/50 z-40 md:hidden"
31-
(click)="toggleNav()"
32+
(click)="this.showNav = !this.showNav"
3233
></div>
3334

3435
<div
@@ -42,7 +43,7 @@ <h2 class="text-white text-2xl font-bold mb-6">EventZ</h2>
4243
<li
4344
class="text-white cursor-pointer"
4445
*ngFor="let route of routes"
45-
(click)="toggleNav()"
46+
(click)="toggleNav(route)"
4647
>
4748
{{ route.name }}
4849
</li>

eventz-ui/src/components/navbar/navbar.component.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component, Input, OnInit } from '@angular/core';
1+
import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
22
import { IRoutes } from '../../interfaces/interface';
33
import { CommonModule } from '@angular/common';
44

@@ -12,6 +12,7 @@ import { CommonModule } from '@angular/common';
1212
export class NavbarComponent implements OnInit {
1313
showNav: Boolean = false;
1414
@Input () isLandinPage: boolean = true;
15+
@Output () clickedNavItem = new EventEmitter<IRoutes>();
1516
routes: IRoutes[] = [
1617
{name:'Home', path: 'home'},
1718
{name:'About', path: 'about'},
@@ -42,8 +43,9 @@ export class NavbarComponent implements OnInit {
4243
}
4344
}
4445

45-
toggleNav() {
46+
toggleNav(route: IRoutes) {
4647
this.showNav = !this.showNav;
48+
this.clickedNavItem.emit(route);
4749
}
4850

4951
ngOnDestroy() {

eventz-ui/src/pages/landing/landing.component.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<div>
22
<div class="main w-full h-[80vh] md:h-screen flex flex-col justify-between mb-12">
3-
<app-navbar> </app-navbar>
3+
<app-navbar (clickedNavItem)="handleClickedNavItem($event)"> </app-navbar>
44
<div class="mx-auto w-3/4">
55
<h2 class="text-white text-center text-4xl md:text-6xl font-bold mx-auto">
66
Your Ultimate Destination For Unforgettable
@@ -9,13 +9,13 @@ <h2 class="text-white text-center text-4xl md:text-6xl font-bold mx-auto">
99
</div>
1010
<app-search-form></app-search-form>
1111
</div>
12-
<div class="py-12">
12+
<div class="py-12" id="about">
1313
<app-categories></app-categories>
1414
</div>
1515
<div class="mx-auto">
1616
<app-about></app-about>
1717
</div>
18-
<div class="mx-auto">
18+
<div class="mx-auto" id="events">
1919
<app-events></app-events>
2020
</div>
2121
<div class="mx-auto">
@@ -38,7 +38,7 @@ <h2 class="font-bold text-2xl">Make Your Own Event</h2>
3838
<app-button [backgroundColor]="whiteColor" [color]="deepBlue"></app-button>
3939
</div>
4040
</div>
41-
<div class="mt-4">
41+
<div class="mt-4" id="contact">
4242
<app-contactform></app-contactform>
4343
</div>
4444
<div>

eventz-ui/src/pages/landing/landing.component.ts

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Component, OnInit } from '@angular/core';
2+
import { CommonModule } from '@angular/common';
23
import { NavbarComponent } from "../../components/navbar/navbar.component";
34
import { CategoriesComponent } from "../../components/categories/categories.component";
45
import { AboutComponent } from "../../components/about/about.component";
@@ -9,16 +10,18 @@ import { ContactformComponent } from "../../components/contactform/contactform.c
910
import { FooterComponent } from "../../components/footer/footer.component";
1011
import { SearchFormComponent } from "../../components/search-form/search-form.component";
1112
import { Router } from '@angular/router';
13+
import { IRoutes } from '../../interfaces/interface';
1214

1315
@Component({
1416
selector: 'app-landing',
1517
standalone: true,
16-
imports: [NavbarComponent, CategoriesComponent, AboutComponent, EventsComponent, EventComponent, ButtonComponent, ContactformComponent, FooterComponent, SearchFormComponent],
18+
imports: [CommonModule,NavbarComponent, CategoriesComponent, AboutComponent, EventsComponent, EventComponent, ButtonComponent, ContactformComponent, FooterComponent, SearchFormComponent],
1719
templateUrl: './landing.component.html',
1820
styleUrl: './landing.component.scss'
1921
})
2022
export class LandingComponent implements OnInit {
21-
23+
whiteColor: string = '#fff'
24+
deepBlue: string ='#fff'
2225
constructor (private router: Router) {}
2326
ngOnInit(): void {
2427
if (typeof window !== "undefined") {
@@ -28,6 +31,18 @@ export class LandingComponent implements OnInit {
2831
}
2932
}
3033
}
31-
whiteColor: string = '#fff'
32-
deepBlue: string ='#fff'
34+
35+
handleClickedNavItem(event: IRoutes) {
36+
console.log('Navigating to:', event);
37+
const element = document.getElementById(event.name.toLocaleLowerCase());
38+
if (!element) {
39+
console.warn('Section not found:', event.name);
40+
return;
41+
}
42+
43+
element.scrollIntoView({
44+
behavior: 'smooth',
45+
block: 'start'
46+
});
47+
}
3348
}

0 commit comments

Comments
 (0)