✨ Leave realm
This commit is contained in:
parent
226eb452e5
commit
04065061e0
@ -648,5 +648,7 @@
|
||||
"realmIsPublic": "Public Realm",
|
||||
"realmIsPublicDescription": "The realm is public, anyone can join.",
|
||||
"realmIsCommunity": "Community Realm",
|
||||
"realmIsCommunityDescription": "Community realm will be displayed on the discover page."
|
||||
"realmIsCommunityDescription": "Community realm will be displayed on the discover page.",
|
||||
"realmLeave": "Leave Realm",
|
||||
"realmLeaveDescription": "Leave the current realm and delete the realm's identity."
|
||||
}
|
||||
|
@ -647,5 +647,7 @@
|
||||
"realmIsPublic": "公开领域",
|
||||
"realmIsPublicDescription": "该领域是公开的,任何人都可以加入。",
|
||||
"realmIsCommunity": "社区领域",
|
||||
"realmIsCommunityDescription": "社区领域会显示在发现页面上。"
|
||||
"realmIsCommunityDescription": "社区领域会显示在发现页面上。",
|
||||
"realmLeave": "离开领域",
|
||||
"realmLeaveDescription": "离开当前领域,并且删除领域中的身份。"
|
||||
}
|
||||
|
@ -357,6 +357,28 @@ class _RealmSettingsWidgetState extends State<_RealmSettingsWidget> {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _leaveRealm() async {
|
||||
final confirm = await context.showConfirmDialog(
|
||||
'realmLeave'.tr(),
|
||||
'realmLeaveDescription'.tr(),
|
||||
);
|
||||
if (!confirm) return;
|
||||
if (!mounted) return;
|
||||
|
||||
final sn = context.read<SnNetworkProvider>();
|
||||
|
||||
try {
|
||||
await sn.client.delete('/cgi/id/realms/${widget.realm!.alias}/members/me');
|
||||
if (!mounted) return;
|
||||
Navigator.pop(context, true);
|
||||
} catch (err) {
|
||||
if (!mounted) return;
|
||||
context.showErrorDialog(err);
|
||||
} finally {
|
||||
setState(() => _isBusy = false);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final ua = context.read<UserProvider>();
|
||||
@ -367,22 +389,31 @@ class _RealmSettingsWidgetState extends State<_RealmSettingsWidget> {
|
||||
children: [
|
||||
const Gap(8),
|
||||
ListTile(
|
||||
leading: const Icon(Symbols.edit),
|
||||
leading: const Icon(Symbols.logout),
|
||||
trailing: const Icon(Symbols.chevron_right),
|
||||
title: Text('realmEdit').tr(),
|
||||
subtitle: Text('realmEditDescription').tr(),
|
||||
title: Text('realmLeave').tr(),
|
||||
subtitle: Text('realmLeaveDescription').tr(),
|
||||
contentPadding: const EdgeInsets.symmetric(horizontal: 24),
|
||||
onTap: () {
|
||||
GoRouter.of(context).pushNamed(
|
||||
'realmManage',
|
||||
queryParameters: {'editing': widget.realm!.alias},
|
||||
).then((value) {
|
||||
if (value != null) {
|
||||
widget.onUpdate();
|
||||
}
|
||||
});
|
||||
},
|
||||
onTap: _isBusy ? null : () => _leaveRealm(),
|
||||
),
|
||||
if (isOwned)
|
||||
ListTile(
|
||||
leading: const Icon(Symbols.edit),
|
||||
trailing: const Icon(Symbols.chevron_right),
|
||||
title: Text('realmEdit').tr(),
|
||||
subtitle: Text('realmEditDescription').tr(),
|
||||
contentPadding: const EdgeInsets.symmetric(horizontal: 24),
|
||||
onTap: () {
|
||||
GoRouter.of(context).pushNamed(
|
||||
'realmManage',
|
||||
queryParameters: {'editing': widget.realm!.alias},
|
||||
).then((value) {
|
||||
if (value != null) {
|
||||
widget.onUpdate();
|
||||
}
|
||||
});
|
||||
},
|
||||
),
|
||||
if (isOwned)
|
||||
ListTile(
|
||||
leading: const Icon(Symbols.delete),
|
||||
|
Loading…
x
Reference in New Issue
Block a user