From a4c0898be8c7e6f99a170d6f7f2e98af601d6453 Mon Sep 17 00:00:00 2001 From: itzMiney Date: Sat, 15 Mar 2025 22:15:59 +0100 Subject: [PATCH] Fixed some styling and token validation issues --- src/app/admin/admin.component.ts | 2 ++ src/app/shortener/shortener.component.css | 24 +++++++------------- src/app/shortener/shortener.component.ts | 27 ++++++++++++++++++++--- 3 files changed, 34 insertions(+), 19 deletions(-) diff --git a/src/app/admin/admin.component.ts b/src/app/admin/admin.component.ts index c1ddc0d..bf176a5 100644 --- a/src/app/admin/admin.component.ts +++ b/src/app/admin/admin.component.ts @@ -75,11 +75,13 @@ export class AdminComponent implements OnInit, OnDestroy { (isValid: boolean) => { if (!isValid) { console.warn('Token is no longer valid. Logging out.'); + localStorage.removeItem('token'); this.navigateToLogin(); } }, (error) => { console.error('Error validating token:', error); + localStorage.removeItem('token'); this.navigateToLogin(); } ); diff --git a/src/app/shortener/shortener.component.css b/src/app/shortener/shortener.component.css index 5a1e75b..f3a9bf8 100644 --- a/src/app/shortener/shortener.component.css +++ b/src/app/shortener/shortener.component.css @@ -1,21 +1,14 @@ -/* Make the body fill the entire height of the viewport */ -body, html { - height: 100%; - margin: 0; -} - -/* Flexbox to center the container */ .container { display: flex; flex-direction: column; - justify-content: center; + justify-content: flex-start; align-items: center; min-width: 300px; padding: 25px; background-color: #ffffff; border-radius: 35px; box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1); - max-height: 80vh; + max-height: 90vh; overflow: scroll; } @@ -28,7 +21,7 @@ body, html { } h1 { - margin-top: 60px; + margin-top: 40px; text-align: center; color: #333; } @@ -89,11 +82,6 @@ button:hover { opacity: 0.9; } -/* List styling */ -.url-list { - margin-top: 40px; -} - .url-list-items { list-style-type: none; padding: 0; @@ -102,12 +90,16 @@ button:hover { .url-list-items li { background-color: #fff; padding: 10px 15px; - margin-bottom: 10px; + row-gap: 10px; border: 1px solid #ddd; border-radius: 20px; line-height: 1.5rem; } +li + li { + margin-top: 10px; +} + .url-list-items a { color: #007bff; text-decoration: none; diff --git a/src/app/shortener/shortener.component.ts b/src/app/shortener/shortener.component.ts index 4f70a6b..f9cb760 100644 --- a/src/app/shortener/shortener.component.ts +++ b/src/app/shortener/shortener.component.ts @@ -1,11 +1,11 @@ import { Component, OnInit } from '@angular/core'; import {Title} from '@angular/platform-browser'; import {Router} from '@angular/router'; -import {UserService} from '../shared/services/user.service'; import {ShortenerService} from '../shared/services/shortener.service'; -import {Observer} from 'rxjs'; +import {interval, Observer, Subscription} from 'rxjs'; import {FormsModule} from '@angular/forms'; import {NgFor, NgIf, SlicePipe} from '@angular/common'; +import {AuthService} from '../shared/services/auth.service'; @Component({ selector: 'app-shortener', @@ -27,11 +27,12 @@ export class ShortenerComponent implements OnInit { og_url: string = ''; short_name: string | null = null; deleteId: number | null = null; + tokenValidationInterval: Subscription = new Subscription(); constructor( private shortenerService: ShortenerService, - private userService: UserService, private router: Router, + private authService: AuthService, private titleService: Title ) {} @@ -39,6 +40,26 @@ export class ShortenerComponent implements OnInit { this.titleService.setTitle('Shortener | itzMiney') this.checkToken() this.loadURLs(); + this.startTokenValidation(); + } + + startTokenValidation() { + this.tokenValidationInterval = interval(300000).subscribe(() => { + this.authService.isTokenValid(this.token).subscribe( + (isValid: boolean) => { + if (!isValid) { + console.warn('Token is no longer valid. Logging out.'); + localStorage.removeItem('token'); + this.navigateToLogin(); + } + }, + (error) => { + console.error('Error validating token:', error); + localStorage.removeItem('token'); + this.navigateToLogin(); + } + ); + }); } checkToken() {