✨ Realm management
This commit is contained in:
parent
db9f4504db
commit
fc025c6bd3
@ -208,6 +208,10 @@
|
||||
"realmDeleted": "Realm {} has been deleted.",
|
||||
"realmDelete": "Delete realm {}",
|
||||
"realmDeleteDescription": "Are you sure you want to delete this realm? This operation is irreversible, all resources (posts, chat channels, publishers, etc) belonging to this realm will be permanently deleted. Be careful and think twice!",
|
||||
"realmActionDelete": "Delete Realm",
|
||||
"realmActionDeleteDescription": "Delete the realm and all its resources.",
|
||||
"realmEdit": "Edit Realm",
|
||||
"realmEditDescription": "Edit the basic information of the realm, metadata, etc.",
|
||||
"realmMemberAdd": "Add Member",
|
||||
"realmMemberAddDescription": "Add new member to this realm.",
|
||||
"realmMemberAdded": "Realm member has been added.",
|
||||
|
@ -208,6 +208,10 @@
|
||||
"realmDeleted": "领域 {} 已被删除",
|
||||
"realmDelete": "删除领域 {}",
|
||||
"realmDeleteDescription": "你确定要删除这个领域吗?该操作不可撤销,其隶属于该领域的所有资源(帖子、聊天频道、发布者、制品等)都将被永久删除。三思而后行!",
|
||||
"realmActionDelete": "删除领域",
|
||||
"realmActionDeleteDescription": "删除整个领域及其附属的资源。",
|
||||
"realmEdit": "编辑领域",
|
||||
"realmEditDescription": "更改领域基本信息,元数据等。",
|
||||
"realmMemberAdd": "添加成员",
|
||||
"realmMemberAddDescription": "给当前领域添加新成员。",
|
||||
"realmMemberAdded": "领域成员已添加。",
|
||||
|
@ -155,6 +155,12 @@ class _RealmScreenState extends State<RealmScreen> {
|
||||
),
|
||||
],
|
||||
),
|
||||
onTap: () {
|
||||
GoRouter.of(context).pushNamed(
|
||||
'realmDetail',
|
||||
pathParameters: {'alias': realm.alias},
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -1,11 +1,13 @@
|
||||
import 'package:easy_localization/easy_localization.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:gap/gap.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:material_symbols_icons/symbols.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:styled_widget/styled_widget.dart';
|
||||
import 'package:surface/providers/sn_network.dart';
|
||||
import 'package:surface/providers/user_directory.dart';
|
||||
import 'package:surface/providers/userinfo.dart';
|
||||
import 'package:surface/types/realm.dart';
|
||||
import 'package:surface/widgets/account/account_image.dart';
|
||||
import 'package:surface/widgets/dialog.dart';
|
||||
@ -77,7 +79,12 @@ class _RealmDetailScreenState extends State<RealmDetailScreen> {
|
||||
children: [
|
||||
_RealmDetailHomeWidget(realm: _realm),
|
||||
_RealmMemberListWidget(realm: _realm),
|
||||
const Icon(Symbols.home).center(),
|
||||
_RealmSettingsWidget(
|
||||
realm: _realm,
|
||||
onUpdate: () {
|
||||
_fetchRealm();
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
@ -326,3 +333,82 @@ class _NewRealmMemberWidgetState extends State<_NewRealmMemberWidget> {
|
||||
)).padding(all: 24);
|
||||
}
|
||||
}
|
||||
|
||||
class _RealmSettingsWidget extends StatefulWidget {
|
||||
final SnRealm? realm;
|
||||
final Function() onUpdate;
|
||||
const _RealmSettingsWidget(
|
||||
{super.key, required this.realm, required this.onUpdate});
|
||||
|
||||
@override
|
||||
State<_RealmSettingsWidget> createState() => _RealmSettingsWidgetState();
|
||||
}
|
||||
|
||||
class _RealmSettingsWidgetState extends State<_RealmSettingsWidget> {
|
||||
bool _isBusy = false;
|
||||
|
||||
Future<void> _deleteRealm() async {
|
||||
final confirm = await context.showConfirmDialog(
|
||||
'realmDelete'.tr(args: ['#${widget.realm!.alias}']),
|
||||
'realmDeleteDescription'.tr(),
|
||||
);
|
||||
if (!confirm) return;
|
||||
|
||||
if (!mounted) return;
|
||||
final sn = context.read<SnNetworkProvider>();
|
||||
|
||||
setState(() => _isBusy = true);
|
||||
|
||||
try {
|
||||
await sn.client.delete('/cgi/id/realms/${widget.realm!.alias}');
|
||||
if (!mounted) return;
|
||||
Navigator.pop(context, true);
|
||||
context.showSnackbar('realmDeleted'.tr(args: [
|
||||
'#${widget.realm!.alias}',
|
||||
]));
|
||||
} catch (err) {
|
||||
if (!mounted) return;
|
||||
context.showErrorDialog(err);
|
||||
} finally {
|
||||
setState(() => _isBusy = false);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final ua = context.read<UserProvider>();
|
||||
|
||||
final isOwned = ua.isAuthorized && widget.realm?.accountId == ua.user?.id;
|
||||
|
||||
return Column(
|
||||
children: [
|
||||
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),
|
||||
trailing: const Icon(Symbols.chevron_right),
|
||||
title: Text('realmActionDelete').tr(),
|
||||
subtitle: Text('realmActionDeleteDescription').tr(),
|
||||
contentPadding: const EdgeInsets.symmetric(horizontal: 24),
|
||||
onTap: _isBusy ? null : _deleteRealm,
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user