Skip to content

Commit b2cbee5

Browse files
committed
feat(start-button): display loading state and disable button while loading
1 parent f7f53a8 commit b2cbee5

File tree

4 files changed

+62
-27
lines changed

4 files changed

+62
-27
lines changed

src/app/components/mod-panel/mod-panel.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<div class="flex w-full flex-col items-center px-10">
2-
<app-start-button (notify)="startUpdateMods()" />
2+
<app-start-button [loading]="this.loading" (notify)="startUpdateMods()" />
33

44
<div class="mt-4 flex w-full flex-col">
55
<div class="w-full">

src/app/components/mod-panel/mod-panel.component.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ export class ModPanelComponent implements OnInit, OnDestroy {
9999
versionsSubscription!: Subscription;
100100
loaderSubscription!: Subscription;
101101
curseforgeSupscription!: Subscription;
102-
private finishedSubscription!: Subscription;
103-
private percentSubscription!: Subscription;
102+
private finishedSubscription?: Subscription;
103+
private percentSubscription?: Subscription;
104104

105105
constructor() {}
106106

@@ -195,6 +195,8 @@ export class ModPanelComponent implements OnInit, OnDestroy {
195195
this.versionsSubscription.unsubscribe();
196196
this.loaderSubscription.unsubscribe();
197197
this.curseforgeSupscription.unsubscribe();
198+
this.finishedSubscription?.unsubscribe();
199+
this.percentSubscription?.unsubscribe();
198200
}
199201

200202
/**
@@ -984,16 +986,18 @@ export class ModPanelComponent implements OnInit, OnDestroy {
984986
* Orchestrates the entire update process, including file processing and dependency fetching.
985987
*/
986988
async startUpdateMods() {
989+
this.loading = true;
990+
this.loadingPercent = 0;
991+
987992
const [anyToProcess, initialFinished$, initialPercent$] =
988993
await this.updateMods();
989994
if (!anyToProcess) {
995+
this.loading = false;
990996
return;
991997
}
992998

993-
this.loadingPercent = 0;
994-
this.loading = true;
995-
if (this.finishedSubscription) this.finishedSubscription.unsubscribe();
996-
if (this.percentSubscription) this.percentSubscription.unsubscribe();
999+
this.finishedSubscription?.unsubscribe();
1000+
this.percentSubscription?.unsubscribe();
9971001

9981002
// assuming an average of 1-2 dependencies per mod batch
9991003
const dependencyProcessingWeight = 1.5 / this.files.length;
@@ -1014,7 +1018,7 @@ export class ModPanelComponent implements OnInit, OnDestroy {
10141018
const { progress$, finished$ } = this.processDependencies(mcVersion);
10151019

10161020
// Switch from file progress to dependency progress
1017-
if (this.percentSubscription) this.percentSubscription.unsubscribe();
1021+
this.percentSubscription?.unsubscribe();
10181022
this.percentSubscription = progress$.subscribe((depPercent) => {
10191023
this.loadingPercent =
10201024
fileProcessingWeight + depPercent * dependencyProcessingWeight;
@@ -1030,7 +1034,7 @@ export class ModPanelComponent implements OnInit, OnDestroy {
10301034
)
10311035
.subscribe(() => {
10321036
this.loading = false;
1033-
if (this.percentSubscription) this.percentSubscription.unsubscribe();
1037+
this.percentSubscription?.unsubscribe();
10341038
});
10351039
}
10361040

Lines changed: 47 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,51 @@
11
<button
22
(click)="notify.emit()"
3-
class="flex items-center gap-x-2 rounded-lg bg-gradient-to-r from-indigo-400 to-purple-600 py-2 px-3 text-lg font-bold text-white hover:from-indigo-400 hover:to-purple-700"
3+
[disabled]="loading"
4+
[ngClass]="{
5+
'cursor-wait bg-indigo-300': loading,
6+
'bg-gradient-to-r from-indigo-400 to-purple-600 hover:from-indigo-400 hover:to-purple-700':
7+
!loading
8+
}"
9+
class="flex items-center justify-center gap-x-2 rounded-lg py-2 px-3 text-lg font-bold text-white"
410
>
5-
Update
6-
<svg
7-
xmlns="http://www.w3.org/2000/svg"
8-
fill="none"
9-
viewBox="0 0 24 24"
10-
stroke-width="1.5"
11-
stroke="currentColor"
12-
class="h-6 w-6"
13-
aria-hidden="true"
14-
>
15-
<path
16-
stroke-linecap="round"
17-
stroke-linejoin="round"
18-
d="M12 9.75v6.75m0 0l-3-3m3 3l3-3m-8.25 6a4.5 4.5 0 01-1.41-8.775 5.25 5.25 0 0110.233-2.33 3 3 0 013.758 3.848A3.752 3.752 0 0118 19.5H6.75z"
19-
/>
20-
</svg>
11+
@if (loading) {
12+
<span>Loading</span>
13+
<svg
14+
class="h-5 w-5 animate-spin text-white"
15+
xmlns="http://www.w3.org/2000/svg"
16+
fill="none"
17+
viewBox="0 0 24 24"
18+
>
19+
<circle
20+
class="opacity-25"
21+
cx="12"
22+
cy="12"
23+
r="10"
24+
stroke="currentColor"
25+
stroke-width="4"
26+
></circle>
27+
<path
28+
class="opacity-75"
29+
fill="currentColor"
30+
d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"
31+
></path>
32+
</svg>
33+
} @else {
34+
<span>Update</span>
35+
<svg
36+
xmlns="http://www.w3.org/2000/svg"
37+
fill="none"
38+
viewBox="0 0 24 24"
39+
stroke-width="1.5"
40+
stroke="currentColor"
41+
class="h-6 w-6"
42+
aria-hidden="true"
43+
>
44+
<path
45+
stroke-linecap="round"
46+
stroke-linejoin="round"
47+
d="M12 9.75v6.75m0 0l-3-3m3 3l3-3m-8.25 6a4.5 4.5 0 01-1.41-8.775 5.25 5.25 0 0110.233-2.33 3 3 0 013.758 3.848A3.752 3.752 0 0118 19.5H6.75z"
48+
/>
49+
</svg>
50+
}
2151
</button>
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component, EventEmitter, Output } from '@angular/core';
1+
import { Component, EventEmitter, Input, Output } from '@angular/core';
22

33
@Component({
44
selector: 'app-start-button',
@@ -7,5 +7,6 @@ import { Component, EventEmitter, Output } from '@angular/core';
77
standalone: false
88
})
99
export class StartButtonComponent {
10+
@Input() loading: boolean = false;
1011
@Output() notify = new EventEmitter();
1112
}

0 commit comments

Comments
 (0)