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

+51
View File
@@ -0,0 +1,51 @@
#admin-bg {
transition: opacity 0.3s ease-in-out;
background: #39354a;
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: 8px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
padding: 40px;
width: 350px;
text-align: center;
margin: 50px auto;
}
.height-container {
min-height: 100vh;
align-content: center;
}
.admin-actions button {
background-color: #4CAF50;
color: white;
padding: 12px 20px;
margin: 10px;
border: none;
border-radius: 5px;
cursor: pointer;
}
.admin-actions button:hover {
background-color: #45a049;
}
.articles-list {
margin-top: 20px;
text-align: left;
}
.article {
border: 1px solid #ccc;
padding: 10px;
margin-bottom: 10px;
border-radius: 4px;
}
+21
View File
@@ -0,0 +1,21 @@
<div id="admin-bg"></div>
<div class="height-container">
<div class="admin-container">
<h2>Admin Dashboard</h2>
<div class="admin-actions">
<button (click)="createArticle()">Create Article</button>
<button (click)="viewArticles()">View Articles</button>
<button (click)="logout()">Logout</button>
</div>
<div *ngIf="articles && articles.length > 0">
<h3>Articles</h3>
<div class="articles-list">
<div *ngFor="let article of articles" class="article">
<h4>{{ article.title }}</h4>
<p>{{ article.content }}</p>
</div>
</div>
</div>
</div>
</div>
+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
}
}