Add support for `/u/user` and `/c/community` style of links
This commit is contained in:
parent
704daca4c7
commit
28bbe5b06f
|
@ -1,23 +1,36 @@
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:lemmur/pages/community.dart';
|
|
||||||
import 'package:lemmur/pages/full_post.dart';
|
|
||||||
import 'package:lemmur/pages/user.dart';
|
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
import 'package:url_launcher/url_launcher.dart' as ul;
|
import 'package:url_launcher/url_launcher.dart' as ul;
|
||||||
|
|
||||||
|
import 'pages/community.dart';
|
||||||
|
import 'pages/full_post.dart';
|
||||||
|
import 'pages/user.dart';
|
||||||
import 'stores/accounts_store.dart';
|
import 'stores/accounts_store.dart';
|
||||||
|
|
||||||
Future<void> urlLauncher(BuildContext c, String url) async {
|
Future<void> urlLauncher({
|
||||||
final instances = c.read<AccountsStore>().users.keys.toList();
|
@required BuildContext context,
|
||||||
print(instances);
|
@required String url,
|
||||||
|
@required String instanceUrl,
|
||||||
|
}) async {
|
||||||
|
push(Widget Function(BuildContext) builder) {
|
||||||
|
Navigator.of(context).push(MaterialPageRoute(builder: builder));
|
||||||
|
}
|
||||||
|
|
||||||
|
final instances = context.read<AccountsStore>().users.keys.toList();
|
||||||
|
|
||||||
|
final chonks = url.split('/');
|
||||||
|
|
||||||
// CHECK IF LINK TO USER
|
// CHECK IF LINK TO USER
|
||||||
|
if (chonks[1] == 'u') {
|
||||||
// TODO: link to user
|
return push((_) =>
|
||||||
|
UserPage.fromName(instanceUrl: instanceUrl, username: chonks[2]));
|
||||||
|
}
|
||||||
|
|
||||||
// CHECK IF LINK TO COMMUNITY
|
// CHECK IF LINK TO COMMUNITY
|
||||||
|
if (chonks[1] == 'c') {
|
||||||
// TODO; link to community
|
return push((_) => CommunityPage.fromName(
|
||||||
|
communityName: chonks[2], instanceUrl: instanceUrl));
|
||||||
|
}
|
||||||
|
|
||||||
// CHECK IF REDIRECTS TO A PAGE ON ONE OF ADDED INSTANCES
|
// CHECK IF REDIRECTS TO A PAGE ON ONE OF ADDED INSTANCES
|
||||||
|
|
||||||
|
@ -31,10 +44,6 @@ Future<void> urlLauncher(BuildContext c, String url) async {
|
||||||
print(rest.length);
|
print(rest.length);
|
||||||
|
|
||||||
if (instances.any((e) => e == match.group(1))) {
|
if (instances.any((e) => e == match.group(1))) {
|
||||||
push(Widget Function(BuildContext) builder) {
|
|
||||||
Navigator.of(c).push(MaterialPageRoute(builder: builder));
|
|
||||||
}
|
|
||||||
|
|
||||||
final split = rest.split('/');
|
final split = rest.split('/');
|
||||||
switch (split[1]) {
|
switch (split[1]) {
|
||||||
case 'c':
|
case 'c':
|
||||||
|
@ -81,7 +90,7 @@ Future<void> urlLauncher(BuildContext c, String url) async {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// REGULAR LINK STUFF
|
// FALLBACK TO REGULAR LINK STUFF
|
||||||
|
|
||||||
openInBrowser(url);
|
openInBrowser(url);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue