Skip to content

Commit 519d17b

Browse files
authored
Refactor SEO meta tag logic and improve contact form UX (#18)
1 parent a0e4323 commit 519d17b

File tree

9 files changed

+175
-174
lines changed

9 files changed

+175
-174
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "personal-website-ui",
3-
"version": "1.8.2",
3+
"version": "1.8.3",
44
"type": "module",
55
"scripts": {
66
"ng": "ng",

src/app/pages/blog-detail/blog-detail.component.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@ export class BlogDetailComponent implements OnInit, OnDestroy {
106106
ngOnDestroy(): void {
107107
this.destroy$.next();
108108
this.destroy$.complete();
109-
this.seoService.setDefaultMetaTags();
110109
}
111110

112111
private incrementViewCount(blogId: string): void {

src/app/pages/contact/contact.component.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Component, OnInit, computed, inject, ChangeDetectionStrategy, ChangeDet
22
import { CommonModule } from '@angular/common';
33
import { FormBuilder, FormGroup, Validators, ReactiveFormsModule } from '@angular/forms';
44
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
5+
import { timer } from 'rxjs';
56
import { PortfolioService } from '../../services/portfolio.service';
67
import { ContactService } from '../../services/contact.service';
78
import { SeoService } from '../../shared/services/seo.service';
@@ -64,8 +65,23 @@ export class ContactComponent implements OnInit {
6465
).subscribe({
6566
next: (response) => {
6667
if (response.success) {
67-
this.contactForm.reset();
68-
this.cdr.markForCheck();
68+
this.contactForm.reset({
69+
name: '',
70+
email: '',
71+
subject: '',
72+
message: ''
73+
});
74+
Object.keys(this.contactForm.controls).forEach(key => {
75+
const control = this.contactForm.get(key);
76+
control?.markAsUntouched();
77+
control?.markAsPristine();
78+
});
79+
timer(3000).pipe(
80+
takeUntilDestroyed(this.destroyRef)
81+
).subscribe(() => {
82+
this.contactService.resetFormState();
83+
this.cdr.markForCheck();
84+
});
6985
} else {
7086
this.cdr.markForCheck();
7187
}

src/app/shared/interceptors/api-key.interceptor.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@ import { isPlatformServer } from '@angular/common';
44
import { environment } from '../../../environments/environment';
55

66
/**
7-
* Interceptor to add API key header for server-side requests (SSR).
8-
* Only adds the header for requests to the configured API endpoints.
7+
* Interceptor to add API key header for SSR requests to admin endpoints only.
8+
* Client-side requests don't need API keys as blog endpoints are public.
99
*/
1010
export const apiKeyInterceptor: HttpInterceptorFn = (req, next) => {
1111

1212
const platformId = inject(PLATFORM_ID);
13+
const isServer = isPlatformServer(platformId);
1314

14-
if (!isPlatformServer(platformId)) {
15+
if (!isServer) {
1516
return next(req);
1617
}
1718

@@ -31,10 +32,16 @@ export const apiKeyInterceptor: HttpInterceptorFn = (req, next) => {
3132
return next(req);
3233
}
3334

34-
const apiKey =
35-
typeof process !== 'undefined'
36-
? process.env?.['API_SERVER_KEY']
37-
: undefined;
35+
// Only add API key for admin blog endpoints (non-GET requests to /blogs)
36+
const isAdminBlogEndpoint = normalizedRequestUrl.includes('/blogs') && req.method !== 'GET';
37+
38+
if (!isAdminBlogEndpoint) {
39+
return next(req);
40+
}
41+
42+
const apiKey = typeof process !== 'undefined'
43+
? (process.env?.['API_SERVER_KEY'] || process.env?.['API_KEY'])
44+
: undefined;
3845

3946
if (apiKey) {
4047
req = req.clone({

src/app/shared/navigation/navigation.component.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666

6767
<!-- Mobile Navigation Menu -->
6868
@if (isMobileMenuOpen()) {
69-
<div
69+
<div
7070
class="mobile-nav-menu-backdrop"
7171
tabindex="0"
7272
role="button"
@@ -75,8 +75,8 @@
7575
(keydown)="onBackdropKeyDown($event)"
7676
></div>
7777
}
78-
<div
79-
class="mobile-nav-menu"
78+
<div
79+
class="mobile-nav-menu"
8080
[class.active]="isMobileMenuOpen()"
8181
(click)="$event.stopPropagation()"
8282
>

0 commit comments

Comments
 (0)