2024-01-24 15:15:57 +01:00
|
|
|
import 'dart:convert';
|
|
|
|
|
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';
|
2023-12-01 09:58:36 +08:00
|
|
|
import 'package:appflowy/workspace/application/recent/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:flutter/material.dart';
|
|
|
|
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-01-29 10:26:45 +08:00
|
|
|
await push(
|
2023-10-23 18:35:07 +08:00
|
|
|
Uri(
|
|
|
|
path: view.routeName,
|
2024-01-24 15:15:57 +01:00
|
|
|
queryParameters: view.queryParameters(arguments),
|
2023-10-23 18:35:07 +08:00
|
|
|
).toString(),
|
2023-12-01 09:58:36 +08:00
|
|
|
).then((value) {
|
|
|
|
RecentService().updateRecentViews([view.id], true);
|
|
|
|
});
|
2023-10-23 18:35:07 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
extension on ViewPB {
|
|
|
|
String get routeName {
|
|
|
|
switch (layout) {
|
|
|
|
case ViewLayoutPB.Document:
|
|
|
|
return MobileEditorScreen.routeName;
|
|
|
|
case ViewLayoutPB.Grid:
|
|
|
|
return MobileGridScreen.routeName;
|
|
|
|
case ViewLayoutPB.Calendar:
|
|
|
|
return MobileCalendarScreen.routeName;
|
|
|
|
case ViewLayoutPB.Board:
|
|
|
|
return MobileBoardScreen.routeName;
|
|
|
|
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 {
|
|
|
|
MobileEditorScreen.viewId: id,
|
|
|
|
MobileEditorScreen.viewTitle: name,
|
|
|
|
};
|
|
|
|
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,
|
|
|
|
};
|
|
|
|
default:
|
|
|
|
throw UnimplementedError(
|
|
|
|
'queryParameters for $this is not implemented',
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|