Skip to content

Commit 05fe996

Browse files
committed
feat: Handle callback setelah delete track user di halaman home_page.dart
1 parent a710ba9 commit 05fe996

File tree

1 file changed

+19
-10
lines changed

1 file changed

+19
-10
lines changed

lib/feature/presentation/page/home/home_page.dart

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,9 @@ class _HomePageState extends State<HomePage> with TrayListener, WindowListener {
7979
var isWindowVisible = true;
8080
var userId = '';
8181
var email = '';
82-
TrackUserLiteResponse? trackUserLite;
8382
var isTimerStart = false;
83+
var isTimerStartTemp = false;
84+
TrackUserLiteResponse? trackUserLite;
8485
ItemProjectResponse? selectedProject;
8586
TrackTask? selectedTask;
8687
Timer? timeTrack, timerCronTrack, timerDate;
@@ -91,6 +92,7 @@ class _HomePageState extends State<HomePage> with TrayListener, WindowListener {
9192
DateTime? finishTime;
9293
DateTime? infoDateTime;
9394
DateTime? now;
95+
var isLoading = false;
9496

9597
@override
9698
void setState(VoidCallback fn) {
@@ -381,13 +383,15 @@ class _HomePageState extends State<HomePage> with TrayListener, WindowListener {
381383
listeners: [
382384
BlocListener<HomeBloc, HomeState>(
383385
listener: (context, state) async {
386+
isLoading = state is LoadingHomeState;
384387
if (state is FailureHomeState) {
385388
final errorMessage = state.errorMessage;
386389
if (errorMessage.contains('401')) {
387390
widgetHelper.showDialog401(context);
388391
return;
389392
}
390393
} else if (state is SuccessLoadDataHomeState) {
394+
isTimerStartTemp = false;
391395
trackUserLite = state.trackUserLiteResponse;
392396
valueNotifierTotalTracked.value = trackUserLite?.trackedInSeconds ?? 0;
393397

@@ -479,8 +483,6 @@ class _HomePageState extends State<HomePage> with TrayListener, WindowListener {
479483
BlocListener<CronTrackingBloc, CronTrackingState>(
480484
listener: (context, state) {
481485
if (state is SuccessRunCronTrackingState) {
482-
// TODO: tampilkan info last sync at: 22:09 04 Jul 2023
483-
// TODO: info ini akan ditampilkan dibagian paling bawah sama seperti tampilan hubstaff
484486
final ids = state.ids;
485487
final files = state.files;
486488
trackDao.deleteMultipleTrackByIds(ids).then((value) {
@@ -549,7 +551,7 @@ class _HomePageState extends State<HomePage> with TrayListener, WindowListener {
549551
Expanded(
550552
child: BlocBuilder<HomeBloc, HomeState>(
551553
builder: (context, state) {
552-
if (state is LoadingHomeState) {
554+
if (state is LoadingHomeState || isLoading) {
553555
return const WidgetCustomCircularProgressIndicator();
554556
} else if (state is FailureHomeState) {
555557
final errorMessage = state.errorMessage;
@@ -639,9 +641,9 @@ class _HomePageState extends State<HomePage> with TrayListener, WindowListener {
639641
}
640642
}
641643

642-
if (selectedTask != itemTask) {
644+
if (selectedTask?.id != itemTask.id) {
643645
if (selectedTask != null) {
644-
selectedTask!.trackedInSeconds = valueNotifierTotalTracked.value;
646+
selectedTask!.trackedInSeconds = valueNotifierTaskTracked.value;
645647
finishTime = DateTime.now();
646648
doTakeScreenshot(startTime, finishTime);
647649
}
@@ -728,7 +730,7 @@ class _HomePageState extends State<HomePage> with TrayListener, WindowListener {
728730
borderRadius: BorderRadius.circular(8),
729731
child: InkWell(
730732
borderRadius: BorderRadius.circular(8),
731-
onTap: isTimerStart
733+
onTap: isTimerStart || isTimerStartTemp
732734
? null
733735
: () async {
734736
final selectedProjectTemp = await showModalBottomSheet(
@@ -787,7 +789,7 @@ class _HomePageState extends State<HomePage> with TrayListener, WindowListener {
787789
height: 8,
788790
decoration: BoxDecoration(
789791
shape: BoxShape.circle,
790-
color: isTimerStart ? Colors.green : Colors.grey,
792+
color: isTimerStart || isTimerStartTemp ? Colors.green : Colors.grey,
791793
),
792794
),
793795
const SizedBox(width: 4),
@@ -803,7 +805,7 @@ class _HomePageState extends State<HomePage> with TrayListener, WindowListener {
803805
),
804806
),
805807
const SizedBox(width: 16),
806-
isTimerStart
808+
isTimerStart || isTimerStartTemp
807809
? Container()
808810
: const Icon(
809811
Icons.keyboard_arrow_down,
@@ -880,7 +882,14 @@ class _HomePageState extends State<HomePage> with TrayListener, WindowListener {
880882
child: InkWell(
881883
borderRadius: BorderRadius.circular(999),
882884
onTap: () {
883-
context.pushNamed(ReportScreenshotPage.routeName);
885+
context.pushNamed<bool?>(ReportScreenshotPage.routeName).then((value) async {
886+
if (value != null && value) {
887+
setState(() => isLoading = true);
888+
isTimerStartTemp = isTimerStart;
889+
stopTimerFromSystemTray();
890+
doLoadDataTask(isAutoStart: isTimerStartTemp);
891+
}
892+
});
884893
},
885894
child: Padding(
886895
padding: const EdgeInsets.symmetric(

0 commit comments

Comments
 (0)