added loading for regularization tab

This commit is contained in:
Vaibhav Surve 2025-05-06 17:53:57 +05:30
parent defd753ab0
commit 488a921f45

View File

@ -873,7 +873,11 @@ class _AttendanceScreenState extends State<AttendanceScreen> with UIMixin {
];
final rows = attendanceController.regularizationLogs
.mapIndexed((index, log) => DataRow(cells: [
.mapIndexed((index, log) {
final uniqueLogKey = '${log.id}-${log.employeeId}'; // Unique key for each log
final isUploading = attendanceController.uploadingStates[uniqueLogKey]?.value ?? false; // Check the upload state
return DataRow(cells: [
DataCell(
Column(
crossAxisAlignment: CrossAxisAlignment.start,
@ -930,17 +934,18 @@ class _AttendanceScreenState extends State<AttendanceScreen> with UIMixin {
children: [
// Approve Button
ElevatedButton(
onPressed: () async {
onPressed: isUploading // Disable button if uploading
? null
: () async {
if (attendanceController.selectedProjectId == null) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text("Please select a project first")),
const SnackBar(content: Text("Please select a project first")),
);
return;
}
final success = await attendanceController
.captureAndUploadAttendance(
attendanceController.uploadingStates[uniqueLogKey]?.value = true; // Start loading
final success = await attendanceController.captureAndUploadAttendance(
log.id,
log.employeeId,
attendanceController.selectedProjectId!,
@ -966,6 +971,8 @@ class _AttendanceScreenState extends State<AttendanceScreen> with UIMixin {
await attendanceController.fetchProjectData(
attendanceController.selectedProjectId!);
}
attendanceController.uploadingStates[uniqueLogKey]?.value = false; // End loading
},
style: ElevatedButton.styleFrom(
backgroundColor: AttendanceActionColors
@ -975,7 +982,9 @@ class _AttendanceScreenState extends State<AttendanceScreen> with UIMixin {
minimumSize: const Size(60, 20),
textStyle: const TextStyle(fontSize: 12),
),
child: const Text("Approve"),
child: isUploading
? const CircularProgressIndicator(strokeWidth: 2) // Show loading indicator while uploading
: const Text("Approve"),
),
// Space between buttons
@ -983,17 +992,19 @@ class _AttendanceScreenState extends State<AttendanceScreen> with UIMixin {
// Reject Button
ElevatedButton(
onPressed: () async {
onPressed: isUploading // Disable button if uploading
? null
: () async {
if (attendanceController.selectedProjectId == null) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text("Please select a project first")),
const SnackBar(content: Text("Please select a project first")),
);
return;
}
final success = await attendanceController
.captureAndUploadAttendance(
attendanceController.uploadingStates[uniqueLogKey]?.value = true; // Start loading
final success = await attendanceController.captureAndUploadAttendance(
log.id,
log.employeeId,
attendanceController.selectedProjectId!,
@ -1019,6 +1030,8 @@ class _AttendanceScreenState extends State<AttendanceScreen> with UIMixin {
await attendanceController.fetchProjectData(
attendanceController.selectedProjectId!);
}
attendanceController.uploadingStates[uniqueLogKey]?.value = false; // End loading
},
style: ElevatedButton.styleFrom(
backgroundColor:
@ -1028,12 +1041,15 @@ class _AttendanceScreenState extends State<AttendanceScreen> with UIMixin {
minimumSize: const Size(60, 20),
textStyle: const TextStyle(fontSize: 12),
),
child: const Text("Reject"),
child: isUploading
? const CircularProgressIndicator(strokeWidth: 2) // Show loading indicator while uploading
: const Text("Reject"),
),
],
),
),
]))
]);
})
.toList();
return Column(
@ -1061,5 +1077,5 @@ class _AttendanceScreenState extends State<AttendanceScreen> with UIMixin {
),
],
);
}
}
}