Add loading page when starting the app + fix electron refresh error

This commit is contained in:
X4Lo committed 2024-10-21 16:08:27 +01:00
1 parent 0b1a1d989f
commit 31d38d8da9
13 files changed
+397 -50

No files matched your search

+90
View File
@@ -0,0 +1,90 @@
.overlay {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: #eff1f3;
color: var(--shz-blue-default);
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
z-index: 9999;
}
.loader {
animation: rotate 1s infinite;
height: 50px;
width: 50px;
}
.loader:before,
.loader:after {
border-radius: 50%;
content: "";
display: block;
height: 20px;
width: 20px;
}
.loader:before {
animation: ball1 1s infinite;
background-color: #fff;
box-shadow: 30px 0 0 var(--shz-blue-default);
margin-bottom: 10px;
}
.loader:after {
animation: ball2 1s infinite;
background-color: var(--shz-blue-default);
box-shadow: 30px 0 0 #fff;
}
@keyframes rotate {
0% {
transform: rotate(0deg) scale(0.8)
}
50% {
transform: rotate(360deg) scale(1.2)
}
100% {
transform: rotate(720deg) scale(0.8)
}
}
@keyframes ball1 {
0% {
box-shadow: 30px 0 0 var(--shz-blue-default);
}
50% {
box-shadow: 0 0 0 var(--shz-blue-default);
margin-bottom: 0;
transform: translate(15px, 15px);
}
100% {
box-shadow: 30px 0 0 var(--shz-blue-default);
margin-bottom: 10px;
}
}
@keyframes ball2 {
0% {
box-shadow: 30px 0 0 #fff;
}
50% {
box-shadow: 0 0 0 #fff;
margin-top: -20px;
transform: translate(15px, 15px);
}
100% {
box-shadow: 30px 0 0 #fff;
margin-top: 0;
}
}
+5
View File
@@ -1,3 +1,8 @@
<div *ngIf="isLoading" class="overlay">
<span class="loader"></span>
<h4>Starting Server...</h4>
</div>
<app-navbar></app-navbar>
<app-sidebar></app-sidebar>
<main class="main-wrapper" id="main-wrapper" #scrollContainer>
+36 -3
View File
@@ -1,23 +1,32 @@
import { AfterViewInit, Component, ElementRef, ViewChild } from '@angular/core';
import {
AfterViewInit,
Component,
ElementRef,
OnInit,
ViewChild,
} from '@angular/core';
import { NavigationEnd, NavigationStart, Router } from '@angular/router';
import { filter } from 'rxjs';
import PerfectScrollbar from 'perfect-scrollbar';
import { PingService } from './core/services/ping.service';
declare const window: any;
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrl: './app.component.css',
})
export class AppComponent implements AfterViewInit {
export class AppComponent implements OnInit, AfterViewInit {
title = 'Showy';
isLoading = true;
@ViewChild('scrollContainer', { static: true }) scrollContainer!: ElementRef;
private ps!: PerfectScrollbar;
private scrollPositions = new Map<string, number>();
private isBackNavigation = '';
constructor(private router: Router) {}
constructor(private router: Router, private pingService: PingService) {}
ngAfterViewInit() {
this.ps = new PerfectScrollbar(this.scrollContainer.nativeElement);
@@ -58,6 +67,30 @@ export class AppComponent implements AfterViewInit {
});
}
ngOnInit() {
this.checkBackendAvailability();
}
checkBackendAvailability() {
if (window && window.electron && window.electron.ipcRenderer) {
window.electron.ipcRenderer.on('backend-ready', () => {
console.log(`Backend started.`);
this.isLoading = false;
});
} else {
this.pingService.ping().subscribe({
next: (response) => {
console.log('Backend ping response:', response);
this.isLoading = false;
},
error: (err) => {
console.log('Backend unreachable, retrying...');
setTimeout(() => this.checkBackendAvailability(), 3000);
},
});
}
}
scrollToTop() {
this.scrollContainer.nativeElement.scrollTop = 0;
this.ps.update();
-3
View File
@@ -17,7 +17,6 @@ import { TrendingComponent } from './features/discover/trending/trending.compone
import { SearchPageComponent } from './features/discover/search-page/search-page.component';
import { SharedModule } from './shared/shared.module';
import { ToastrModule } from 'ngx-toastr';
import { MinutesFormatPipe } from './shared/pipes/minutes-format/minutes-format.pipe';
@NgModule({
@@ -37,8 +36,6 @@ import { MinutesFormatPipe } from './shared/pipes/minutes-format/minutes-format.
DragDropModule,
// ? downloaded
ToastrModule.forRoot(),
],
declarations: [
AppComponent,
@@ -0,0 +1,19 @@
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { environment } from '../../../environments/environment.prod';
@Injectable({
providedIn: 'root',
})
export class PingService {
private backend_apiUrl = environment.API_URL;
private apiAction = 'ping';
constructor(private http: HttpClient) {}
ping() {
return this.http.get<string>(
`${this.backend_apiUrl}/${this.apiAction}`
);
}
}
+1 -1
View File
@@ -4,7 +4,7 @@
<head>
<meta charset="utf-8">
<title>Showy</title>
<base href="/">
<base href="./">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="favicon.ico">