dev/fix-news #2
|
|
@ -131,10 +131,25 @@ class _DidvanState extends State<Didvan> with WidgetsBindingObserver {
|
||||||
void _navigateTo(Uri uri) {
|
void _navigateTo(Uri uri) {
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
String path = uri.path;
|
String path = uri.path;
|
||||||
if (uri.fragment.isNotEmpty) {
|
print("path: $path, uri: $uri");
|
||||||
path = "/${uri.fragment}";
|
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
navigatorKey.currentState?.pushNamed(path);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -25,16 +25,20 @@ class NewsDetailsState extends CoreProvier {
|
||||||
NewsDetailsData get currentNews => news[_currentIndex]!;
|
NewsDetailsData get currentNews => news[_currentIndex]!;
|
||||||
|
|
||||||
Future<void> getNewsDetails(int id, {bool? isForward}) async {
|
Future<void> getNewsDetails(int id, {bool? isForward}) async {
|
||||||
if (isForward == null) {
|
|
||||||
appState = AppState.busy;
|
print("isForward: $isForward");
|
||||||
} else {
|
// if (isForward == null) {
|
||||||
|
// appState = AppState.busy;
|
||||||
|
// } else {
|
||||||
isFetchingNewItem = true;
|
isFetchingNewItem = true;
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
}
|
// }
|
||||||
final service = RequestService(RequestHelper.newsDetails(id, args));
|
final service = RequestService(RequestHelper.newsDetails(id, args));
|
||||||
await service.httpGet();
|
await service.httpGet();
|
||||||
|
print("making request to news endpoint $id");
|
||||||
_handleTracking(sendRequest: isForward != null);
|
_handleTracking(sendRequest: isForward != null);
|
||||||
if (service.isSuccess) {
|
if (service.isSuccess) {
|
||||||
|
print("success in receiving news detail for id $id");
|
||||||
final result = service.result;
|
final result = service.result;
|
||||||
final newsItem = NewsDetailsData.fromJson(result['news']);
|
final newsItem = NewsDetailsData.fromJson(result['news']);
|
||||||
if (args.page == 0) {
|
if (args.page == 0) {
|
||||||
|
|
@ -79,9 +83,10 @@ class NewsDetailsState extends CoreProvier {
|
||||||
appState = AppState.idle;
|
appState = AppState.idle;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (isForward == null) {
|
print("failed to receive news detail for id $id");
|
||||||
appState = AppState.failed;
|
// if (isForward == null) {
|
||||||
}
|
// appState = AppState.failed;
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
bool exists(NewsDetailsData? newsItem) =>
|
bool exists(NewsDetailsData? newsItem) =>
|
||||||
|
|
|
||||||
|
|
@ -87,7 +87,9 @@ class _SplashState extends State<Splash> {
|
||||||
Future<void> _initialize(ThemeProvider themeProvider,
|
Future<void> _initialize(ThemeProvider themeProvider,
|
||||||
UserProvider userProvider, MediaProvider mediaProvider) async {
|
UserProvider userProvider, MediaProvider mediaProvider) async {
|
||||||
try {
|
try {
|
||||||
|
print("checking if is in browser");
|
||||||
if (kIsWeb) {
|
if (kIsWeb) {
|
||||||
|
print("detected browser");
|
||||||
html.window.onBeforeUnload.listen((event) {
|
html.window.onBeforeUnload.listen((event) {
|
||||||
StorageService.webStorage
|
StorageService.webStorage
|
||||||
.removeWhere((key, value) => key == 'image-cache');
|
.removeWhere((key, value) => key == 'image-cache');
|
||||||
|
|
@ -103,20 +105,25 @@ class _SplashState extends State<Splash> {
|
||||||
await AppInitializer.setupServices(navigatorKey.currentContext!);
|
await AppInitializer.setupServices(navigatorKey.currentContext!);
|
||||||
|
|
||||||
final String? token = await userProvider.setAndGetToken();
|
final String? token = await userProvider.setAndGetToken();
|
||||||
|
print("detected token as $token");
|
||||||
|
|
||||||
if (token != null) {
|
if (token != null) {
|
||||||
|
print("detected token");
|
||||||
if (!kIsWeb) {
|
if (!kIsWeb) {
|
||||||
await mediaProvider.getDownloadsList();
|
await mediaProvider.getDownloadsList();
|
||||||
}
|
}
|
||||||
|
|
||||||
RequestService.token = token;
|
RequestService.token = token;
|
||||||
|
|
||||||
|
print("fetching user info...");
|
||||||
final result = await userProvider.getUserInfo();
|
final result = await userProvider.getUserInfo();
|
||||||
|
|
||||||
if (!result) {
|
if (!result) {
|
||||||
|
print("no results were returned for user info");
|
||||||
try {
|
try {
|
||||||
StorageService.delete(key: 'token');
|
StorageService.delete(key: 'token');
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
print("error in case of no user info result: $e");
|
||||||
// catch
|
// catch
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -127,29 +134,53 @@ class _SplashState extends State<Splash> {
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
print("got results for user info: $result");
|
||||||
await ServerDataProvider.getData();
|
await ServerDataProvider.getData();
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- بخش اصلاح شده ---
|
|
||||||
// ابتدا بررسی میکنیم که کاربر باید به کدام صفحه اصلی برود
|
|
||||||
final String destinationRoute = token == null ? Routes.authenticaion : Routes.home;
|
|
||||||
final dynamic routeArguments = token == null ? false : {'showDialogs': true};
|
|
||||||
|
|
||||||
// اگر لینک ورودی وجود داشت، آن را به عنوان آرگومان به صفحه Home میفرستیم
|
// --- بخش اصلاح شده ---
|
||||||
if (destinationRoute == Routes.home && initialURI != null) {
|
try {
|
||||||
(routeArguments as Map)['deepLinkUri'] = initialURI;
|
// Determine destination and arguments based on authentication status
|
||||||
initialURI = null; // لینک را مصرف میکنیم تا دوباره استفاده نشود
|
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.");
|
||||||
|
|
||||||
|
// 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(
|
||||||
|
Routes.home,
|
||||||
|
arguments: routeArguments,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
// --- پایان بخش اصلاح شده ---
|
||||||
|
|
||||||
|
} catch (e) {
|
||||||
|
print("An error occurred during initialization: $e");
|
||||||
|
if (mounted) {
|
||||||
|
setState(() {
|
||||||
|
_errorOccured = true;
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// در نهایت به مسیر تعیین شده میرویم
|
|
||||||
await navigatorKey.currentState!.pushReplacementNamed(
|
|
||||||
destinationRoute,
|
|
||||||
arguments: routeArguments,
|
|
||||||
);
|
|
||||||
// --- پایان بخش اصلاح شده ---
|
|
||||||
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
print("error in splash screen: $e");
|
||||||
setState(() {
|
setState(() {
|
||||||
_errorOccured = true;
|
_errorOccured = true;
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue