solving problem to move to search from home

This commit is contained in:
José Salazar
2026-02-04 10:37:12 +09:00
parent 24d346d9a9
commit cf2433774d
7 changed files with 92 additions and 10 deletions

View File

@@ -31,9 +31,11 @@ extension HomeNavigator on IModularNavigator {
/// Optionally provide a [tab] query param (e.g. `find`). /// Optionally provide a [tab] query param (e.g. `find`).
void pushShifts({String? tab}) { void pushShifts({String? tab}) {
if (tab == null) { if (tab == null) {
pushNamed('/worker-main/shifts'); navigate('/worker-main/shifts');
} else { } else {
pushNamed('/worker-main/shifts?tab=$tab'); navigate('/worker-main/shifts', arguments: <String, dynamic>{
'initialTab': tab,
});
} }
} }

View File

@@ -132,8 +132,7 @@ class WorkerHomePage extends StatelessWidget {
EmptyStateWidget( EmptyStateWidget(
message: emptyI18n.no_shifts_today, message: emptyI18n.no_shifts_today,
actionLink: emptyI18n.find_shifts_cta, actionLink: emptyI18n.find_shifts_cta,
onAction: () => onAction: () => Modular.to.pushShifts(tab: 'find'),
Modular.to.pushShifts(tab: 'find'),
) )
else else
Column( Column(

View File

@@ -31,6 +31,7 @@ class ShiftsBloc extends Bloc<ShiftsEvent, ShiftsState> {
on<LoadShiftsEvent>(_onLoadShifts); on<LoadShiftsEvent>(_onLoadShifts);
on<LoadHistoryShiftsEvent>(_onLoadHistoryShifts); on<LoadHistoryShiftsEvent>(_onLoadHistoryShifts);
on<LoadAvailableShiftsEvent>(_onLoadAvailableShifts); on<LoadAvailableShiftsEvent>(_onLoadAvailableShifts);
on<LoadFindFirstEvent>(_onLoadFindFirst);
on<LoadShiftsForRangeEvent>(_onLoadShiftsForRange); on<LoadShiftsForRangeEvent>(_onLoadShiftsForRange);
on<FilterAvailableShiftsEvent>(_onFilterAvailableShifts); on<FilterAvailableShiftsEvent>(_onFilterAvailableShifts);
} }
@@ -113,6 +114,65 @@ class ShiftsBloc extends Bloc<ShiftsEvent, ShiftsState> {
} }
} }
Future<void> _onLoadFindFirst(
LoadFindFirstEvent event,
Emitter<ShiftsState> emit,
) async {
if (state is! ShiftsLoaded) {
emit(const ShiftsLoaded(
myShifts: [],
pendingShifts: [],
cancelledShifts: [],
availableShifts: [],
historyShifts: [],
availableLoading: false,
availableLoaded: false,
historyLoading: false,
historyLoaded: false,
searchQuery: '',
jobType: 'all',
));
}
final currentState =
state is ShiftsLoaded ? state as ShiftsLoaded : null;
if (currentState != null && currentState.availableLoaded) return;
if (currentState != null) {
emit(currentState.copyWith(availableLoading: true));
}
try {
final availableResult =
await getAvailableShifts(const GetAvailableShiftsArguments());
final loadedState = state is ShiftsLoaded
? state as ShiftsLoaded
: const ShiftsLoaded(
myShifts: [],
pendingShifts: [],
cancelledShifts: [],
availableShifts: [],
historyShifts: [],
availableLoading: true,
availableLoaded: false,
historyLoading: false,
historyLoaded: false,
searchQuery: '',
jobType: 'all',
);
emit(loadedState.copyWith(
availableShifts: _filterPastShifts(availableResult),
availableLoading: false,
availableLoaded: true,
));
} catch (_) {
if (state is ShiftsLoaded) {
final current = state as ShiftsLoaded;
emit(current.copyWith(availableLoading: false));
}
}
}
Future<void> _onLoadShiftsForRange( Future<void> _onLoadShiftsForRange(
LoadShiftsForRangeEvent event, LoadShiftsForRangeEvent event,
Emitter<ShiftsState> emit, Emitter<ShiftsState> emit,

View File

@@ -14,6 +14,8 @@ class LoadHistoryShiftsEvent extends ShiftsEvent {}
class LoadAvailableShiftsEvent extends ShiftsEvent {} class LoadAvailableShiftsEvent extends ShiftsEvent {}
class LoadFindFirstEvent extends ShiftsEvent {}
class LoadShiftsForRangeEvent extends ShiftsEvent { class LoadShiftsForRangeEvent extends ShiftsEvent {
final DateTime start; final DateTime start;
final DateTime end; final DateTime end;

View File

@@ -21,6 +21,7 @@ class ShiftsPage extends StatefulWidget {
class _ShiftsPageState extends State<ShiftsPage> { class _ShiftsPageState extends State<ShiftsPage> {
late String _activeTab; late String _activeTab;
DateTime? _selectedDate; DateTime? _selectedDate;
bool _prioritizeFind = false;
final ShiftsBloc _bloc = Modular.get<ShiftsBloc>(); final ShiftsBloc _bloc = Modular.get<ShiftsBloc>();
@override @override
@@ -28,12 +29,22 @@ class _ShiftsPageState extends State<ShiftsPage> {
super.initState(); super.initState();
_activeTab = widget.initialTab ?? 'myshifts'; _activeTab = widget.initialTab ?? 'myshifts';
_selectedDate = widget.selectedDate; _selectedDate = widget.selectedDate;
_bloc.add(LoadShiftsEvent()); print('ShiftsPage init: initialTab=$_activeTab');
_prioritizeFind = widget.initialTab == 'find';
if (_prioritizeFind) {
_bloc.add(LoadFindFirstEvent());
} else {
_bloc.add(LoadShiftsEvent());
}
if (_activeTab == 'history') { if (_activeTab == 'history') {
print('ShiftsPage init: loading history tab');
_bloc.add(LoadHistoryShiftsEvent()); _bloc.add(LoadHistoryShiftsEvent());
} }
if (_activeTab == 'find') { if (_activeTab == 'find') {
_bloc.add(LoadAvailableShiftsEvent()); print('ShiftsPage init: entering find tab (not loaded yet)');
if (!_prioritizeFind) {
_bloc.add(LoadAvailableShiftsEvent());
}
} }
} }
@@ -43,6 +54,7 @@ class _ShiftsPageState extends State<ShiftsPage> {
if (widget.initialTab != null && widget.initialTab != _activeTab) { if (widget.initialTab != null && widget.initialTab != _activeTab) {
setState(() { setState(() {
_activeTab = widget.initialTab!; _activeTab = widget.initialTab!;
_prioritizeFind = widget.initialTab == 'find';
}); });
} }
if (widget.selectedDate != null && widget.selectedDate != _selectedDate) { if (widget.selectedDate != null && widget.selectedDate != _selectedDate) {
@@ -86,6 +98,7 @@ class _ShiftsPageState extends State<ShiftsPage> {
final bool historyLoaded = (state is ShiftsLoaded) final bool historyLoaded = (state is ShiftsLoaded)
? state.historyLoaded ? state.historyLoaded
: false; : false;
final bool blockTabsForFind = _prioritizeFind && !availableLoaded;
// Note: "filteredJobs" logic moved to FindShiftsTab // Note: "filteredJobs" logic moved to FindShiftsTab
// Note: Calendar logic moved to MyShiftsTab // Note: Calendar logic moved to MyShiftsTab
@@ -124,7 +137,7 @@ class _ShiftsPageState extends State<ShiftsPage> {
"My Shifts", "My Shifts",
UiIcons.calendar, UiIcons.calendar,
myShifts.length, myShifts.length,
enabled: true, enabled: !blockTabsForFind,
), ),
const SizedBox(width: 8), const SizedBox(width: 8),
_buildTab( _buildTab(
@@ -143,7 +156,7 @@ class _ShiftsPageState extends State<ShiftsPage> {
UiIcons.clock, UiIcons.clock,
historyShifts.length, historyShifts.length,
showCount: historyLoaded, showCount: historyLoaded,
enabled: baseLoaded, enabled: !blockTabsForFind && baseLoaded,
), ),
], ],
), ),

View File

@@ -22,6 +22,12 @@ class _FindShiftsTabState extends State<FindShiftsTab> {
String _searchQuery = ''; String _searchQuery = '';
String _jobType = 'all'; String _jobType = 'all';
@override
void initState() {
super.initState();
print('FindShiftsTab init: tab entered, data pending');
}
Widget _buildFilterTab(String id, String label) { Widget _buildFilterTab(String id, String label) {
final isSelected = _jobType == id; final isSelected = _jobType == id;
return GestureDetector( return GestureDetector(

View File

@@ -5,7 +5,7 @@ mutation seedAll @transaction {
data: { data: {
id: "dvpWnaBjT6UksS5lo04hfMTyq1q1" id: "dvpWnaBjT6UksS5lo04hfMTyq1q1"
email: "legendary@krowd.com" email: "legendary@krowd.com"
fullName: "Krow" fullName: "Krow Payements"
role: USER role: USER
userRole: "BUSINESS" userRole: "BUSINESS"
} }
@@ -26,7 +26,7 @@ mutation seedAll @transaction {
id: "ef69e942-d6e5-48e5-a8bc-69d3faa63b2f" id: "ef69e942-d6e5-48e5-a8bc-69d3faa63b2f"
businessName: "Krow" businessName: "Krow"
userId: "dvpWnaBjT6UksS5lo04hfMTyq1q1" userId: "dvpWnaBjT6UksS5lo04hfMTyq1q1"
contactName: "Krow Ops" contactName: "Krow Payements"
email: "legendary@krowd.com" email: "legendary@krowd.com"
phone: "+1-818-555-0148" phone: "+1-818-555-0148"
address: "5000 San Jose Street, Granada Hills, CA, USA" address: "5000 San Jose Street, Granada Hills, CA, USA"