feat: honestly forgot

This commit is contained in:
Alzalia 2025-08-11 22:41:15 +02:00
parent 48bcf0b1f8
commit da953ba651
19 changed files with 1097 additions and 244 deletions

View file

@ -1,16 +0,0 @@
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:seshat/ui/core/ui/navigation_bar.dart';
class HomePage extends StatelessWidget {
const HomePage({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
bottomNavigationBar: AppNavigationBar(startIndex: 0),
body: Center(child: Text("Home page.")),
);
// return Center(child: Text("Home page;"));
}
}

View file

@ -0,0 +1,79 @@
import 'package:flutter/material.dart';
import 'package:seshat/data/repositories/bal_repository.dart';
import 'package:seshat/domain/models/bal.dart';
import 'package:seshat/utils/command.dart';
import 'package:seshat/utils/result.dart';
class HomeViewModel extends ChangeNotifier {
HomeViewModel({required BalRepository balRepository})
: _balRepository = balRepository {
load = Command0(_load)..execute();
}
final BalRepository _balRepository;
/*
* =================
* =====[ BAL ]=====
* =================
*/
List<Bal> _bals = [];
List<Bal> get bals => _bals;
Bal? _currentBal;
Bal? get currentBal => _currentBal;
Future<Result<void>> createBal(String name) async {
final result = await _balRepository.addBal(name);
switch (result) {
case Ok():
final result2 = await _balRepository.getBals();
switch (result2) {
case Ok():
_bals = result2.value..sort((a, b) => a.compareTo(b));
break;
case Error():
debugPrint("\n\n\n\n${result2.error.toString()}\n\n\n\n");
return result2;
}
break;
case Error():
return result;
}
notifyListeners();
return result;
}
/*
* =================================
* =====[ COMMAND AND LOADING ]=====
* =================================
*/
late final Command0 load;
bool isLoaded = false;
Future<Result<void>> _load() async {
final result2 = await _loadBal();
isLoaded = true;
notifyListeners();
return result2;
}
Future<Result<void>> _loadBal() async {
final result = await _balRepository.getBals();
switch (result) {
case Ok():
_bals = result.value..sort((a, b) => a.compareTo(b));
_currentBal = _bals
.where((bal) => bal.state == BalState.ongoing)
.firstOrNull;
break;
case Error():
return result;
}
return result;
}
}

View file

@ -0,0 +1,71 @@
import 'package:flutter/material.dart';
import 'package:seshat/ui/home_page/view_model/home_view_model.dart';
class CreateConfirmationPopup extends StatefulWidget {
const CreateConfirmationPopup({super.key, required this.viewModel});
final HomeViewModel viewModel;
@override
State<CreateConfirmationPopup> createState() =>
_CreateConfirmationPopupState();
}
class _CreateConfirmationPopupState extends State<CreateConfirmationPopup> {
final GlobalKey<FormState> _formKey = GlobalKey<FormState>();
String? name;
@override
Widget build(BuildContext context) {
return AlertDialog(
title: Text("Créer une BAL"),
content: Column(
mainAxisSize: MainAxisSize.min,
children: [
Form(
key: _formKey,
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
TextFormField(
decoration: InputDecoration(
labelText: "Nom de la BAL",
border: OutlineInputBorder(),
),
validator: (value) {
if (value == null || value.isEmpty) {
return "Veuillez entrer un nom";
}
return null;
},
onSaved: (newValue) {
name = newValue;
},
),
],
),
),
],
),
actions: [
TextButton(
onPressed: () {
Navigator.of(context).pop();
},
child: Text("Annuler"),
),
TextButton(
onPressed: () async {
if (_formKey.currentState!.validate()) {
_formKey.currentState!.save();
await widget.viewModel.createBal(name!);
}
if (context.mounted) {
Navigator.of(context).pop();
}
},
child: Text("Valider"),
),
],
);
}
}

View file

