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

feat: add loader when navigating between pages #247

Merged
merged 1 commit into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion libs/blog/feature-home/src/lib/blog-home.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ <h2 class="text-xl lg:max-w-2xl">
</dl>
</div>
<a
class="text-accent-base group-hover:text-accent-base flex items-center text-sm dark:text-white dark:group-hover:text-white"
ui-link
[routerLink]="[
'/blog',
(article.createdAt | date: 'YYYY-MM-dd') + '-' + article.slug,
Expand Down
13 changes: 13 additions & 0 deletions libs/shared/layout/src/lib/logo/logo.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<a href="/" class="relative flex items-center">
@if (loading) {
<div class="loader absolute"></div>
}

<img
src="/assets/images/valerymelou.jpg"
class="border-dark rounded-full border-2 dark:border-white"
alt="Valery Melou"
width="40"
height="40"
/>
</a>
21 changes: 21 additions & 0 deletions libs/shared/layout/src/lib/logo/logo.component.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { LogoComponent } from './logo.component';

describe('LogoComponent', () => {
let component: LogoComponent;
let fixture: ComponentFixture<LogoComponent>;

beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [LogoComponent],
}).compileComponents();

fixture = TestBed.createComponent(LogoComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
143 changes: 143 additions & 0 deletions libs/shared/layout/src/lib/logo/logo.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
import { Component } from '@angular/core';
import { CommonModule } from '@angular/common';
import {
NavigationEnd,
NavigationStart,
RouteConfigLoadEnd,
RouteConfigLoadStart,
Router,
} from '@angular/router';

@Component({
selector: 'app-logo',
standalone: true,
imports: [CommonModule],
templateUrl: './logo.component.html',
styles: `
/* HTML: <div class="loader"></div> */
.loader {
width: 40px;
aspect-ratio: 1;
border-radius: 50%;
border: 2px solid #3754ed;
animation:
l20-1 0.8s infinite linear alternate,
l20-2 1.6s infinite linear;
}

@keyframes l20-1 {
0% {
clip-path: polygon(
50% 50%,
0 0,
50% 0%,
50% 0%,
50% 0%,
50% 0%,
50% 0%
);
}
12.5% {
clip-path: polygon(
50% 50%,
0 0,
50% 0%,
100% 0%,
100% 0%,
100% 0%,
100% 0%
);
}
25% {
clip-path: polygon(
50% 50%,
0 0,
50% 0%,
100% 0%,
100% 100%,
100% 100%,
100% 100%
);
}
50% {
clip-path: polygon(
50% 50%,
0 0,
50% 0%,
100% 0%,
100% 100%,
50% 100%,
0% 100%
);
}
62.5% {
clip-path: polygon(
50% 50%,
100% 0,
100% 0%,
100% 0%,
100% 100%,
50% 100%,
0% 100%
);
}
75% {
clip-path: polygon(
50% 50%,
100% 100%,
100% 100%,
100% 100%,
100% 100%,
50% 100%,
0% 100%
);
}
100% {
clip-path: polygon(
50% 50%,
50% 100%,
50% 100%,
50% 100%,
50% 100%,
50% 100%,
0% 100%
);
}
}
@keyframes l20-2 {
0% {
transform: scaleY(1) rotate(0deg);
}
49.99% {
transform: scaleY(1) rotate(135deg);
}
50% {
transform: scaleY(-1) rotate(0deg);
}
100% {
transform: scaleY(-1) rotate(-135deg);
}
}
`,
})
export class LogoComponent {
loading = false;

constructor(router: Router) {
router.events.subscribe({
next: (event) => {
if (
event instanceof NavigationStart ||
event instanceof RouteConfigLoadStart
) {
this.loading = true;
} else if (
event instanceof NavigationEnd ||
event instanceof RouteConfigLoadEnd
) {
this.loading = false;
}
},
});
}
}
10 changes: 1 addition & 9 deletions libs/shared/layout/src/lib/navbar/navbar.component.html
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
<div class="fixed left-0 right-0 top-0 z-10 flex p-5 lg:hidden">
<a href="/" class="flex items-center">
<img
src="/assets/images/valerymelou.jpg"
class="border-dark rounded-full border-2 dark:border-white"
alt="Valery Melou"
width="40"
height="40"
/>
</a>
<app-logo></app-logo>

<button
class="ml-auto items-center text-black dark:text-white"
Expand Down
2 changes: 2 additions & 0 deletions libs/shared/layout/src/lib/navbar/navbar.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {

import { MenuComponent, MenuTriggerForDirective } from '@valerymelou/shared/ui';
import { SocialLinksComponent } from '../social-links/social-links.component';
import { LogoComponent } from '../logo/logo.component';

interface NavbarLink {
label: string;
Expand All @@ -27,6 +28,7 @@ interface NavbarLink {
CommonModule,
RouterModule,
NgIconComponent,
LogoComponent,
MenuComponent,
MenuTriggerForDirective,
SocialLinksComponent,
Expand Down
10 changes: 1 addition & 9 deletions libs/shared/layout/src/lib/social-bar/social-bar.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,7 @@
'lg:dark:bg-dark bg-transparent px-4 lg:bg-white': !isHome,
}"
>
<a href="/" class="flex items-center">
<img
src="/assets/images/valerymelou.jpg"
class="border-dark rounded-full border-2 dark:border-white"
alt="Valery Melou"
width="40"
height="40"
/>
</a>
<app-logo></app-logo>

@if (!isHome) {
<a
Expand Down
2 changes: 2 additions & 0 deletions libs/shared/layout/src/lib/social-bar/social-bar.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {

import { MenuComponent, MenuTriggerForDirective } from '@valerymelou/shared/ui';
import { SocialLinksComponent } from '../social-links/social-links.component';
import { LogoComponent } from '../logo/logo.component';

@Component({
selector: 'app-social-bar',
Expand All @@ -28,6 +29,7 @@ import { SocialLinksComponent } from '../social-links/social-links.component';
CommonModule,
RouterModule,
NgIconComponent,
LogoComponent,
MenuTriggerForDirective,
MenuComponent,
SocialLinksComponent,
Expand Down
3 changes: 3 additions & 0 deletions nx.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@
"@nx/angular:library": {
"linter": "eslint",
"unitTestRunner": "jest"
},
"@nx/angular:component": {
"style": "none"
}
},
"plugins": [
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
"skipDefaultLibCheck": true,
"baseUrl": ".",
"paths": {
"@valerymelou/blog-tasks": ["libs/blog/tasks/src/index.ts"],
"@valerymelou/blog/article": ["libs/blog/feature-article/src/index.ts"],
"@valerymelou/blog/data-access": ["libs/blog/data-access/src/index.ts"],
"@valerymelou/blog/home": ["libs/blog/feature-home/src/index.ts"],
"@valerymelou/blog-tasks": ["libs/blog/tasks/src/index.ts"],
"@valerymelou/cms/contentful": ["libs/cms/contentful/src/index.ts"],
"@valerymelou/common/browser": ["libs/common/browser/src/index.ts"],
"@valerymelou/pages/about": ["libs/pages/about/src/index.ts"],
Expand Down