✨ New friendship
This commit is contained in:
parent
5346224f1e
commit
47c10a180a
@ -36,6 +36,9 @@
|
|||||||
"friendActive": "Active",
|
"friendActive": "Active",
|
||||||
"friendBlocked": "Blocked",
|
"friendBlocked": "Blocked",
|
||||||
"friendListHint": "Swipe left to decline, swipe right to approve",
|
"friendListHint": "Swipe left to decline, swipe right to approve",
|
||||||
|
"friendAdd": "Add friend",
|
||||||
|
"friendAddHint": "Use your their username to send a friend request to your best friend!",
|
||||||
|
"friendAddDone": "Friend request sent, go reach your friend!",
|
||||||
"reaction": "Reaction",
|
"reaction": "Reaction",
|
||||||
"reactVerb": "React",
|
"reactVerb": "React",
|
||||||
"post": "Post",
|
"post": "Post",
|
||||||
|
@ -36,6 +36,9 @@
|
|||||||
"friendActive": "活跃的好友",
|
"friendActive": "活跃的好友",
|
||||||
"friendBlocked": "封锁中",
|
"friendBlocked": "封锁中",
|
||||||
"friendListHint": "左滑来拒绝,右滑来接受",
|
"friendListHint": "左滑来拒绝,右滑来接受",
|
||||||
|
"friendAdd": "添加好友",
|
||||||
|
"friendAddHint": "使用用户名来给你的好朋友发一个好友请求吧!",
|
||||||
|
"friendAddDone": "好友请求已发送,快告诉你的朋友吧!",
|
||||||
"reaction": "反应",
|
"reaction": "反应",
|
||||||
"reactVerb": "作出反应",
|
"reactVerb": "作出反应",
|
||||||
"post": "帖子",
|
"post": "帖子",
|
||||||
|
@ -46,6 +46,30 @@ class _FriendScreenState extends State<FriendScreen> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> createFriendship(String username) async {
|
||||||
|
setState(() => _isSubmitting = true);
|
||||||
|
|
||||||
|
final auth = context.read<AuthProvider>();
|
||||||
|
if (!await auth.isAuthorized()) {
|
||||||
|
setState(() => _isSubmitting = false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var res = await auth.client!.post(
|
||||||
|
getRequestUri('passport', '/api/users/me/friends?related=$username'),
|
||||||
|
);
|
||||||
|
if (res.statusCode == 200) {
|
||||||
|
await fetchFriendships();
|
||||||
|
} else {
|
||||||
|
var message = utf8.decode(res.bodyBytes);
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
SnackBar(content: Text("Something went wrong... $message")),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
setState(() => _isSubmitting = false);
|
||||||
|
}
|
||||||
|
|
||||||
Future<void> updateFriendship(Friendship relation, int status) async {
|
Future<void> updateFriendship(Friendship relation, int status) async {
|
||||||
setState(() => _isSubmitting = true);
|
setState(() => _isSubmitting = true);
|
||||||
|
|
||||||
@ -67,6 +91,9 @@ class _FriendScreenState extends State<FriendScreen> {
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
if (res.statusCode == 200) {
|
if (res.statusCode == 200) {
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
SnackBar(content: Text(AppLocalizations.of(context)!.friendAddDone)),
|
||||||
|
);
|
||||||
await fetchFriendships();
|
await fetchFriendships();
|
||||||
} else {
|
} else {
|
||||||
var message = utf8.decode(res.bodyBytes);
|
var message = utf8.decode(res.bodyBytes);
|
||||||
@ -78,6 +105,54 @@ class _FriendScreenState extends State<FriendScreen> {
|
|||||||
setState(() => _isSubmitting = false);
|
setState(() => _isSubmitting = false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void promptAddFriend() async {
|
||||||
|
final controller = TextEditingController();
|
||||||
|
final input = await showDialog(
|
||||||
|
context: context,
|
||||||
|
builder: (context) {
|
||||||
|
return AlertDialog(
|
||||||
|
title: Text(AppLocalizations.of(context)!.friendAdd),
|
||||||
|
content: Column(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
Text(AppLocalizations.of(context)!.friendAddHint),
|
||||||
|
const SizedBox(height: 18),
|
||||||
|
TextField(
|
||||||
|
controller: controller,
|
||||||
|
decoration: InputDecoration(
|
||||||
|
isDense: true,
|
||||||
|
prefixIcon: const Icon(Icons.account_circle),
|
||||||
|
border: const OutlineInputBorder(),
|
||||||
|
labelText: AppLocalizations.of(context)!.username,
|
||||||
|
),
|
||||||
|
onTapOutside: (_) => FocusManager.instance.primaryFocus?.unfocus(),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
actions: <Widget>[
|
||||||
|
TextButton(
|
||||||
|
style: TextButton.styleFrom(
|
||||||
|
foregroundColor: Theme.of(context).colorScheme.onSurface.withOpacity(0.8),
|
||||||
|
),
|
||||||
|
onPressed: () => Navigator.pop(context),
|
||||||
|
child: Text(AppLocalizations.of(context)!.cancel),
|
||||||
|
),
|
||||||
|
TextButton(
|
||||||
|
child: Text(AppLocalizations.of(context)!.next),
|
||||||
|
onPressed: () {
|
||||||
|
Navigator.pop(context, controller.text);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
WidgetsBinding.instance.addPostFrameCallback((_) => controller.dispose());
|
||||||
|
|
||||||
|
await createFriendship(input);
|
||||||
|
}
|
||||||
|
|
||||||
List<Friendship> filterWithStatus(int status) {
|
List<Friendship> filterWithStatus(int status) {
|
||||||
return _friendships.where((x) => x.status == status).toList();
|
return _friendships.where((x) => x.status == status).toList();
|
||||||
}
|
}
|
||||||
@ -153,6 +228,12 @@ class _FriendScreenState extends State<FriendScreen> {
|
|||||||
|
|
||||||
return IndentWrapper(
|
return IndentWrapper(
|
||||||
title: AppLocalizations.of(context)!.friend,
|
title: AppLocalizations.of(context)!.friend,
|
||||||
|
appBarActions: [
|
||||||
|
IconButton(
|
||||||
|
icon: const Icon(Icons.add),
|
||||||
|
onPressed: () => promptAddFriend(),
|
||||||
|
),
|
||||||
|
],
|
||||||
child: RefreshIndicator(
|
child: RefreshIndicator(
|
||||||
onRefresh: () => fetchFriendships(),
|
onRefresh: () => fetchFriendships(),
|
||||||
child: CustomScrollView(
|
child: CustomScrollView(
|
||||||
|
Loading…
Reference in New Issue
Block a user