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