feat: made the ongoing screen... for now

This commit is contained in:
alzalia1 2025-08-14 11:19:06 +02:00
parent 099b20f805
commit e5a8745e0e
5 changed files with 119 additions and 2 deletions

View file

@ -17,6 +17,18 @@ class BalViewModel extends ChangeNotifier {
Bal? get bal => _bal;
bool isABalOngoing = false;
Future<Result<void>> stopBal(int id) async {
final result = await _balRepository.stopBal(id);
switch (result) {
case Ok():
_bal = result.value;
notifyListeners();
break;
default:
}
return result;
}
Future<Result<void>> startBal(int id) async {
if (isABalOngoing) {
return Result.error(Exception("Cannot have multiple BALs ongoing !"));

View file

@ -12,7 +12,50 @@ class BalOngoingScreen extends StatelessWidget {
return Scaffold(
bottomNavigationBar: AppNavigationBar(startIndex: 0),
appBar: AppBar(title: Text(viewModel.bal!.name)),
body: Center(child: Text("Ongoing BAL")),
body: Padding(
padding: const EdgeInsets.all(10.0),
child: Column(
children: [
Center(
child: ElevatedButton(
onPressed: () {
showDialog(
context: context,
builder: (context) {
return AlertDialog(
title: Text(
"Êtes-vous sûr·e de vouloir arrêter cette BAL ?",
),
content: Text(
"Cette action est irréversible. Vous pourrez ensuite consulter des statistiques sur la BAL, mais ne pourrez plus ajouter ou vendre de livre qui en fasse partie.",
),
actions: [
TextButton(
onPressed: () {
Navigator.of(context).pop();
},
child: Text("Annuler"),
),
TextButton(
onPressed: () async {
await viewModel.stopBal(viewModel.bal!.id);
if (context.mounted) {
Navigator.of(context).pop();
}
},
child: Text("Valider"),
),
],
);
},
);
},
child: Text("Arrêter la BAL"),
),
),
],
),
),
);
}
}

View file

@ -38,7 +38,36 @@ class BalPendingScreen extends StatelessWidget {
);
}
: () {
viewModel.startBal(viewModel.bal!.id);
showDialog(
context: context,
builder: (context) {
return AlertDialog(
title: Text(
"Êtes-vous sûr·e de vouloir débuter cette BAL ?",
),
content: Text(
"Cette action est irréversible. Vous pourrez ensuite intéragir avec la BAL, mais pas la remettre en mode \"À venir\"",
),
actions: [
TextButton(
onPressed: () {
Navigator.of(context).pop();
},
child: Text("Annuler"),
),
TextButton(
onPressed: () async {
await viewModel.startBal(viewModel.bal!.id);
if (context.mounted) {
Navigator.of(context).pop();
}
},
child: Text("Valider"),
),
],
);
},
);
},
child: Text("Démarrer cette BAL"),
),