diff --git a/src/app/admin/admin.component.css b/src/app/admin/admin.component.css index 52a9552..fd0c626 100644 --- a/src/app/admin/admin.component.css +++ b/src/app/admin/admin.component.css @@ -4,27 +4,67 @@ position: fixed; top: 0; left: 0; - width: 100vw; /* Full viewport width */ - height: 100vh; /* Full viewport height */ - z-index: -100; /* Place the background behind content */ -} - -.admin-container { - background: #fff; - border-radius: 25px; - box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1); - padding: 40px; - width: 350px; - text-align: center; - margin: 50px auto; + width: 100vw; + height: 100vh; + z-index: -100; } .height-container { - min-height: 100vh; - align-content: center; + display: flex; + justify-content: space-between; + align-items: center; + height: 100vh; + width: 100vw; } -.admin-actions button { +.center-section, +.left-section, +.right-section { + display: flex; + flex-direction: column; + justify-content: center; + align-items: center; + width: 33.33%; + padding: 30px; + height: auto; + box-sizing: border-box; +} + +.admin-dashboard-tile, +.create-article-tile, +.articles-list-tile { + background: #fff; + border-radius: 25px; + box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1); + padding: 20px; + text-align: center; + max-width: 400px; + width: 100%; +} + +.admin-dashboard-tile, +.create-article-tile { + margin-bottom: 30px; + display: flex; + flex-direction: column; + justify-content: space-between; +} + +.articles-list-tile { + overflow-y: auto; + max-width: 300px; +} + +input, +textarea { + width: 90%; + padding: 10px; + margin: 10px 0; + border: 1px solid #ccc; + border-radius: 25px; +} + +.admin-actions button, .create-article-tile button { background-color: #bd3948; color: white; padding: 12px 20px; @@ -34,11 +74,11 @@ cursor: pointer; } -.admin-actions button:hover { +.admin-actions button:hover, .create-article-tile button:hover { background-color: #e3485a; } -.logout button { +.admin-actions button.logout { background-color: #713252; color: white; padding: 12px 20px; @@ -48,18 +88,37 @@ cursor: pointer; } -.logout button:hover { +.admin-actions button.logout:hover { background-color: #592840; } -.articles-list { - margin-top: 20px; - text-align: left; +.articles-list-tile ul { + list-style-type: none; + padding: 0; + overflow-y: auto; + max-height: 100%; } -.article { +.articles-list-tile li { border: 1px solid #ccc; padding: 10px; margin-bottom: 10px; - border-radius: 4px; + border-radius: 25px; +} + +.articles-list-tile li:last-child { + margin-bottom: 0; +} + +.articles-list-tile h2 { + margin-bottom: 30px; +} + +.articles-list-tile { + padding-bottom: 5px; +} + +textarea { + resize: none; + min-height: 100px; } diff --git a/src/app/admin/admin.component.html b/src/app/admin/admin.component.html index 1c0b31d..c09cb97 100644 --- a/src/app/admin/admin.component.html +++ b/src/app/admin/admin.component.html @@ -1,29 +1,52 @@ -
-
-
-

Admin Dashboard

-
- - - - -
+
+
+ +
+ +
-
-

No articles available.

-
+ +
+
+

Admin Dashboard

+
+ + + +
+
-
-
    -
  • - - {{ article.title }} -
  • -
-
+
+

Create New Article

+
+
+ + +
+
+ + +
+ +
+
+
-
- + +
+
+

Articles

+
+

No articles available.

+
+
+
    +
  • + ID {{ article.id }} - {{ article.title }} +
  • +
+
+
+
-
diff --git a/src/app/admin/admin.component.ts b/src/app/admin/admin.component.ts index e5d75b0..afe3c18 100644 --- a/src/app/admin/admin.component.ts +++ b/src/app/admin/admin.component.ts @@ -3,6 +3,7 @@ import {Router} from '@angular/router'; import {ArticleService} from '../services/article.service'; import {NgFor, NgIf} from '@angular/common'; import {Observer} from 'rxjs'; +import {FormsModule} from '@angular/forms'; @Component({ selector: 'app-admin', @@ -10,72 +11,33 @@ import {Observer} from 'rxjs'; styleUrls: ['./admin.component.css'], imports: [ NgIf, - NgFor + NgFor, + FormsModule, ] }) export class AdminComponent implements OnInit { articles: any[] = []; noArticles: boolean = false; - constructor(private articleService: ArticleService, private router: Router) {} + title: string = ''; + content: string = ''; + token: string | null = localStorage.getItem('token'); - ngOnInit() { - this.fetchArticles(); - } + constructor( + private articleService: ArticleService, + private router: Router + ) {} // Fetch articles from backend - fetchArticles() { - const token = localStorage.getItem('token'); - if (!token) { - this.router.navigate(['/login']).then( - (success) => { - if (success) { - console.log('Navigation to login succeeded'); - } else { - console.warn('Navigation to login failed'); - } - }, - (error) => { - console.error('Navigation error:', error); - } - ); + ngOnInit() { + if (!this.token) { + this.navigateToLogin(); return; } - - const articleObserver: Observer = { - next: (data) => { - this.articles = data; - this.noArticles = this.articles.length === 0; - }, - error: (error) => { - console.error('Failed to load articles', error); - }, - complete: () => { - console.log('Article loading complete'); - } - }; - - this.articleService.getArticles(token).subscribe(articleObserver); + this.loadArticles() } - createArticle() { - alert('Create article functionality goes here'); - } - - editArticle() { - alert('Delete article functionality goes here'); - } - - deleteArticle() { - alert('Delete article functionality goes here'); - } - - viewArticles() { - this.fetchArticles(); - } - - logout() { - localStorage.removeItem('token'); + navigateToLogin() { this.router.navigate(['/login']).then( (success) => { if (success) { @@ -89,4 +51,120 @@ export class AdminComponent implements OnInit { } ); } + + createArticle() { + if (!this.token) { + this.navigateToLogin(); + return; + } + + if (!this.title || !this.content) { + alert('Both title and content are required!'); + return; + } + + this.articleService.postArticle(this.token, this.title, this.content).subscribe( + (response) => { + alert('Article created successfully!'); + this.loadArticles(); + console.log(response); // You can log the response or take further actions like redirecting + }, + (error) => { + alert('Error creating article'); + console.error(error); // Log the error for debugging + } + ); + } + + editArticle(): void { + if (!this.token) { + this.navigateToLogin(); + return; + } + + const articleId = prompt('Enter the article ID to edit:'); + + if (articleId && !isNaN(Number(articleId))) { + const id = Number(articleId); + + // Fetch the current article to get existing values + this.articleService.getArticleById(id).subscribe( + (article) => { + if (!article) { + alert(`Article with ID ${id} not found.`); + return; + } + + // Prompt for title and content with placeholders + const newTitle = prompt('Enter the new title (Leave blank to leave as is):'); + const newContent = prompt('Enter the new content (Leave blank to leave as is):'); + + // Use current values if left blank + const updatedTitle = newTitle?.trim() || article.title; + const updatedContent = newContent?.trim() || article.content; + + this.articleService.editArticle(id, this.token, updatedTitle, updatedContent).subscribe( + (response) => { + alert(`Article ${id} updated successfully!`); + console.log('Updated Article:', response); + this.loadArticles(); + }, + (error) => { + alert(`Error updating article ${id}: ${error.message}`); + } + ); + }, + (error: { message: any; }) => { + alert(`Failed to fetch article with ID ${id}: ${error.message}`); + } + ); + } else { + alert('Invalid input. Please enter a valid article ID.'); + } + } + + deleteArticle(): void { + if (!this.token) { + this.navigateToLogin(); + return; + } + const articleId = prompt('Enter the article ID to delete:'); + + if (articleId && !isNaN(Number(articleId))) { + const id = Number(articleId); + + this.articleService.deleteArticle(id, this.token).subscribe( + () => { + alert(`Article ${id} deleted successfully`); + this.loadArticles(); + }, + (error) => { + alert(`Error deleting article ${id}: ${error.message}`); + } + ); + } else { + alert('Invalid input. Please enter a valid article ID.'); + } + } + + loadArticles(): void { + const articleObserver: Observer = { + next: (data) => { + this.articles = data; + this.noArticles = this.articles.length === 0; + }, + error: (error) => { + console.error('Failed to load articles', error); + }, + complete: () => { + console.log('Article loading complete'); + } + }; + this.articleService.getAllArticles().subscribe(articleObserver); + } + + logout() { + localStorage.removeItem('token'); + this.navigateToLogin(); + } } diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 61184e9..a09f5d1 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -4,9 +4,9 @@ import {ActivatedRoute, NavigationEnd, Router, RouterOutlet} from '@angular/rout import {NavbarComponent} from './navbar/navbar.component'; import {MobileNavbarComponent} from './mobile-navbar/mobile-navbar.component'; import {FooterComponent} from './footer/footer.component'; -import {Meta, Title} from '@angular/platform-browser'; import {filter, map, mergeMap} from 'rxjs/operators'; import {DeviceDetectorService} from './services/device-detector.service'; +import { UpdateMetaService } from './services/update-meta.service'; @Component({ selector: 'app-root', @@ -22,9 +22,8 @@ export class AppComponent implements OnInit { constructor( private router: Router, private activatedRoute: ActivatedRoute, - private titleService: Title, - private metaService: Meta, private deviceService: DeviceDetectorService, + private updateMetaService: UpdateMetaService, ) {} ngOnInit() { @@ -50,31 +49,11 @@ export class AppComponent implements OnInit { meta.url = meta.url || 'https://itzminey.dev'; meta.color = meta.color || '#eb284c'; } - this.updateMetaTags(meta); + this.updateMetaService.updateMetaTags(meta); this.checkRoute(); }); } - updateMetaTags(meta: { title?: string; description?: string; image?: string; url?: string; color?: string }) { - if (meta.title) { - this.titleService.setTitle(meta.title); - this.metaService.updateTag({ name: 'og:title', content: meta.title }); - } - if (meta.description) { - this.metaService.updateTag({ name: 'description', content: meta.description }); - this.metaService.updateTag({ name: 'og:description', content: meta.description }); - } - if (meta.image) { - this.metaService.updateTag({ name: 'og:image', content: meta.image }); - } - if (meta.url) { - this.metaService.updateTag({ name: 'og:url', content: meta.url }); - } - if (meta.color) { - this.metaService.updateTag({ name: 'theme-color', content: meta.color}); - } - } - checkRoute() { const currentRoute = this.activatedRoute.snapshot.firstChild?.routeConfig?.path; diff --git a/src/app/app.routes.server.ts b/src/app/app.routes.server.ts index 1f8a520..9a1058c 100644 --- a/src/app/app.routes.server.ts +++ b/src/app/app.routes.server.ts @@ -17,6 +17,10 @@ export const serverRoutes: ServerRoute[] = [ path: 'blog', renderMode: RenderMode.Prerender, }, + { + path: 'blog/:slug', + renderMode: RenderMode.Client, + }, { path: 'admin', renderMode: RenderMode.Client, diff --git a/src/app/app.routes.ts b/src/app/app.routes.ts index e2dfd2c..59a2f1a 100644 --- a/src/app/app.routes.ts +++ b/src/app/app.routes.ts @@ -5,6 +5,7 @@ import {BlogComponent} from './blog/blog.component'; import {NotFoundComponent} from './not-found/not-found.component'; import {LoginComponent} from './login/login.component'; import {AdminComponent} from './admin/admin.component'; +import {ArticlePageComponent} from './article-page/article-page.component'; export const routes: Routes = [ { @@ -77,6 +78,9 @@ export const routes: Routes = [ } } }, + { + path: 'blog/:slug', + component: ArticlePageComponent }, { path: '**', pathMatch: 'full', diff --git a/src/app/article-page/article-page.component.css b/src/app/article-page/article-page.component.css new file mode 100644 index 0000000..29bf354 --- /dev/null +++ b/src/app/article-page/article-page.component.css @@ -0,0 +1,114 @@ +@keyframes fadeIn { + 0% { + opacity: 0; + visibility: hidden; + } + 100% { + opacity: 1; + visibility: visible; + } +} + +#vanta-article-bg { + animation: fadeIn 1s ease-out; + position: fixed; + top: 0; + left: 0; + width: 100vw; /* Full viewport width */ + height: 100vh; /* Full viewport height */ + z-index: -100; /* Place the background behind content */ +} +.height-container { + display: flex; + min-height: 100vh; + justify-content: center; + align-items: center; + text-align: center; + z-index: 10; +} + +.article-container { + z-index: 1; + width: 100%; + min-height: 100vh; + background: linear-gradient(to bottom, rgba(0, 0, 0, 0.3) 50%, rgb(0, 0, 0) 100%); + padding: 30px; + justify-items: center; + align-items: center; +} + +.content-container { + display: inline-grid; + max-width: 960px; +} + +h1 { + font-size: 2.5rem; + color: #fff; + margin-top: 120px; + margin-bottom: 40px; + font-weight: 600; +} + +.article-content { + font-size: 1.2rem; + color: #fff; + line-height: 1.8; /* Improve readability */ + margin-bottom: 30px; +} + +.article-meta { + font-size: 1rem; + color: #e6e6e6; + text-align: left; +} + +.article-meta p { + margin: 8px 0; +} + +.content-container button { + background-color: #713252; + color: #fff; + border: none; + padding: 10px 20px; + font-size: 1rem; + cursor: pointer; + border-radius: 25px; + transition: background-color 0.3s; + font-weight: 400; +} + +.content-container button:hover { + background-color: #bf9bae; +} + +.error-message h1 { + font-size: 10rem; + margin: 0; + font-weight: 700; + color: white; +} + +.error-message p { + font-size: 1.5rem; + margin: 20px 0; + font-weight: 400; + color: white; +} + +.error-message button { + background-color: #713252; + color: #fff; + border: none; + padding: 10px 20px; + font-size: 1rem; + cursor: pointer; + border-radius: 25px; + transition: background-color 0.3s; + font-weight: 400; +} + +.error-message button:hover { + background-color: #bf9bae; +} diff --git a/src/app/article-page/article-page.component.html b/src/app/article-page/article-page.component.html new file mode 100644 index 0000000..45535a5 --- /dev/null +++ b/src/app/article-page/article-page.component.html @@ -0,0 +1,30 @@ +
+
+
+
+ +

{{ article.title }}

+
+ +
+ + + + +
+
+
+ + +
+

404

+

Article not found!

+ +
+
+
diff --git a/src/app/article-page/article-page.component.ts b/src/app/article-page/article-page.component.ts new file mode 100644 index 0000000..3775371 --- /dev/null +++ b/src/app/article-page/article-page.component.ts @@ -0,0 +1,130 @@ +import {AfterViewInit, Component, Inject, OnDestroy, OnInit, PLATFORM_ID} from '@angular/core'; +import {DeviceDetectorService} from '../services/device-detector.service' +import {DatePipe, isPlatformBrowser, NgIf} from '@angular/common'; +import {VantaBackgroundService} from '../services/vanta-background.service'; +import {ArticleService} from '../services/article.service'; +import {ActivatedRoute} from '@angular/router'; +import {UpdateMetaService} from '../services/update-meta.service'; + +interface Article { + id: number; + title: string; + slug: string; + content: string; + createdAt: string; + updatedAt: string; + views: number; + authorId: number; + authorName: string; +} + +@Component({ + selector: 'app-article-page', + imports: [ + NgIf, + DatePipe + ], + templateUrl: './article-page.component.html', + styleUrl: './article-page.component.css' +}) +export class ArticlePageComponent implements OnInit, OnDestroy, AfterViewInit { + private readonly elementId = 'vanta-article-bg'; + isMobile: boolean = false; + article: Article | undefined; + currentArticle: any; + constructor( + private deviceService: DeviceDetectorService, + private vantaService: VantaBackgroundService, + private articleService: ArticleService, + private updateMetaService: UpdateMetaService, + private route: ActivatedRoute, + @Inject(PLATFORM_ID) private platformId: Object + ) { + } + + ngOnInit() { + this.isMobile = this.deviceService.isMobile; + + this.route.params.subscribe((params) => { + const slug = params['slug']; + if (slug) { + this.loadArticleMetaBySlug(slug); + } else { + this.updateMetaService.updateMetaTags({ + title: 'Article | itzMiney', + description: 'An article on itzMiney\'s Blog.', + image: 'https://itzminey.dev/assets/ogimg.png', + url: 'https://itzminey.dev/blog', + color: '#ffffff' + }); + } + }); + + if (isPlatformBrowser(this.platformId)) { + window.addEventListener('resize', this.onResize.bind(this)); + } + const slug = this.route.snapshot.paramMap.get('slug') || ''; + this.articleService.getArticleBySlug(slug).subscribe( + (article) => { + this.article = article; + console.log('Article found!') + }, + (error) => { + console.error('Error fetching article:', error); + } + ); + } + + ngAfterViewInit() { + this.vantaService.initVanta(this.elementId, { + color: 0xac1f4e, + backgroundColor: 0x191522 + }); + } + ngOnDestroy() { + this.vantaService.destroyVanta(this.elementId); + if (isPlatformBrowser(this.platformId)) { + window.removeEventListener('resize', this.onResize); + } + } + + onResize() { + this.vantaService.resizeVanta(this.elementId); + } + + loadArticleMetaBySlug(slug: string) { + this.articleService.getArticleBySlug(slug).subscribe( + (article) => { + if (article) { + this.currentArticle = article; + this.updateMetaService.updateMetaTags({ + title: article.title, + description: article.content.slice(0, 150), // First 150 characters + image: 'https://itzminey.dev/assets/ogimg.png', // Use article image or default + url: `https://itzminey.dev/blog/${article.slug}`, + color: '#ffffff' + }); + } else { + console.warn('Article not found for slug:', slug); + this.updateMetaService.updateMetaTags({ + title: 'Article Not Found', + description: 'The requested article could not be found.', + image: 'https://itzminey.dev/assets/ogimg.png', + url: 'https://itzminey.dev', + color: '#ff0000' + }); + } + }, + (error) => { + console.error('Failed to load article metadata', error); + this.updateMetaService.updateMetaTags({ + title: 'Error', + description: 'An error occurred while loading this article.', + image: 'https://itzminey.dev/assets/ogimg.png', + url: 'https://itzminey.dev', + color: '#ff0000' + }); + } + ); + } +} diff --git a/src/app/blog/blog.component.css b/src/app/blog/blog.component.css index ed6d03f..2580142 100644 --- a/src/app/blog/blog.component.css +++ b/src/app/blog/blog.component.css @@ -28,30 +28,35 @@ z-index: 10; /* Ensure the text and button are above the canvas */ } -.error-message h2 { - font-size: 10rem; - margin: 0; - font-weight: 700; - color: white; +.blog-container { + max-width: 900px; + margin-top: 120px; + margin-bottom: 80px; + padding: 20px; } -.error-message p { - font-size: 1.5rem; - margin: 20px 0; - font-weight: 400; - color: white; +.article-card { + z-index: 10; + background: linear-gradient(135deg, #9c27b0, #6200ea); + padding: 15px; + margin: 25px 0; + cursor: pointer; + border-radius: 45px; + box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1); + transition: background-color 0.3s, transform 0.2s; } -.error-message-mobile h2 { - font-size: 4.0rem; - margin: 0; - font-weight: 500; - color: white; +.article-card:hover { + background: linear-gradient(135deg, #b737cd, #773ec6); + transform: translateY(-5px); } -.error-message-mobile p { - font-size: 1.2rem; - margin: 10px 0; - font-weight: 400; - color: white; +h2 { + font-size: 1.6rem; + color: #ffffff; +} + +p { + font-size: 1rem; + color: #dcdcdc; } diff --git a/src/app/blog/blog.component.html b/src/app/blog/blog.component.html index 837af9b..fa2512f 100644 --- a/src/app/blog/blog.component.html +++ b/src/app/blog/blog.component.html @@ -1,15 +1,15 @@
- -
-

Soon™

-

Under Construction!

+
+
+
+

{{ (article.title | slice:0:45) + (article.title.length > 40 ? '...' : '')}}

+

{{ (article.content | slice:0:80) + (article.content.length > 80 ? '...' : '')}}

+

By {{ article.authorName }} | {{ article.createdAt | date: 'short' }}

+
+
- - -
-

Soon™

-

Under Construction!

-
-
+ +

No Articles yet!

+
diff --git a/src/app/blog/blog.component.ts b/src/app/blog/blog.component.ts index 649a1cf..92fd295 100644 --- a/src/app/blog/blog.component.ts +++ b/src/app/blog/blog.component.ts @@ -1,31 +1,45 @@ import {AfterViewInit, Component, Inject, OnDestroy, OnInit, PLATFORM_ID} from '@angular/core'; import {DeviceDetectorService} from '../services/device-detector.service' -import {isPlatformBrowser, NgIf} from '@angular/common'; +import {DatePipe, isPlatformBrowser, NgIf, NgFor, AsyncPipe, SlicePipe} from '@angular/common'; import {VantaBackgroundService} from '../services/vanta-background.service'; +import { ArticleService } from '../services/article.service'; +import { Router } from '@angular/router'; +import {Observable} from 'rxjs'; @Component({ selector: 'app-blog', imports: [ - NgIf + NgIf, + NgFor, + DatePipe, + AsyncPipe, + SlicePipe ], templateUrl: './blog.component.html', styleUrl: './blog.component.css' }) export class BlogComponent implements OnInit, OnDestroy, AfterViewInit { + articles$: Observable | undefined; private readonly elementId = 'vanta-blog-bg'; isMobile: boolean = false; constructor( private deviceService: DeviceDetectorService, private vantaService: VantaBackgroundService, + private articleService: ArticleService, + private router: Router, @Inject(PLATFORM_ID) private platformId: Object - ) { - } + ) {} ngOnInit() { this.isMobile = this.deviceService.isMobile; if (isPlatformBrowser(this.platformId)) { window.addEventListener('resize', this.onResize.bind(this)); } + this.articles$ = this.articleService.getAllArticles(); + } + + navigateToArticle(slug: string): void { + this.router.navigate([`/blog/${slug}`]); } ngAfterViewInit() { diff --git a/src/app/navbar/navbar.component.ts b/src/app/navbar/navbar.component.ts index 5429755..1675cf4 100644 --- a/src/app/navbar/navbar.component.ts +++ b/src/app/navbar/navbar.component.ts @@ -1,7 +1,7 @@ import {Component, OnInit} from '@angular/core'; import {NavigationEnd, Router, RouterLink} from '@angular/router'; import {DeviceDetectorService} from 'ngx-device-detector'; -import {NgIf} from '@angular/common'; +import {filter} from 'rxjs/operators'; @Component({ selector: 'app-navbar', @@ -19,11 +19,16 @@ export class NavbarComponent implements OnInit { this.isMobile = this.deviceService.isMobile(); } - ngOnInit() { - // Listen to route changes - this.router.events.subscribe((event) => { - if (event instanceof NavigationEnd) { - this.activeLink = event.urlAfterRedirects; // Capture the active route + ngOnInit(): void { + this.router.events.pipe( + filter(event => event instanceof NavigationEnd) + ).subscribe(() => { + // Update activeLink based on current route + const currentRoute = this.router.url; + if (currentRoute.startsWith('/blog')) { + this.activeLink = '/blog'; + } else { + this.activeLink = currentRoute; } }); } diff --git a/src/app/services/article.service.ts b/src/app/services/article.service.ts index 57752ec..0520391 100644 --- a/src/app/services/article.service.ts +++ b/src/app/services/article.service.ts @@ -1,21 +1,70 @@ import {Injectable} from '@angular/core'; -import {HttpClient} from '@angular/common/http'; +import {HttpClient, HttpHeaders} from '@angular/common/http'; import {Observable} from 'rxjs'; +import { map } from 'rxjs/operators'; + +interface Article { + id: number; + title: string; + slug: string; + content: string; + createdAt: string; + updatedAt: string; + views: number; + authorId: number; + authorName: string; +} @Injectable({ providedIn: 'root' }) export class ArticleService { - private apiUrl = 'http://localhost:7020/api/articles'; // Replace with your API endpoint + private apiUrl = '/api/articles'; constructor(private http: HttpClient) {} - getArticles(token: string): Observable { - return this.http.get(this.apiUrl, { + getAllArticles(): Observable { + return this.http.get(this.apiUrl); + } + + getArticleBySlug(slug: string): Observable
{ + return this.http.get(this.apiUrl).pipe( + map((articles) => articles.find((article) => article.slug === slug)) + ); + } + + getArticleById(id: number): Observable
{ + return this.http.get(this.apiUrl).pipe( + map((articles) => articles.find((article) => article.id === id)) + ); + } + + postArticle(token: string, title: string, content: string ): Observable { + return this.http.post(this.apiUrl, { + title, + content + },{ headers: { 'Authorization': `Bearer ${token}` } }); } + + deleteArticle(id: number, token: string): Observable { + const headers = new HttpHeaders().set('Authorization', `Bearer ${token}`); + return this.http.delete(`${this.apiUrl}/${id}`, { headers }).pipe( + map((response) => { + // If the backend responds successfully, return true + return !!(response && response.message === 'Article deleted'); + }) + ); + } + + editArticle(id: number, token: string | null, title: string, content: string): Observable { + const headers = new HttpHeaders().set('Authorization', `Bearer ${token}`); + const body = { title, content }; + + return this.http.put(`${this.apiUrl}/${id}`, body, { headers }); + } } diff --git a/src/app/services/auth.service.ts b/src/app/services/auth.service.ts index b84c7b0..7f8b92e 100644 --- a/src/app/services/auth.service.ts +++ b/src/app/services/auth.service.ts @@ -7,7 +7,7 @@ import {Observable, tap} from 'rxjs'; }) export class AuthService { - private apiUrl = '/api/auth/login'; // Replace with your API endpoint + private apiUrl = '/api/auth/login'; constructor(private http: HttpClient) {} diff --git a/src/app/services/update-meta.service.ts b/src/app/services/update-meta.service.ts new file mode 100644 index 0000000..b7e0a6f --- /dev/null +++ b/src/app/services/update-meta.service.ts @@ -0,0 +1,31 @@ +import { Injectable } from '@angular/core'; +import { Title } from '@angular/platform-browser'; +import { Meta } from '@angular/platform-browser'; + +@Injectable({ + providedIn: 'root' +}) +export class UpdateMetaService { + + constructor(private titleService: Title, private metaService: Meta) {} + + updateMetaTags(meta: { title?: string; description?: string; image?: string; url?: string; color?: string }) { + if (meta.title) { + this.titleService.setTitle(meta.title); + this.metaService.updateTag({ name: 'og:title', content: meta.title }); + } + if (meta.description) { + this.metaService.updateTag({ name: 'description', content: meta.description }); + this.metaService.updateTag({ name: 'og:description', content: meta.description }); + } + if (meta.image) { + this.metaService.updateTag({ name: 'og:image', content: meta.image }); + } + if (meta.url) { + this.metaService.updateTag({ name: 'og:url', content: meta.url }); + } + if (meta.color) { + this.metaService.updateTag({ name: 'theme-color', content: meta.color }); + } + } +}