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