diff --git a/lib/router.dart b/lib/router.dart index 1784d07f..0ff0e476 100644 --- a/lib/router.dart +++ b/lib/router.dart @@ -19,28 +19,21 @@ class ScreenPaths { static String settings = '/settings'; - // editorial static String wonderDetails(WonderType type, {required int tabIndex}) => '$home/wonder/${type.name}?t=$tabIndex'; - // add /home/wonderType/ - static String video(String id, {String? currentPath}) { - var value = '${currentPath ?? ''}/video/$id'; - // if(currentPath != null) { - // - // value = '${context.go}/$value'; - // } - return value; + + /// Dynamically nested pages, always added on to the existing path + static String video(String id) => _appendToCurrentPath('/video/$id'); + static String search(WonderType type) => _appendToCurrentPath('/search/${type.name}'); + static String maps(WonderType type) => _appendToCurrentPath('/maps/${type.name}'); + static String timeline(WonderType? type) => _appendToCurrentPath('/timeline?type=${type?.name ?? ''}'); + static String artifact(String id) => _appendToCurrentPath('/artifact/$id'); + static String collection(String id) => _appendToCurrentPath('/collection?id=$id'); + + static String _appendToCurrentPath(String newPath) { + final uri = appRouter.routeInformationProvider.value.uri; + Uri? loc = Uri(path: '${uri.path}$newPath', queryParameters: uri.queryParameters); + return loc.toString(); } - - static String search(WonderType type) => '/search/${type.name}'; - static String maps(WonderType type) => '/maps/${type.name}'; - - // both home/timeline and /home/wonderType/timeline - static String timeline(WonderType? type) => '/timeline?type=${type?.name ?? ''}'; - - // /collection, /search, /carousel, this should be a dialog... but then it can't be deep-linked? - static String artifact(String id) => '/artifact/$id'; - - static String collection(String id) => '/collection?id=$id'; } // Routes that are used multiple times @@ -92,6 +85,7 @@ final appRouter = GoRouter( routes: [ _timelineRoute, _collectionRoute, + _artifactRoute, // Youtube Video AppRoute('video/:id', (s) { return FullscreenVideoViewer(id: s.pathParameters['id']!); diff --git a/lib/ui/screens/editorial/widgets/_scrolling_content.dart b/lib/ui/screens/editorial/widgets/_scrolling_content.dart index db6e386b..1712164c 100644 --- a/lib/ui/screens/editorial/widgets/_scrolling_content.dart +++ b/lib/ui/screens/editorial/widgets/_scrolling_content.dart @@ -166,15 +166,19 @@ class _ScrollingContent extends StatelessWidget { } class _YouTubeThumbnail extends StatelessWidget { - const _YouTubeThumbnail({Key? key, required this.id, required this.caption}) : super(key: key); + const _YouTubeThumbnail({Key? key, required this.id, required this.caption, this.wonderType}) : super(key: key); final String id; final String caption; + final WonderType? wonderType; String get imageUrl => 'https://www.wonderous.info/youtube/$id.jpg'; @override Widget build(BuildContext context) { - void handlePressed() => context.push(ScreenPaths.video(id)); + void handlePressed() { + context.go(ScreenPaths.video(id)); + } + return MergeSemantics( child: ConstrainedBox( constraints: BoxConstraints(maxWidth: 400), @@ -227,7 +231,7 @@ class _MapsThumbnailState extends State<_MapsThumbnail> { @override Widget build(BuildContext context) { - void handlePressed() => context.push(ScreenPaths.maps(widget.data.type)); + void handlePressed() => context.go(ScreenPaths.maps(widget.data.type)); if (PlatformInfo.isDesktop) return SizedBox.shrink(); return AspectRatio( aspectRatio: 1.65,