dev/fix-news #2
|
|
@ -131,12 +131,27 @@ class _DidvanState extends State<Didvan> with WidgetsBindingObserver {
|
|||
void _navigateTo(Uri uri) {
|
||||
if (mounted) {
|
||||
String path = uri.path;
|
||||
if (uri.fragment.isNotEmpty) {
|
||||
path = "/${uri.fragment}";
|
||||
print("path: $path, uri: $uri");
|
||||
|
||||
if (path.contains("news")) {
|
||||
final regex = RegExp(r'^/news/(\d+)$');
|
||||
final match = regex.firstMatch(path);
|
||||
|
||||
if (match != null) {
|
||||
final id = match.group(1); // This will be '1234' as a string
|
||||
print('Extracted ID: $id');
|
||||
navigatorKey.currentState?.pushNamed(Routes.newsDetails, arguments: { 'id': int.parse(id!) ,'hasUnmarkConfirmation':true, 'isForward': true });
|
||||
} else {
|
||||
print('No match found');
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
print("no fragments identified. opening home path, uri: $uri");
|
||||
navigatorKey.currentState?.pushNamed(path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void didChangeAppLifecycleState(AppLifecycleState state) async {
|
||||
|
|
|
|||
|
|
@ -25,16 +25,20 @@ class NewsDetailsState extends CoreProvier {
|
|||
NewsDetailsData get currentNews => news[_currentIndex]!;
|
||||
|
||||
Future<void> getNewsDetails(int id, {bool? isForward}) async {
|
||||
if (isForward == null) {
|
||||
appState = AppState.busy;
|
||||
} else {
|
||||
|
||||
print("isForward: $isForward");
|
||||
// if (isForward == null) {
|
||||
// appState = AppState.busy;
|
||||
// } else {
|
||||
isFetchingNewItem = true;
|
||||
notifyListeners();
|
||||
}
|
||||
// }
|
||||
final service = RequestService(RequestHelper.newsDetails(id, args));
|
||||
await service.httpGet();
|
||||
print("making request to news endpoint $id");
|
||||
_handleTracking(sendRequest: isForward != null);
|
||||
if (service.isSuccess) {
|
||||
print("success in receiving news detail for id $id");
|
||||
final result = service.result;
|
||||
final newsItem = NewsDetailsData.fromJson(result['news']);
|
||||
if (args.page == 0) {
|
||||
|
|
@ -79,9 +83,10 @@ class NewsDetailsState extends CoreProvier {
|
|||
appState = AppState.idle;
|
||||
return;
|
||||
}
|
||||
if (isForward == null) {
|
||||
appState = AppState.failed;
|
||||
}
|
||||
print("failed to receive news detail for id $id");
|
||||
// if (isForward == null) {
|
||||
// appState = AppState.failed;
|
||||
// }
|
||||
}
|
||||
|
||||
bool exists(NewsDetailsData? newsItem) =>
|
||||
|
|
|
|||
|
|
@ -87,7 +87,9 @@ class _SplashState extends State<Splash> {
|
|||
Future<void> _initialize(ThemeProvider themeProvider,
|
||||
UserProvider userProvider, MediaProvider mediaProvider) async {
|
||||
try {
|
||||
print("checking if is in browser");
|
||||
if (kIsWeb) {
|
||||
print("detected browser");
|
||||
html.window.onBeforeUnload.listen((event) {
|
||||
StorageService.webStorage
|
||||
.removeWhere((key, value) => key == 'image-cache');
|
||||
|
|
@ -103,20 +105,25 @@ class _SplashState extends State<Splash> {
|
|||
await AppInitializer.setupServices(navigatorKey.currentContext!);
|
||||
|
||||
final String? token = await userProvider.setAndGetToken();
|
||||
print("detected token as $token");
|
||||
|
||||
if (token != null) {
|
||||
print("detected token");
|
||||
if (!kIsWeb) {
|
||||
await mediaProvider.getDownloadsList();
|
||||
}
|
||||
|
||||
RequestService.token = token;
|
||||
|
||||
print("fetching user info...");
|
||||
final result = await userProvider.getUserInfo();
|
||||
|
||||
if (!result) {
|
||||
print("no results were returned for user info");
|
||||
try {
|
||||
StorageService.delete(key: 'token');
|
||||
} catch (e) {
|
||||
print("error in case of no user info result: $e");
|
||||
// catch
|
||||
}
|
||||
|
||||
|
|
@ -127,29 +134,53 @@ class _SplashState extends State<Splash> {
|
|||
|
||||
return;
|
||||
}
|
||||
|
||||
print("got results for user info: $result");
|
||||
await ServerDataProvider.getData();
|
||||
}
|
||||
|
||||
// --- بخش اصلاح شده ---
|
||||
// ابتدا بررسی میکنیم که کاربر باید به کدام صفحه اصلی برود
|
||||
final String destinationRoute = token == null ? Routes.authenticaion : Routes.home;
|
||||
final dynamic routeArguments = token == null ? false : {'showDialogs': true};
|
||||
try {
|
||||
// Determine destination and arguments based on authentication status
|
||||
if (token == null) {
|
||||
// User is not authenticated, go to the authentication screen
|
||||
print("User not authenticated. Navigating to authentication.");
|
||||
await navigatorKey.currentState!.pushReplacementNamed(
|
||||
Routes.authenticaion,
|
||||
arguments: false, // Pass the expected boolean argument
|
||||
);
|
||||
} else {
|
||||
// User is authenticated, go to the home screen
|
||||
print("User authenticated. Navigating to home.");
|
||||
|
||||
// اگر لینک ورودی وجود داشت، آن را به عنوان آرگومان به صفحه Home میفرستیم
|
||||
if (destinationRoute == Routes.home && initialURI != null) {
|
||||
(routeArguments as Map)['deepLinkUri'] = initialURI;
|
||||
initialURI = null; // لینک را مصرف میکنیم تا دوباره استفاده نشود
|
||||
// Prepare arguments for the home screen
|
||||
final Map<String, dynamic> routeArguments = {'showDialogs': true};
|
||||
|
||||
// If a deep link exists, add it to the arguments
|
||||
if (initialURI != null) {
|
||||
print("Deep link found: $initialURI. Adding to arguments.");
|
||||
routeArguments['deepLinkUri'] = initialURI;
|
||||
initialURI = null; // Consume the link so it's not used again
|
||||
}
|
||||
|
||||
// در نهایت به مسیر تعیین شده میرویم
|
||||
// Navigate to the home screen with the correct arguments
|
||||
await navigatorKey.currentState!.pushReplacementNamed(
|
||||
destinationRoute,
|
||||
Routes.home,
|
||||
arguments: routeArguments,
|
||||
);
|
||||
}
|
||||
// --- پایان بخش اصلاح شده ---
|
||||
|
||||
} catch (e) {
|
||||
print("An error occurred during initialization: $e");
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
_errorOccured = true;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
} catch (e) {
|
||||
print("error in splash screen: $e");
|
||||
setState(() {
|
||||
_errorOccured = true;
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in New Issue