Add auth to user profile fetching, fixes #118
This commit is contained in:
parent
eee7cbf612
commit
20ebcd0dfa
|
@ -2,6 +2,7 @@ import 'package:cached_network_image/cached_network_image.dart';
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_hooks/flutter_hooks.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:lemmur/hooks/memo_future.dart';
|
||||
import 'package:lemmy_api_client/v2.dart';
|
||||
import 'package:timeago/timeago.dart' as timeago;
|
||||
|
||||
|
@ -17,21 +18,35 @@ import 'sortable_infinite_list.dart';
|
|||
|
||||
/// Shared widget of UserPage and ProfileTab
|
||||
class UserProfile extends HookWidget {
|
||||
final Future<FullUserView> _userDetails;
|
||||
final String instanceHost;
|
||||
final int userId;
|
||||
|
||||
UserProfile({@required int userId, @required this.instanceHost})
|
||||
: _userDetails = LemmyApiV2(instanceHost).run(GetUserDetails(
|
||||
userId: userId, savedOnly: false, sort: SortType.active));
|
||||
final FullUserView _fullUserView;
|
||||
|
||||
UserProfile.fromFullUserView(FullUserView fullUserView)
|
||||
: _userDetails = Future.value(fullUserView),
|
||||
instanceHost = fullUserView.instanceHost;
|
||||
const UserProfile({@required this.userId, @required this.instanceHost})
|
||||
: assert(userId != null),
|
||||
assert(instanceHost != null),
|
||||
_fullUserView = null;
|
||||
|
||||
UserProfile.fromFullUserView(this._fullUserView)
|
||||
: assert(_fullUserView != null),
|
||||
userId = _fullUserView.userView.user.id,
|
||||
instanceHost = _fullUserView.instanceHost;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
final userDetailsSnap = useFuture(_userDetails, preserveState: false);
|
||||
final accountsStore = useAccountsStore();
|
||||
final userDetailsSnap = useMemoFuture(() async {
|
||||
if (_fullUserView != null) return _fullUserView;
|
||||
|
||||
return await LemmyApiV2(instanceHost).run(GetUserDetails(
|
||||
userId: userId,
|
||||
savedOnly: false,
|
||||
sort: SortType.active,
|
||||
auth: accountsStore.defaultTokenFor(instanceHost)?.raw,
|
||||
));
|
||||
});
|
||||
|
||||
if (!userDetailsSnap.hasData) {
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
|
@ -85,6 +100,7 @@ class UserProfile extends HookWidget {
|
|||
sort: SortType.active,
|
||||
page: page,
|
||||
limit: batchSize,
|
||||
auth: accountsStore.defaultTokenFor(instanceHost)?.raw,
|
||||
))
|
||||
.then((val) => val.posts),
|
||||
),
|
||||
|
@ -96,6 +112,7 @@ class UserProfile extends HookWidget {
|
|||
sort: SortType.active,
|
||||
page: page,
|
||||
limit: batchSize,
|
||||
auth: accountsStore.defaultTokenFor(instanceHost)?.raw,
|
||||
))
|
||||
.then((val) => val.comments),
|
||||
),
|
||||
|
|
Loading…
Reference in New Issue