2024-06-03 09:10:02 +08:00
|
|
|
import 'dart:async';
|
2024-01-24 15:15:57 +01:00
|
|
|
import 'dart:convert';
|
|
|
|
|
2024-06-03 14:27:28 +08:00
|
|
|
import 'package:appflowy/mobile/presentation/chat/mobile_chat_screen.dart';
|
|
|
|
import 'package:appflowy/workspace/presentation/home/menu/menu_shared_state.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
2023-11-29 19:01:29 -07:00
|
|
|
import 'package:appflowy/mobile/presentation/database/board/mobile_board_screen.dart';
|
2023-10-23 18:35:07 +08:00
|
|
|
import 'package:appflowy/mobile/presentation/database/mobile_calendar_screen.dart';
|
|
|
|
import 'package:appflowy/mobile/presentation/database/mobile_grid_screen.dart';
|
|
|
|
import 'package:appflowy/mobile/presentation/presentation.dart';
|
2024-04-23 15:46:57 +02:00
|
|
|
import 'package:appflowy/startup/startup.dart';
|
|
|
|
import 'package:appflowy/workspace/application/recent/cached_recent_service.dart';
|
2023-12-31 07:29:40 +08:00
|
|
|
import 'package:appflowy_backend/protobuf/flowy-folder/view.pb.dart';
|
2023-10-23 18:35:07 +08:00
|
|
|
import 'package:go_router/go_router.dart';
|
|
|
|
|
|
|
|
extension MobileRouter on BuildContext {
|
2024-01-24 15:15:57 +01:00
|
|
|
Future<void> pushView(ViewPB view, [Map<String, dynamic>? arguments]) async {
|
2024-06-03 09:10:02 +08:00
|
|
|
// set the current view before pushing the new view
|
|
|
|
getIt<MenuSharedState>().latestOpenView = view;
|
|
|
|
unawaited(getIt<CachedRecentService>().updateRecentViews([view.id], true));
|
|
|
|
|
|
|
|
final uri = Uri(
|
|
|
|
path: view.routeName,
|
|
|
|
queryParameters: view.queryParameters(arguments),
|
|
|
|
).toString();
|
|
|
|
await push(uri);
|
2023-10-23 18:35:07 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
extension on ViewPB {
|
|
|
|
String get routeName {
|
|
|
|
switch (layout) {
|
|
|
|
case ViewLayoutPB.Document:
|
2024-03-21 12:26:48 +07:00
|
|
|
return MobileDocumentScreen.routeName;
|
2023-10-23 18:35:07 +08:00
|
|
|
case ViewLayoutPB.Grid:
|
|
|
|
return MobileGridScreen.routeName;
|
|
|
|
case ViewLayoutPB.Calendar:
|
|
|
|
return MobileCalendarScreen.routeName;
|
|
|
|
case ViewLayoutPB.Board:
|
|
|
|
return MobileBoardScreen.routeName;
|
2024-06-03 14:27:28 +08:00
|
|
|
case ViewLayoutPB.Chat:
|
|
|
|
return MobileChatScreen.routeName;
|
|
|
|
|
2023-10-23 18:35:07 +08:00
|
|
|
default:
|
|
|
|
throw UnimplementedError('routeName for $this is not implemented');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-24 15:15:57 +01:00
|
|
|
Map<String, dynamic> queryParameters([Map<String, dynamic>? arguments]) {
|
2023-10-23 18:35:07 +08:00
|
|
|
switch (layout) {
|
|
|
|
case ViewLayoutPB.Document:
|
|
|
|
return {
|
2024-03-21 12:26:48 +07:00
|
|
|
MobileDocumentScreen.viewId: id,
|
|
|
|
MobileDocumentScreen.viewTitle: name,
|
2023-10-23 18:35:07 +08:00
|
|
|
};
|
|
|
|
case ViewLayoutPB.Grid:
|
|
|
|
return {
|
|
|
|
MobileGridScreen.viewId: id,
|
|
|
|
MobileGridScreen.viewTitle: name,
|
2024-01-24 15:15:57 +01:00
|
|
|
MobileGridScreen.viewArgs: jsonEncode(arguments),
|
2023-10-23 18:35:07 +08:00
|
|
|
};
|
|
|
|
case ViewLayoutPB.Calendar:
|
|
|
|
return {
|
|
|
|
MobileCalendarScreen.viewId: id,
|
|
|
|
MobileCalendarScreen.viewTitle: name,
|
|
|
|
};
|
|
|
|
case ViewLayoutPB.Board:
|
|
|
|
return {
|
|
|
|
MobileBoardScreen.viewId: id,
|
|
|
|
MobileBoardScreen.viewTitle: name,
|
|
|
|
};
|
2024-06-03 14:27:28 +08:00
|
|
|
case ViewLayoutPB.Chat:
|
|
|
|
return {
|
|
|
|
MobileChatScreen.viewId: id,
|
|
|
|
MobileChatScreen.viewTitle: name,
|
|
|
|
};
|
2023-10-23 18:35:07 +08:00
|
|
|
default:
|
|
|
|
throw UnimplementedError(
|
|
|
|
'queryParameters for $this is not implemented',
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|