2021-09-14 23:45:26 +02:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_hooks/flutter_hooks.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';
|
2021-10-02 23:15:15 +02:00
|
|
|
import '../../../util/async_store_listener.dart';
|
2021-10-02 17:42:28 +02:00
|
|
|
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 {
|
2021-10-19 21:36:54 +02:00
|
|
|
const BlocksPage._();
|
2021-09-14 23:45:26 +02:00
|
|
|
@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() =>
|
2021-10-19 21:36:54 +02:00
|
|
|
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) {
|
2021-10-02 23:15:15 +02:00
|
|
|
return AsyncStoreListener(
|
|
|
|
asyncStore: context.read<BlocksStore>().blocksState,
|
|
|
|
child: ObserverBuilder<BlocksStore>(
|
|
|
|
builder: (context, store) {
|
|
|
|
return RefreshIndicator(
|
|
|
|
onRefresh: store.refresh,
|
|
|
|
child: ListView(
|
|
|
|
children: [
|
|
|
|
if (!store.isUsable) ...[
|
|
|
|
if (store.blocksState.isLoading)
|
|
|
|
const Padding(
|
|
|
|
padding: EdgeInsets.only(top: 64),
|
|
|
|
child: Center(
|
|
|
|
child: CircularProgressIndicator.adaptive(),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
else if (store.blocksState.errorTerm != null)
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.only(top: 64),
|
|
|
|
child: Center(
|
|
|
|
child: Text(
|
|
|
|
store.blocksState.errorTerm!.tr(context),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
] else ...[
|
|
|
|
for (final user in store.blockedUsers!)
|
|
|
|
Provider(
|
|
|
|
create: (context) => user,
|
|
|
|
key: ValueKey(user),
|
|
|
|
child: const BlockPersonTile(),
|
2021-10-02 18:48:00 +02:00
|
|
|
),
|
2021-10-02 23:15:15 +02:00
|
|
|
if (store.blockedUsers!.isEmpty)
|
|
|
|
const ListTile(
|
|
|
|
title: Center(
|
|
|
|
child: Text('No users blocked'),
|
|
|
|
),
|
2021-10-01 23:14:19 +02:00
|
|
|
),
|
2021-10-02 23:15:15 +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'),
|
|
|
|
// ),
|
|
|
|
const Divider(),
|
|
|
|
for (final community in store.blockedCommunities!)
|
|
|
|
Provider(
|
|
|
|
create: (context) => community,
|
|
|
|
key: ValueKey(community),
|
|
|
|
child: const BlockCommunityTile(),
|
|
|
|
),
|
|
|
|
if (store.blockedCommunities!.isEmpty)
|
|
|
|
const ListTile(
|
|
|
|
title: Center(
|
|
|
|
child: Text('No communities blocked'),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
// 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
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|