Optimized code (significantly)

This commit is contained in:
ItzMineyy committed 2024-12-28 20:50:18 +01:00
1 parent 5fbb41c477
commit a4b69c5b9a
31 files changed
+343 -441

No files matched your search

+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:7020/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}`
}
});
}
}
+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 = '/api/auth/login'; // Replace with your API endpoint
constructor(private http: HttpClient) {}
login(username: string, password: string): Observable<any> {
return this.http.post(this.apiUrl, { username, password })
.pipe(
tap((response: any) => {
// Store token in localStorage after successful login
if (response.token) {
localStorage.setItem('token', response.token);
}
})
);
}
}
@@ -0,0 +1,24 @@
import {Inject, Injectable, PLATFORM_ID} from '@angular/core';
import {isPlatformBrowser} from '@angular/common';
@Injectable({
providedIn: 'root',
})
export class DeviceDetectorService {
isMobile: boolean = false;
constructor(@Inject(PLATFORM_ID) private platformId: Object) {
this.updateDeviceType();
if (isPlatformBrowser(this.platformId)) {
window.addEventListener('resize', () => this.updateDeviceType());
}
}
private updateDeviceType() {
if (isPlatformBrowser(this.platformId)) {
this.isMobile = window.innerWidth <= 768;
} else {
this.isMobile = false;
}
}
}
@@ -0,0 +1,52 @@
import {Inject, Injectable, PLATFORM_ID} from '@angular/core';
import {isPlatformBrowser} from '@angular/common';
@Injectable({
providedIn: 'root',
})
export class VantaBackgroundService {
private vantaEffect: Map<string, any> = new Map();
constructor(
@Inject(PLATFORM_ID) private platformId: Object,
) {}
initVanta(elementId: string, options?: any) {
if (isPlatformBrowser(this.platformId)) {
const element = document.getElementById(elementId);
if (element && !this.vantaEffect.has(elementId)) {
(window as any).VANTA.NET({
el: element,
mouseControls: false,
touchControls: false,
gyroControls: false,
scale: 1.0,
scaleMobile: 1.0,
points: 20.0,
maxDistance: 25.0,
spacing: 18.0,
showDots: false,
minWidth: window.innerWidth,
minHeight: window.innerHeight,
...(options || {}),
});
element.style.position = 'fixed';
}
}
}
resizeVanta(elementId: string): void {
const effect = this.vantaEffect.get(elementId);
if (effect) {
effect.resize();
}
}
destroyVanta(elementId: string): void {
const effect = this.vantaEffect.get(elementId);
if (effect) {
effect.destroy();
this.vantaEffect.delete(elementId);
}
}
}