2021-09-14 23:45:26 +02:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_hooks/flutter_hooks.dart';
|
|
|
|
import 'package:provider/provider.dart';
|
|
|
|
|
2021-10-02 17:42:28 +02:00
|
|
|
import '../../../hooks/stores.dart';
|
2021-10-02 20:01:33 +02:00
|
|
|
import '../../../l10n/l10n_from_string.dart';
|
2021-10-02 17:42:28 +02:00
|
|
|
import '../../../stores/accounts_store.dart';
|
|
|
|
import '../../../util/observer_consumers.dart';
|
2021-10-02 20:05:42 +02:00
|
|
|
import 'block_tile.dart';
|
2021-09-14 23:45:26 +02:00
|
|
|
import 'blocks_store.dart';
|
|
|
|
|
|
|
|
class BlocksPage extends HookWidget {
|
|
|
|
const BlocksPage();
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
final accStore = useAccountsStore();
|
|
|
|
|
|
|
|
return DefaultTabController(
|
|
|
|
length: accStore.loggedInInstances.length,
|
|
|
|
child: Scaffold(
|
|
|
|
appBar: AppBar(
|
|
|
|
title: const Text('Blocks'),
|
|
|
|
bottom: TabBar(
|
|
|
|
isScrollable: true,
|
|
|
|
tabs: [
|
|
|
|
for (final instance in accStore.loggedInInstances)
|
|
|
|
Tab(
|
|
|
|
child: Text(
|
|
|
|
'${accStore.defaultUsernameFor(instance)!}@$instance'),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
body: TabBarView(
|
|
|
|
children: [
|
|
|
|
for (final instance in accStore.loggedInInstances)
|
2021-10-02 18:48:00 +02:00
|
|
|
_UserBlocksWrapper(
|
2021-09-14 23:45:26 +02:00
|
|
|
instanceHost: instance,
|
|
|
|
username: accStore.defaultUsernameFor(instance)!,
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
2021-10-02 18:48:00 +02:00
|
|
|
|
|
|
|
static Route route() =>
|
|
|
|
MaterialPageRoute(builder: (context) => const BlocksPage());
|
2021-09-14 23:45:26 +02:00
|
|
|
}
|
|
|
|
|
2021-10-02 18:48:00 +02:00
|
|
|
class _UserBlocksWrapper extends StatelessWidget {
|
2021-09-14 23:45:26 +02:00
|
|
|
final String instanceHost;
|
|
|
|
final String username;
|
|
|
|
|
2021-10-02 18:48:00 +02:00
|
|
|
const _UserBlocksWrapper(
|
|
|
|
{required this.instanceHost, required this.username});
|
2021-09-14 23:45:26 +02:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Provider<BlocksStore>(
|
|
|
|
create: (context) => BlocksStore(
|
|
|
|
instanceHost: instanceHost,
|
|
|
|
token: context
|
|
|
|
.read<AccountsStore>()
|
|
|
|
.userDataFor(instanceHost, username)!
|
|
|
|
.jwt,
|
2021-10-02 18:48:00 +02:00
|
|
|
)..refresh(),
|
2021-09-14 23:45:26 +02:00
|
|
|
child: const _UserBlocks(),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-02 20:01:33 +02:00
|
|
|
class _UserBlocks extends StatelessWidget {
|
2021-09-14 23:45:26 +02:00
|
|
|
const _UserBlocks();
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return ObserverBuilder<BlocksStore>(
|
|
|
|
builder: (context, store) {
|
|
|
|
return RefreshIndicator(
|
|
|
|
onRefresh: store.refresh,
|
|
|
|
child: ListView(
|
|
|
|
children: [
|
|
|
|
if (store.blocksState.isLoading &&
|
|
|
|
store.blockedCommunities.isEmpty &&
|
|
|
|
store.blockedUsers.isEmpty)
|
|
|
|
const Padding(
|
|
|
|
padding: EdgeInsets.only(top: 64),
|
|
|
|
child: Center(child: CircularProgressIndicator.adaptive()),
|
|
|
|
)
|
|
|
|
else if (store.blocksState.errorTerm != null)
|
2021-10-02 18:48:00 +02:00
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.only(top: 64),
|
2021-10-02 20:01:33 +02:00
|
|
|
child: Center(
|
|
|
|
child: Text(store.blocksState.errorTerm!.tr(context))),
|
2021-09-14 23:45:26 +02:00
|
|
|
)
|
|
|
|
else ...[
|
|
|
|
for (final user in store.blockedUsers)
|
2021-10-02 20:05:42 +02:00
|
|
|
BlockPersonTile(user, key: ValueKey(user)),
|
2021-09-14 23:45:26 +02:00
|
|
|
if (store.blockedUsers.isEmpty)
|
|
|
|
const ListTile(
|
2021-10-02 18:48:00 +02:00
|
|
|
title: Center(
|
|
|
|
child: Text('No users blocked'),
|
|
|
|
),
|
|
|
|
),
|
2021-10-01 23:14:19 +02:00
|
|
|
// TODO: add user search & block
|
|
|
|
// ListTile(
|
|
|
|
// leading: const Padding(
|
|
|
|
// padding: EdgeInsets.only(left: 16, right: 10),
|
|
|
|
// child: Icon(Icons.add),
|
|
|
|
// ),
|
|
|
|
// onTap: () {},
|
|
|
|
// title: const Text('Block User'),
|
|
|
|
// ),
|
2021-09-14 23:45:26 +02:00
|
|
|
const Divider(),
|
|
|
|
for (final community in store.blockedCommunities)
|
2021-10-02 20:05:42 +02:00
|
|
|
BlockCommunityTile(community, key: ValueKey(community)),
|
2021-09-14 23:45:26 +02:00
|
|
|
if (store.blockedCommunities.isEmpty)
|
|
|
|
const ListTile(
|
2021-10-01 23:14:19 +02:00
|
|
|
title: Center(
|
|
|
|
child: Text('No communities blocked'),
|
|
|
|
),
|
2021-09-14 23:45:26 +02:00
|
|
|
),
|
2021-10-01 23:14:19 +02:00
|
|
|
// TODO: add community search & block
|
|
|
|
// const ListTile(
|
|
|
|
// leading: Padding(
|
|
|
|
// padding: EdgeInsets.only(left: 16, right: 10),
|
|
|
|
// child: Icon(Icons.add),
|
|
|
|
// ),
|
|
|
|
// onTap: () {},
|
|
|
|
// title: Text('Block Community'),
|
|
|
|
// ),
|
2021-09-14 23:45:26 +02:00
|
|
|
]
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|