From c628f1e05b9a46b3ce0cf17b157bd9ab147b4d7f Mon Sep 17 00:00:00 2001 From: Teriuihi Date: Sat, 5 Apr 2025 21:30:55 +0200 Subject: [PATCH] Refactor randomize slide images on init --- frontend/src/app/home/home.component.ts | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/frontend/src/app/home/home.component.ts b/frontend/src/app/home/home.component.ts index 7e9387f..7451544 100644 --- a/frontend/src/app/home/home.component.ts +++ b/frontend/src/app/home/home.component.ts @@ -12,10 +12,6 @@ export class HomeComponent implements OnInit { constructor(private titleService: Title) { } - ngOnInit(): void { - this.titleService.setTitle('Survival Minecraft Server on ' + ALTITUDE_VERSION + ' | Altitude Community'); - } - private slides: string[] = ["/public/img/backgrounds/caruselimage2.png", "/public/img/backgrounds/caruselimage4.png", "/public/img/backgrounds/caruselimage1.png", @@ -23,6 +19,23 @@ export class HomeComponent implements OnInit { "/public/img/backgrounds/caruselimage3.png" ]; + ngOnInit(): void { + this.titleService.setTitle('Survival Minecraft Server on ' + ALTITUDE_VERSION + ' | Altitude Community'); + this.randomizeSlides() + } + + + private randomizeSlides(): void { + const array = [...this.slides]; + + for (let i = array.length - 1; i > 0; i--) { + const j = Math.floor(Math.random() * (i + 1)); + [array[i], array[j]] = [array[j], array[i]]; + } + + this.slides = array; + } + private slideIndex = 0; get slide(): string {