@ -0,0 +1,213 @@
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:seshat/domain/models/bal.dart';
import 'package:seshat/ui/core/ui/navigation_bar.dart';
import 'package:seshat/ui/home_page/view_model/home_view_model.dart';
import 'package:seshat/ui/home_page/widgets/create_confirmation_popup.dart';
class HomePage extends StatefulWidget {
const HomePage({super.key, required this.viewModel});
final HomeViewModel viewModel;
@override
State<HomePage> createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
bottomNavigationBar: AppNavigationBar(startIndex: 0),
body: ListenableBuilder(
listenable: widget.viewModel,
builder: (context, child) {
return switch (widget.viewModel.isLoaded) {
false => Center(child: CircularProgressIndicator()),
true => switch (widget.viewModel.currentBal == null) {
true => HomePageOnNoCurrent(widget: widget),
false => HomePageOnCurrent(widget: widget),
},
};
},
),
);
// return Center(child: Text("Home page;"));
}
}
class HomePageOnNoCurrent extends StatelessWidget {
const HomePageOnNoCurrent({super.key, required this.widget});
final HomePage widget;
@override
Widget build(BuildContext context) {
return Column(
children: [
Expanded(
child: (widget.viewModel.bals.isEmpty)
? Center(child: Text("Aucune BAL existante"))
: ListView(
children: [
for (Bal bal in widget.viewModel.bals.where(
(el) => el.id != widget.viewModel.currentBal?.id,
))
Padding(
padding: const EdgeInsets.symmetric(horizontal: 10.0),
child: Card(
child: ListTile(
leading: switch (bal.state) {
BalState.pending => Icon(Icons.event),
BalState.ongoing => Icon(Icons.event_available),
BalState.ended => Icon(Icons.lock),
},
title: Text(bal.name),
subtitle: switch (bal.state) {
BalState.pending => Text(
"À venir · Débute le ${bal.startTime.toString()}",
),
BalState.ongoing => Text("En cours"),
BalState.ended => Text("Terminée"),
},
trailing: switch (bal.state) {
BalState.pending => IconButton(
onPressed: () {
_moveToBal(context, bal.id);
},
icon: Icon(Icons.edit),
),
BalState.ongoing => IconButton(
onPressed: () {
_moveToBal(context, bal.id);
},
icon: Icon(Icons.arrow_forward),
),
BalState.ended => IconButton(
onPressed: () {
_moveToBal(context, bal.id);
},
icon: Icon(Icons.analytics),
),
},
),
),
),
],
),
),
SizedBox(height: 10),
ElevatedButton(
onPressed: () {
showDialog(
context: context,
builder: (context) {
return CreateConfirmationPopup(viewModel: widget.viewModel);
},
);
},
child: Text("Débuter une BAL"),
),
SizedBox(height: 5),
],
);
}
}
class HomePageOnCurrent extends StatelessWidget {
const HomePageOnCurrent({super.key, required this.widget});
final HomePage widget;
@override
Widget build(BuildContext context) {
return Column(
children: [
Expanded(
child: (widget.viewModel.bals.isEmpty)
? Center(child: Text("Aucune BAL existante"))
: ListView(
children: [
for (Bal bal in widget.viewModel.bals.where(
(el) => el.id != widget.viewModel.currentBal?.id,
))
Padding(
padding: const EdgeInsets.symmetric(horizontal: 10.0),
child: Card(
child: ListTile(
leading: switch (bal.state) {
BalState.pending => Icon(Icons.event),
BalState.ongoing => Icon(Icons.event_available),
BalState.ended => Icon(Icons.lock),
},
title: Text(bal.name),
subtitle: switch (bal.state) {
BalState.pending => Text(
"À venir · Débute le ${bal.startTime.toString()}",
),
BalState.ongoing => Text("En cours"),
BalState.ended => Text("Terminée"),
},
trailing: switch (bal.state) {
BalState.pending => IconButton(
onPressed: () {
_moveToBal(context, bal.id);
},
icon: Icon(Icons.edit),
),
BalState.ongoing => IconButton(
onPressed: () {
_moveToBal(context, bal.id);
},
icon: Icon(Icons.arrow_forward),
),
BalState.ended => IconButton(
onPressed: () {
_moveToBal(context, bal.id);
},
icon: Icon(Icons.analytics),
),
},
),
),
),
],
),
),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 10.0),
child: Card(
child: ListTile(
leading: Icon(Icons.event_available),
title: Text(widget.viewModel.currentBal!.name),
subtitle: Text("BAL en cours"),
trailing: IconButton(
onPressed: () {
_moveToBal(context, widget.viewModel.currentBal!.id);
},
icon: Icon(Icons.arrow_forward),
),
),
),
),
SizedBox(height: 10),
ElevatedButton(
onPressed: () {
showDialog(
context: context,
builder: (context) {
return CreateConfirmationPopup(viewModel: widget.viewModel);
},
);
},
child: Text("Créer une BAL"),
),
SizedBox(height: 5),
],
);
}
}
void _moveToBal(BuildContext context, int id) {
context.goNamed("bal", pathParameters: {"id": id.toString()});
}