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
+446 -19

No files matched your search

+5 -2
View File
@@ -13,6 +13,7 @@
"build": { "build": {
"builder": "@angular-devkit/build-angular:application", "builder": "@angular-devkit/build-angular:application",
"options": { "options": {
"aot": true,
"outputPath": "dist/itzmineydev", "outputPath": "dist/itzmineydev",
"index": "src/index.html", "index": "src/index.html",
"browser": "src/main.ts", "browser": "src/main.ts",
@@ -34,7 +35,8 @@
}, },
"configurations": { "configurations": {
"csr": { "csr": {
"browser": "src/main.ts" "browser": "src/main.ts",
"aot": true
}, },
"ssr": { "ssr": {
"browser": "src/main.ts", "browser": "src/main.ts",
@@ -42,7 +44,8 @@
"outputMode": "server", "outputMode": "server",
"ssr": { "ssr": {
"entry": "src/server.ts" "entry": "src/server.ts"
} },
"aot": true
} }
} }
}, },
+5 -1
View File
@@ -13,11 +13,15 @@ a {
color: inherit; color: inherit;
} }
.height-container {
min-height: 100vh;
align-content: center;
}
.about-container { .about-container {
position: relative; position: relative;
color: white; color: white;
padding: 120px 20px; padding: 120px 20px;
box-shadow: 0px 4px 20px rgba(0, 0, 0, 0.1);
max-width: 960px; max-width: 960px;
margin: 0px auto 0px auto; margin: 0px auto 0px auto;
font-family: 'Roboto', sans-serif; font-family: 'Roboto', sans-serif;
+2 -1
View File
@@ -1,5 +1,5 @@
<div id="vanta-about-bg"></div> <div id="vanta-about-bg"></div>
<div class="height-container">
<div class="about-container"> <div class="about-container">
<ng-container *ngIf="!isMobile; else mobileContainer"> <ng-container *ngIf="!isMobile; else mobileContainer">
<div class="about-header" *ngIf="!isMobile"> <div class="about-header" *ngIf="!isMobile">
@@ -66,3 +66,4 @@
</div> </div>
</div> </div>
</div> </div>
</div>
+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
}
}
+12 -1
View File
@@ -4,7 +4,18 @@ import { provideRouter } from '@angular/router';
import { routes } from './app.routes'; import { routes } from './app.routes';
import { provideAnimationsAsync } from '@angular/platform-browser/animations/async'; import { provideAnimationsAsync } from '@angular/platform-browser/animations/async';
import { provideClientHydration, withEventReplay } from '@angular/platform-browser'; import { provideClientHydration, withEventReplay } from '@angular/platform-browser';
import { provideHttpClient } from '@angular/common/http';
import { AuthService } from './auth.service';
import { AuthInterceptor } from './auth.interceptor';
export const appConfig: ApplicationConfig = { export const appConfig: ApplicationConfig = {
providers: [provideZoneChangeDetection({ eventCoalescing: true }), provideRouter(routes), provideAnimationsAsync(), provideClientHydration(withEventReplay())] providers: [
provideZoneChangeDetection({ eventCoalescing: true }),
provideRouter(routes),
provideAnimationsAsync(),
provideClientHydration(withEventReplay()),
provideHttpClient(),
AuthService,
AuthInterceptor
]
}; };
+8
View File
@@ -20,5 +20,13 @@ export const serverRoutes: ServerRoute[] = [
{ {
path: '**', path: '**',
renderMode: RenderMode.Client, renderMode: RenderMode.Client,
},
{
path: 'admin',
renderMode: RenderMode.Client,
},
{
path: 'login',
renderMode: RenderMode.Client,
} }
] ]
+10
View File
@@ -3,6 +3,8 @@ import { AboutComponent } from './about/about.component';
import { PortfolioComponent } from './portfolio/portfolio.component'; import { PortfolioComponent } from './portfolio/portfolio.component';
import { BlogComponent } from './blog/blog.component'; import { BlogComponent } from './blog/blog.component';
import {NotFoundComponent} from './not-found/not-found.component'; import {NotFoundComponent} from './not-found/not-found.component';
import {LoginComponent} from './login/login.component';
import {AdminComponent} from './admin/admin.component';
export const routes: Routes = [ export const routes: Routes = [
{ {
@@ -49,6 +51,14 @@ export const routes: Routes = [
} }
} }
}, },
{
path: 'login',
component: LoginComponent,
},
{
path: 'admin',
component: AdminComponent,
},
{ {
path: '**', path: '**',
pathMatch: 'full', pathMatch: 'full',
+21
View File
@@ -0,0 +1,21 @@
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs';
@Injectable({
providedIn: 'root'
})
export class ArticleService {
private apiUrl = 'http://localhost:5000/api/articles'; // Replace with your API endpoint
constructor(private http: HttpClient) {}
getArticles(token: string): Observable<any[]> {
return this.http.get<any[]>(this.apiUrl, {
headers: {
'Authorization': `Bearer ${token}`
}
});
}
}
+27
View File
@@ -0,0 +1,27 @@
import { Injectable } from '@angular/core';
import { HttpEvent, HttpHandler, HttpInterceptor, HttpRequest } from '@angular/common/http';
import { Observable } from 'rxjs';
@Injectable()
export class AuthInterceptor implements HttpInterceptor {
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
// Retrieve the token from localStorage
const token = localStorage.getItem('token');
if (token) {
// Clone the request and add the Authorization header
const clonedRequest = req.clone({
setHeaders: {
Authorization: `Bearer ${token}`
}
});
// Pass the cloned request to the next handler
return next.handle(clonedRequest);
}
// If no token, continue without adding the Authorization header
return next.handle(req);
}
}
+25
View File
@@ -0,0 +1,25 @@
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import {Observable, tap} from 'rxjs';
@Injectable({
providedIn: 'root'
})
export class AuthService {
private apiUrl = 'http://localhost:5000/api/auth/login'; // Replace with your API endpoint
constructor(private http: HttpClient) {}
login(username: string, password: string): Observable<any> {
return this.http.post('http://localhost:5000/api/auth/login', { username, password })
.pipe(
tap((response: any) => {
// Store token in localStorage after successful login
if (response.token) {
localStorage.setItem('token', response.token);
}
})
);
}
}
+2 -2
View File
@@ -8,9 +8,9 @@
z-index: -100; /* Place the background behind content */ z-index: -100; /* Place the background behind content */
} }
.container { .height-container {
display: flex; display: flex;
height: 100%; min-height: 100vh;
justify-content: center; justify-content: center;
align-items: center; align-items: center;
text-align: center; text-align: center;
+1 -1
View File
@@ -1,5 +1,5 @@
<div id="vanta-blog-bg"></div> <div id="vanta-blog-bg"></div>
<div class="container" id="container"> <div class="height-container">
<ng-container *ngIf="!isMobile; else mobileError"> <ng-container *ngIf="!isMobile; else mobileError">
<div class="error-message"> <div class="error-message">
<h2>Soon&#8482;</h2> <h2>Soon&#8482;</h2>
+63
View File
@@ -0,0 +1,63 @@
#vanta-login-bg {
transition: opacity 0.3s ease-in-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 {
min-height: 100vh;
align-content: center;
}
/* Login Form Styles */
.login-container {
background: #fff;
border-radius: 8px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
padding: 40px;
width: 300px;
text-align: center;
margin: 0px auto 0px auto;
position: relative;
z-index: 1;
}
h2 {
margin-bottom: 20px;
}
input {
width: 100%;
padding: 10px;
margin: 10px 0;
border: 1px solid #ccc;
border-radius: 4px;
}
button {
width: 100%;
padding: 10px;
background-color: #4CAF50;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
}
button:disabled {
background-color: #ccc;
}
button:hover {
background-color: #45a049;
}
.error-message {
color: red;
font-size: 14px;
margin-top: 10px;
}
+17
View File
@@ -0,0 +1,17 @@
<div id="vanta-login-bg"></div>
<div class="height-container">
<div class="login-container">
<h2>Login</h2>
<form (ngSubmit)="onLogin()" #loginForm="ngForm">
<label for="username">Username:</label>
<input type="text" id="username" name="username" [(ngModel)]="username" required placeholder="Enter your username">
<label for="password">Password:</label>
<input type="password" id="password" name="password" [(ngModel)]="password" required placeholder="Enter your password">
<button type="submit" [disabled]="!loginForm.valid">Login</button>
</form>
<p *ngIf="errorMessage" class="error-message">{{ errorMessage }}</p>
</div>
</div>
+101
View File
@@ -0,0 +1,101 @@
import {Component, OnInit, OnDestroy, AfterViewInit, Inject} from '@angular/core';
import { AuthService } from '../auth.service';
import { Router } from '@angular/router';
import {FormsModule} from '@angular/forms';
import {NgIf} from '@angular/common';
import { HttpClientModule } from '@angular/common/http';
import { isPlatformBrowser } from '@angular/common';
import { PLATFORM_ID } from '@angular/core';
@Component({
selector: 'app-login',
templateUrl: './login.component.html',
styleUrls: ['./login.component.css'],
imports: [
FormsModule,
NgIf,
HttpClientModule
]
})
export class LoginComponent implements OnInit, OnDestroy, AfterViewInit {
username: string = '';
password: string = '';
errorMessage: string = '';
private vantaEffect: any;
constructor(
private authService: AuthService,
private router: Router,
@Inject(PLATFORM_ID) private platformId: Object
) {}
ngOnInit() {
window.addEventListener('resize', this.onResize.bind(this));
const bgElement = document.getElementById('vanta-login-bg');
if (bgElement) {
bgElement.style.position = 'fixed';
}
}
onLogin() {
this.authService.login(this.username, this.password).subscribe(
(response: any) => {
localStorage.setItem('token', response.token);
this.router.navigate(['/admin']); // Redirect to admin page
},
() => {
this.errorMessage = 'Invalid credentials';
}
);
}
ngAfterViewInit() {
if (isPlatformBrowser(this.platformId)) {
// Initialize VANTA effect only in the browser
this.initVanta();
this.resizeVanta();
}
}
ngOnDestroy() {
if (isPlatformBrowser(this.platformId)) {
if (this.vantaEffect) {
this.vantaEffect.destroy(); // Clean up the effect on destroy
}
window.removeEventListener('resize', this.onResize); // Remove the listener when the component is destroyed
}
}
initVanta() {
if (isPlatformBrowser(this.platformId)) {
// Initialize the Vanta effect on the element with ID 'vanta-bg'
this.vantaEffect = window.VANTA.NET({
el: '#vanta-login-bg',
mouseControls: true,
touchControls: true,
gyroControls: false,
scale: 1.00,
scaleMobile: 1.00,
points: 20.00,
maxDistance: 25.00,
spacing: 18.00,
showDots: false,
minWidth: window.innerWidth,
minHeight: window.innerHeight,
});
}
}
onResize() {
// Update the minHeight and minWidth when the window is resized
this.resizeVanta();
}
resizeVanta() {
if (this.vantaEffect) {
// Trigger the resize on the vanta effect
this.vantaEffect.resize();
}
}
}
+3 -3
View File
@@ -8,9 +8,9 @@
z-index: -100; /* Place the background behind content */ z-index: -100; /* Place the background behind content */
} }
.container { .height-container {
display: flex; display: flex;
height: 100%; min-height: 100vh;
justify-content: center; justify-content: center;
align-items: center; align-items: center;
text-align: center; text-align: center;
@@ -38,7 +38,7 @@ button {
padding: 10px 20px; padding: 10px 20px;
font-size: 1rem; font-size: 1rem;
cursor: pointer; cursor: pointer;
border-radius: 5px; border-radius: 25px;
transition: background-color 0.3s; transition: background-color 0.3s;
font-weight: 400; font-weight: 400;
} }
+1 -1
View File
@@ -1,5 +1,5 @@
<div id="vanta-not-found-bg"></div> <div id="vanta-not-found-bg"></div>
<div class="container" id="container"> <div class="height-container">
<div class="error-message"> <div class="error-message">
<h1>404</h1> <h1>404</h1>
<p>Oops! You got lost in space.</p> <p>Oops! You got lost in space.</p>
+8 -2
View File
@@ -17,6 +17,11 @@
font-family: 'Roboto', sans-serif; font-family: 'Roboto', sans-serif;
} }
.height-container {
min-height: 100vh;
align-content: center;
}
.portfolio-header { .portfolio-header {
text-align: center; text-align: center;
} }
@@ -83,9 +88,10 @@
font-weight: 400; font-weight: 400;
} }
.portfolio-footer { .commission-button {
text-align: center; text-align: center;
margin-top: 50px; margin-top: 30px;
margin-bottom: 50px;
} }
.ko-fi-btn { .ko-fi-btn {
+7 -5
View File
@@ -1,4 +1,5 @@
<div id="vanta-portfolio-bg"></div> <div id="vanta-portfolio-bg"></div>
<div class="height-container">
<div class="portfolio-container"> <div class="portfolio-container">
<ng-container *ngIf="!isMobile; else mobileContainer"> <ng-container *ngIf="!isMobile; else mobileContainer">
<div class="portfolio-header" *ngIf="!isMobile"> <div class="portfolio-header" *ngIf="!isMobile">
@@ -18,9 +19,14 @@
I mostly do modern graphic designs since a couple years now, I mostly do modern graphic designs since a couple years now,
but I'm also getting better at coding and you might soon see a couple little coding projects from my <a href="https://github.com/itzminey">GitHub</a> listed here too!<br> but I'm also getting better at coding and you might soon see a couple little coding projects from my <a href="https://github.com/itzminey">GitHub</a> listed here too!<br>
If you like what I do consider following me on my <a href="https://linktr.ee/itzminey">socials</a> and if you feel really generous leave a tip on my <a href="https://ko-fi.com/itzminey">Ko-Fi!</a><br> If you like what I do consider following me on my <a href="https://linktr.ee/itzminey">socials</a> and if you feel really generous leave a tip on my <a href="https://ko-fi.com/itzminey">Ko-Fi!</a><br>
You can also commission me to make designs for you, just click on the button at the end of this page! You can also commission me to make designs for you, just click on the button below!
</p> </p>
</div> </div>
<div class="commission-button">
<a href="https://ko-fi.com/itzminey/commissions" target="_blank">
<button class="ko-fi-btn">Commission me on Ko-Fi</button>
</a>
</div>
<div class="portfolio-gallery"> <div class="portfolio-gallery">
<div class="gallery-item"> <div class="gallery-item">
<img src="/assets/design1.png" alt="Design 1"> <img src="/assets/design1.png" alt="Design 1">
@@ -47,9 +53,5 @@
<p>Logo Design</p> <p>Logo Design</p>
</div> </div>
</div> </div>
<div class="portfolio-footer">
<a href="https://ko-fi.com/itzminey/commissions" target="_blank">
<button class="ko-fi-btn">Commission me on Ko-Fi</button>
</a>
</div> </div>
</div> </div>