1
1
import 'package:flutter/material.dart' ;
2
2
import 'package:flutter_bloc/flutter_bloc.dart' ;
3
3
import 'package:go_router/go_router.dart' ;
4
- import 'package:ht_authentication_repository/ht_authentication_repository.dart' ;
5
- import 'package:ht_categories_repository/ht_categories_repository.dart' ;
6
- import 'package:ht_countries_repository/ht_countries_repository.dart' ;
7
- import 'package:ht_headlines_repository/ht_headlines_repository.dart' ;
4
+ import 'package:ht_auth_repository/ht_auth_repository.dart' ; // Auth Repository
5
+ import 'package:ht_data_repository/ht_data_repository.dart' ; // Generic Data Repository
8
6
import 'package:ht_main/account/bloc/account_bloc.dart' ;
9
7
import 'package:ht_main/account/view/account_page.dart' ;
10
8
import 'package:ht_main/app/bloc/app_bloc.dart' ;
11
9
import 'package:ht_main/app/view/app_shell.dart' ;
12
10
import 'package:ht_main/authentication/bloc/authentication_bloc.dart' ;
13
11
import 'package:ht_main/authentication/view/authentication_page.dart' ;
14
- import 'package:ht_main/authentication/view/email_link_sent_page .dart' ;
15
- import 'package:ht_main/authentication/view/email_sign_in_page .dart' ;
12
+ import 'package:ht_main/authentication/view/email_code_verification_page .dart' ;
13
+ import 'package:ht_main/authentication/view/request_code_page .dart' ; // Will be renamed to request_code_page.dart later
16
14
import 'package:ht_main/headline-details/bloc/headline_details_bloc.dart' ;
17
15
import 'package:ht_main/headline-details/view/headline_details_page.dart' ;
18
16
import 'package:ht_main/headlines-feed/bloc/categories_filter_bloc.dart' ; // Import new BLoC
@@ -34,21 +32,23 @@ import 'package:ht_main/settings/view/article_settings_page.dart'; // Added
34
32
import 'package:ht_main/settings/view/feed_settings_page.dart' ; // Added
35
33
import 'package:ht_main/settings/view/notification_settings_page.dart' ; // Added
36
34
import 'package:ht_main/settings/view/settings_page.dart' ; // Added
37
- import 'package:ht_preferences_repository/ht_preferences_repository.dart' ; // Added
38
- import 'package:ht_sources_repository/ht_sources_repository.dart' ;
35
+ import 'package:ht_shared/ht_shared.dart' ; // Shared models, FromJson, ToJson, etc.
39
36
40
37
/// Creates and configures the GoRouter instance for the application.
41
38
///
42
39
/// Requires an [authStatusNotifier] to trigger route re-evaluation when
43
40
/// authentication state changes.
44
41
GoRouter createRouter ({
45
42
required ValueNotifier <AppStatus > authStatusNotifier,
46
- required HtAuthenticationRepository htAuthenticationRepository,
47
- required HtHeadlinesRepository htHeadlinesRepository,
48
- required HtCategoriesRepository htCategoriesRepository,
49
- required HtCountriesRepository htCountriesRepository,
50
- required HtSourcesRepository htSourcesRepository,
51
- required HtPreferencesRepository htPreferencesRepository, // Added
43
+ required HtAuthRepository htAuthenticationRepository,
44
+ required HtDataRepository <Headline > htHeadlinesRepository,
45
+ required HtDataRepository <Category > htCategoriesRepository,
46
+ required HtDataRepository <Country > htCountriesRepository,
47
+ required HtDataRepository <Source > htSourcesRepository,
48
+ required HtDataRepository <UserAppSettings > htUserAppSettingsRepository,
49
+ required HtDataRepository <UserContentPreferences >
50
+ htUserContentPreferencesRepository,
51
+ required HtDataRepository <AppConfig > htAppConfigRepository,
52
52
}) {
53
53
return GoRouter (
54
54
refreshListenable: authStatusNotifier,
@@ -78,11 +78,11 @@ GoRouter createRouter({
78
78
// Base paths for major sections.
79
79
const authenticationPath = Routes .authentication; // '/authentication'
80
80
const feedPath = Routes .feed; // Updated path constant
81
- // Specific authentication sub-routes crucial for the email linking flow.
82
- const emailSignInPath =
83
- '$authenticationPath /${Routes .emailSignIn }' ; // '/authentication/email-sign-in '
84
- const emailLinkSentPath =
85
- '$authenticationPath /${Routes .emailLinkSent }' ; // '/authentication/email-link-sent '
81
+ // Specific authentication sub-routes crucial for the email code verification flow.
82
+ const requestCodePath =
83
+ '$authenticationPath /${Routes .requestCode }' ; // '/authentication/request-code '
84
+ const verifyCodePath =
85
+ '$authenticationPath /${Routes .verifyCode }' ; // '/authentication/verify-code '
86
86
87
87
// --- Helper Booleans ---
88
88
// Check if the navigation target is within the authentication section.
@@ -155,13 +155,14 @@ GoRouter createRouter({
155
155
return feedPath; // Redirect to feed
156
156
}
157
157
}
158
- // **Sub-Case 2.2: Navigating to Specific Email Linking Sub-Routes**
159
- // Explicitly allow access to the necessary pages for the email linking process,
158
+ // **Sub-Case 2.2: Navigating to Specific Email Code Verification Sub-Routes**
159
+ // Explicitly allow access to the necessary pages for the email code verification process,
160
160
// even if the 'context=linking' parameter is lost during navigation between these pages.
161
- else if (currentLocation == emailSignInPath ||
162
- currentLocation == emailLinkSentPath) {
161
+ else if (currentLocation == requestCodePath ||
162
+ currentLocation.startsWith (verifyCodePath)) {
163
+ // Use startsWith for parameterized path
163
164
print (
164
- ' Action: Allowing navigation to email linking sub-route ($currentLocation ).' ,
165
+ ' Action: Allowing navigation to email code verification sub-route ($currentLocation ).' ,
165
166
);
166
167
return null ; // Allow access
167
168
}
@@ -217,9 +218,8 @@ GoRouter createRouter({
217
218
// print(' Redirect Decision: No specific redirect condition met. Allowing navigation.');
218
219
// return null; // Allow access (already covered by the final return null below)
219
220
},
220
- // --- Routes ---
221
+ // --- Authentication Routes ---
221
222
routes: [
222
- // --- Authentication Routes ---
223
223
GoRoute (
224
224
path: Routes .authentication,
225
225
name: Routes .authenticationName,
@@ -247,7 +247,7 @@ GoRouter createRouter({
247
247
return BlocProvider (
248
248
create:
249
249
(context) => AuthenticationBloc (
250
- authenticationRepository: htAuthenticationRepository ,
250
+ authenticationRepository: context. read < HtAuthRepository >() ,
251
251
),
252
252
child: AuthenticationPage (
253
253
headline: headline,
@@ -259,18 +259,26 @@ GoRouter createRouter({
259
259
},
260
260
routes: [
261
261
GoRoute (
262
- path: Routes .emailSignIn,
263
- name: Routes .emailSignInName,
262
+ path: Routes .requestCode, // Use new path
263
+ name: Routes .requestCodeName, // Use new name
264
264
builder: (context, state) {
265
265
// Extract the linking context flag from 'extra', default to false.
266
266
final isLinking = (state.extra as bool ? ) ?? false ;
267
- return EmailSignInPage (isLinkingContext: isLinking);
267
+ return EmailSignInPage (
268
+ isLinkingContext: isLinking,
269
+ ); // Page will be renamed later
268
270
},
269
271
),
270
272
GoRoute (
271
- path: Routes .emailLinkSent,
272
- name: Routes .emailLinkSentName,
273
- builder: (context, state) => const EmailLinkSentPage (),
273
+ path:
274
+ '${Routes .verifyCode }/:email' , // Use new path with email parameter
275
+ name: Routes .verifyCodeName, // Use new name
276
+ builder: (context, state) {
277
+ final email = state.pathParameters['email' ]! ; // Extract email
278
+ return EmailCodeVerificationPage (
279
+ email: email,
280
+ ); // Use renamed page
281
+ },
274
282
),
275
283
],
276
284
),
@@ -283,19 +291,25 @@ GoRouter createRouter({
283
291
BlocProvider (
284
292
create:
285
293
(context) => HeadlinesFeedBloc (
286
- headlinesRepository: htHeadlinesRepository,
294
+ headlinesRepository:
295
+ context.read <HtDataRepository <Headline >>(),
287
296
)..add (const HeadlinesFeedFetchRequested ()),
288
297
),
289
298
BlocProvider (
290
299
create:
291
300
(context) => HeadlinesSearchBloc (
292
- headlinesRepository: htHeadlinesRepository,
301
+ headlinesRepository:
302
+ context.read <HtDataRepository <Headline >>(),
293
303
),
294
304
),
295
305
BlocProvider (
296
306
create:
297
307
(context) => AccountBloc (
298
- authenticationRepository: htAuthenticationRepository,
308
+ authenticationRepository:
309
+ context.read <HtAuthRepository >(),
310
+ userContentPreferencesRepository:
311
+ context
312
+ .read <HtDataRepository <UserContentPreferences >>(),
299
313
),
300
314
),
301
315
],
@@ -320,7 +334,8 @@ GoRouter createRouter({
320
334
return BlocProvider (
321
335
create:
322
336
(context) => HeadlineDetailsBloc (
323
- headlinesRepository: htHeadlinesRepository,
337
+ headlinesRepository:
338
+ context.read <HtDataRepository <Headline >>(),
324
339
)..add (HeadlineDetailsRequested (headlineId: id)),
325
340
child: HeadlineDetailsPage (headlineId: id),
326
341
);
@@ -364,7 +379,8 @@ GoRouter createRouter({
364
379
create:
365
380
(context) => CategoriesFilterBloc (
366
381
categoriesRepository:
367
- context.read <HtCategoriesRepository >(),
382
+ context
383
+ .read <HtDataRepository <Category >>(),
368
384
),
369
385
child: const CategoryFilterPage (),
370
386
),
@@ -381,7 +397,8 @@ GoRouter createRouter({
381
397
create:
382
398
(context) => SourcesFilterBloc (
383
399
sourcesRepository:
384
- context.read <HtSourcesRepository >(),
400
+ context
401
+ .read <HtDataRepository <Source >>(),
385
402
),
386
403
child: const SourceFilterPage (),
387
404
),
@@ -398,7 +415,8 @@ GoRouter createRouter({
398
415
create:
399
416
(context) => CountriesFilterBloc (
400
417
countriesRepository:
401
- context.read <HtCountriesRepository >(),
418
+ context
419
+ .read <HtDataRepository <Country >>(),
402
420
),
403
421
child: const CountryFilterPage (),
404
422
),
@@ -436,8 +454,11 @@ GoRouter createRouter({
436
454
return BlocProvider (
437
455
create:
438
456
(context) => SettingsBloc (
439
- preferencesRepository:
440
- context.read <HtPreferencesRepository >(),
457
+ userAppSettingsRepository:
458
+ context
459
+ .read<
460
+ HtDataRepository <UserAppSettings >
461
+ > (),
441
462
)..add (
442
463
const SettingsLoadRequested (),
443
464
), // Load on entry
@@ -473,6 +494,31 @@ GoRouter createRouter({
473
494
),
474
495
],
475
496
),
497
+ // New routes for Account sub-pages
498
+ GoRoute (
499
+ path:
500
+ Routes
501
+ .accountContentPreferences, // Relative path 'content-preferences'
502
+ name: Routes .accountContentPreferencesName,
503
+ builder: (context, state) {
504
+ // TODO(fulleni): Replace with actual ContentPreferencesPage
505
+ return const Placeholder (
506
+ child: Center (child: Text ('CONTENT PREFERENCES PAGE' )),
507
+ );
508
+ },
509
+ ),
510
+ GoRoute (
511
+ path:
512
+ Routes
513
+ .accountSavedHeadlines, // Relative path 'saved-headlines'
514
+ name: Routes .accountSavedHeadlinesName,
515
+ builder: (context, state) {
516
+ // TODO(fulleni): Replace with actual SavedHeadlinesPage
517
+ return const Placeholder (
518
+ child: Center (child: Text ('SAVED HEADLINES PAGE' )),
519
+ );
520
+ },
521
+ ),
476
522
],
477
523
),
478
524
],
0 commit comments