Added backend request logic & admin page placeholders, along with some tweaks to frontend design

This commit is contained in:
ItzMineyy committed 2024-12-28 12:43:11 +01:00
1 parent 696181a772
commit 0907f0b66b
21 files changed
+447 -20

No files matched your search

+56
View File
@@ -0,0 +1,56 @@
import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';
import { ArticleService } from '../article.service';
import {NgFor, NgIf} from '@angular/common';
import { HttpClientModule } from '@angular/common/http';
@Component({
selector: 'app-admin',
templateUrl: './admin.component.html',
styleUrls: ['./admin.component.css'],
imports: [
NgIf,
NgFor,
HttpClientModule
]
})
export class AdminComponent implements OnInit {
articles: any[] = [];
constructor(private articleService: ArticleService, private router: Router) {}
ngOnInit() {
this.fetchArticles();
}
// Fetch articles from backend
fetchArticles() {
const token = localStorage.getItem('token');
if (!token) {
this.router.navigate(['/login']); // Redirect to login if not logged in
return;
}
this.articleService.getArticles(token).subscribe(
(data) => {
this.articles = data;
},
(error) => {
console.error('Failed to load articles', error);
}
);
}
createArticle() {
alert('Create article functionality goes here');
}
viewArticles() {
this.fetchArticles();
}
logout() {
localStorage.removeItem('token');
this.router.navigate(['/login']); // Redirect to login page
}
}