Compare commits

...

2 Commits

Author SHA1 Message Date
32739821ba Publisher popover 2024-12-01 20:08:04 +08:00
000caf4dd2 Publisher personal & organization management 2024-12-01 14:33:47 +08:00
8 changed files with 473 additions and 15 deletions

View File

@ -99,6 +99,12 @@
"publishersNew": "New Publisher", "publishersNew": "New Publisher",
"publisherNewSubtitle": "Create a new publisher identity.", "publisherNewSubtitle": "Create a new publisher identity.",
"publisherSyncWithAccount": "Sync with account", "publisherSyncWithAccount": "Sync with account",
"publisherTotalUpvote": "Upvote",
"publisherTotalDownvote": "Downvote",
"publisherSocialPoint": "Social Point",
"publisherJoinedAt": "Joined At",
"fieldPublisherBelongToRealm": "Belongs to",
"fieldPublisherBelongToRealmUnset": "Unset Publisher Belongs to Realm",
"writePostTypeStory": "Post a story", "writePostTypeStory": "Post a story",
"writePostTypeArticle": "Write an article", "writePostTypeArticle": "Write an article",
"fieldPostPublisher": "Post publisher", "fieldPostPublisher": "Post publisher",

View File

@ -99,6 +99,12 @@
"publishersNew": "新发布者", "publishersNew": "新发布者",
"publisherNewSubtitle": "创建一个新的公共身份。", "publisherNewSubtitle": "创建一个新的公共身份。",
"publisherSyncWithAccount": "同步账户信息", "publisherSyncWithAccount": "同步账户信息",
"publisherTotalUpvote": "总顶数",
"publisherTotalDownvote": "总踩数",
"publisherSocialPoint": "社会信用点",
"publisherJoinedAt": "加入于",
"fieldPublisherBelongToRealm": "所属领域",
"fieldPublisherBelongToRealmUnset": "未设置发布者所属领域",
"writePostTypeStory": "发动态", "writePostTypeStory": "发动态",
"writePostTypeArticle": "写文章", "writePostTypeArticle": "写文章",
"fieldPostPublisher": "帖子发布者", "fieldPostPublisher": "帖子发布者",

View File

@ -267,11 +267,14 @@ class _AccountPublisherEditScreenState
Row( Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween, mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [ children: [
if (_publisher?.type == 0)
TextButton.icon( TextButton.icon(
onPressed: _syncWithAccount, onPressed: _syncWithAccount,
label: Text('publisherSyncWithAccount').tr(), label: Text('publisherSyncWithAccount').tr(),
icon: const Icon(Symbols.sync), icon: const Icon(Symbols.sync),
), )
else
const SizedBox(),
ElevatedButton.icon( ElevatedButton.icon(
onPressed: _isBusy ? null : _performAction, onPressed: _isBusy ? null : _performAction,
label: Text('apply').tr(), label: Text('apply').tr(),

View File

@ -1,3 +1,4 @@
import 'package:dropdown_button2/dropdown_button2.dart';
import 'package:easy_localization/easy_localization.dart'; import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:gap/gap.dart'; import 'package:gap/gap.dart';
@ -6,6 +7,7 @@ import 'package:provider/provider.dart';
import 'package:styled_widget/styled_widget.dart'; import 'package:styled_widget/styled_widget.dart';
import 'package:surface/providers/sn_network.dart'; import 'package:surface/providers/sn_network.dart';
import 'package:surface/providers/userinfo.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/account/account_image.dart';
import 'package:surface/widgets/dialog.dart'; import 'package:surface/widgets/dialog.dart';
@ -47,6 +49,7 @@ class _AccountPublisherNewScreenState extends State<AccountPublisherNewScreen> {
), ),
switch (mode) { switch (mode) {
'personal' => const _PublisherNewPersonal(), 'personal' => const _PublisherNewPersonal(),
'organization' => const _PublisherNewOrganization(),
_ => const Placeholder(), _ => const Placeholder(),
}, },
], ],
@ -66,6 +69,10 @@ class _PublisherNewPersonal extends StatefulWidget {
class _PublisherNewPersonalState extends State<_PublisherNewPersonal> { class _PublisherNewPersonalState extends State<_PublisherNewPersonal> {
bool _isBusy = false; bool _isBusy = false;
final TextEditingController _nameController = TextEditingController();
final TextEditingController _nickController = TextEditingController();
final TextEditingController _descriptionController = TextEditingController();
void _performAction() async { void _performAction() async {
final sn = context.read<SnNetworkProvider>(); final sn = context.read<SnNetworkProvider>();
final ua = context.read<UserProvider>(); final ua = context.read<UserProvider>();
@ -74,15 +81,48 @@ class _PublisherNewPersonalState extends State<_PublisherNewPersonal> {
setState(() => _isBusy = true); setState(() => _isBusy = true);
try { try {
await sn.client.post('/cgi/co/publishers/personal'); await sn.client.post('/cgi/co/publishers/personal', data: {
'name': _nameController.text,
'nick': _nickController.text,
'description': _descriptionController.text,
'avatar': ua.user!.avatar,
'banner': ua.user!.banner,
});
if (!mounted) return;
Navigator.pop(context, true); Navigator.pop(context, true);
} catch (err) { } catch (err) {
if (!mounted) return;
context.showErrorDialog(err); context.showErrorDialog(err);
} finally { } finally {
setState(() => _isBusy = false); setState(() => _isBusy = false);
} }
} }
void _syncState() {
final ua = context.read<UserProvider>();
if (ua.user == null) return;
_nameController.text = ua.user!.name;
_nickController.text = ua.user!.nick;
_descriptionController.text = ua.user!.description;
}
@override
void initState() {
super.initState();
_syncState();
_nameController.addListener(() => setState(() => {}));
_nickController.addListener(() => setState(() => {}));
}
@override
void dispose() {
super.dispose();
_nameController.dispose();
_nickController.dispose();
_descriptionController.dispose();
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final ua = context.watch<UserProvider>(); final ua = context.watch<UserProvider>();
@ -90,10 +130,41 @@ class _PublisherNewPersonalState extends State<_PublisherNewPersonal> {
return Column( return Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
Text('preview') Column(
.tr() children: [
.textStyle(Theme.of(context).textTheme.titleMedium!) TextField(
.padding(horizontal: 16, vertical: 4), controller: _nameController,
decoration: InputDecoration(
labelText: 'fieldUsername'.tr(),
helperText: 'fieldUsernameCannotEditHint'.tr(),
helperMaxLines: 2,
),
onTapOutside: (_) =>
FocusManager.instance.primaryFocus?.unfocus(),
),
const Gap(4),
TextField(
controller: _nickController,
decoration: InputDecoration(
labelText: 'fieldNickname'.tr(),
),
onTapOutside: (_) =>
FocusManager.instance.primaryFocus?.unfocus(),
),
const Gap(4),
TextField(
controller: _descriptionController,
minLines: 3,
maxLines: null,
decoration: InputDecoration(
labelText: 'fieldDescription'.tr(),
),
onTapOutside: (_) =>
FocusManager.instance.primaryFocus?.unfocus(),
),
],
).padding(horizontal: 8),
const Gap(16),
Card( Card(
child: SizedBox( child: SizedBox(
width: double.infinity, width: double.infinity,
@ -105,10 +176,254 @@ class _PublisherNewPersonalState extends State<_PublisherNewPersonal> {
crossAxisAlignment: CrossAxisAlignment.baseline, crossAxisAlignment: CrossAxisAlignment.baseline,
textBaseline: TextBaseline.alphabetic, textBaseline: TextBaseline.alphabetic,
children: [ children: [
Text(ua.user!.nick) Text(_nickController.text)
.textStyle(Theme.of(context).textTheme.titleLarge!), .textStyle(Theme.of(context).textTheme.titleLarge!),
const Gap(4), const Gap(4),
Text('@${ua.user!.name}') Text('@${_nameController.text}')
.textStyle(Theme.of(context).textTheme.bodySmall!),
],
),
],
),
).padding(all: 16),
),
SizedBox(
width: double.infinity,
child: ElevatedButton.icon(
onPressed: _isBusy ? null : _performAction,
icon: const Icon(Symbols.add),
label: Text('create').tr(),
),
).padding(horizontal: 2),
],
);
}
}
class _PublisherNewOrganization extends StatefulWidget {
const _PublisherNewOrganization({super.key});
@override
State<_PublisherNewOrganization> createState() =>
_PublisherNewOrganizationState();
}
class _PublisherNewOrganizationState extends State<_PublisherNewOrganization> {
bool _isBusy = false;
final TextEditingController _nameController = TextEditingController();
final TextEditingController _nickController = TextEditingController();
final TextEditingController _descriptionController = TextEditingController();
void _performAction() async {
final sn = context.read<SnNetworkProvider>();
final ua = context.read<UserProvider>();
if (!ua.isAuthorized) return;
if (_belongToRealm == null) return;
setState(() => _isBusy = true);
try {
await sn.client.post('/cgi/co/publishers/organization', data: {
'realm': _belongToRealm!.alias,
'name': _nameController.text,
'nick': _nickController.text,
'description': _descriptionController.text,
'avatar': _belongToRealm!.avatar,
'banner': _belongToRealm!.banner,
});
if (!mounted) return;
Navigator.pop(context, true);
} catch (err) {
if (!mounted) return;
context.showErrorDialog(err);
} finally {
setState(() => _isBusy = false);
}
}
List<SnRealm>? _realms;
SnRealm? _belongToRealm;
Future<void> _fetchRealms() async {
setState(() => _isBusy = true);
try {
final sn = context.read<SnNetworkProvider>();
final resp = await sn.client.get('/cgi/id/realms/me/available');
_realms = List<SnRealm>.from(
resp.data?.map((e) => SnRealm.fromJson(e)) ?? [],
);
} catch (err) {
if (mounted) context.showErrorDialog(err);
} finally {
setState(() => _isBusy = false);
}
}
void _syncState() {
if (_belongToRealm == null) return;
_nameController.text = _belongToRealm!.alias;
_nickController.text = _belongToRealm!.name;
_descriptionController.text = _belongToRealm!.description;
}
@override
void initState() {
super.initState();
_fetchRealms();
}
@override
void dispose() {
super.dispose();
_nameController.dispose();
_nickController.dispose();
_descriptionController.dispose();
}
@override
Widget build(BuildContext context) {
return Column(
children: [
DropdownButtonHideUnderline(
child: DropdownButton2<SnRealm>(
isExpanded: true,
hint: Text(
'fieldPublisherBelongToRealm'.tr(),
style: TextStyle(
color: Theme.of(context).hintColor,
),
),
items: [
...(_realms?.map(
(SnRealm item) => DropdownMenuItem<SnRealm>(
value: item,
child: Row(
children: [
AccountImage(
content: item.avatar,
radius: 16,
fallbackWidget: const Icon(
Symbols.group,
size: 16,
),
),
const Gap(12),
Expanded(
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(item.name).textStyle(
Theme.of(context).textTheme.bodyMedium!),
Text(
item.description,
maxLines: 1,
overflow: TextOverflow.ellipsis,
).textStyle(
Theme.of(context).textTheme.bodySmall!),
],
),
),
],
),
),
) ??
[]),
DropdownMenuItem<SnRealm>(
value: null,
child: Row(
children: [
CircleAvatar(
radius: 16,
backgroundColor: Colors.transparent,
foregroundColor: Theme.of(context).colorScheme.onSurface,
child: const Icon(Symbols.clear),
),
const Gap(12),
Expanded(
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text('fieldPublisherBelongToRealmUnset')
.tr()
.textStyle(
Theme.of(context).textTheme.bodyMedium!,
),
],
),
),
],
),
),
],
value: _belongToRealm,
onChanged: (SnRealm? value) {
_belongToRealm = value;
_syncState();
setState(() {});
},
buttonStyleData: const ButtonStyleData(
padding: EdgeInsets.only(right: 16),
height: 60,
),
menuItemStyleData: const MenuItemStyleData(
height: 60,
),
),
),
Column(
children: [
TextField(
controller: _nameController,
decoration: InputDecoration(
labelText: 'fieldUsername'.tr(),
helperText: 'fieldUsernameCannotEditHint'.tr(),
helperMaxLines: 2,
),
onTapOutside: (_) =>
FocusManager.instance.primaryFocus?.unfocus(),
),
const Gap(4),
TextField(
controller: _nickController,
decoration: InputDecoration(
labelText: 'fieldNickname'.tr(),
),
onTapOutside: (_) =>
FocusManager.instance.primaryFocus?.unfocus(),
),
const Gap(4),
TextField(
controller: _descriptionController,
minLines: 3,
maxLines: null,
decoration: InputDecoration(
labelText: 'fieldDescription'.tr(),
),
onTapOutside: (_) =>
FocusManager.instance.primaryFocus?.unfocus(),
),
],
).padding(horizontal: 8),
const Gap(16),
Card(
child: SizedBox(
width: double.infinity,
child: Row(
children: [
AccountImage(content: _belongToRealm?.avatar, radius: 24),
const Gap(16),
Column(
crossAxisAlignment: CrossAxisAlignment.baseline,
textBaseline: TextBaseline.alphabetic,
children: [
Text(_nickController.text)
.textStyle(Theme.of(context).textTheme.titleLarge!),
const Gap(4),
Text('@${_nameController.text}')
.textStyle(Theme.of(context).textTheme.bodySmall!), .textStyle(Theme.of(context).textTheme.bodySmall!),
], ],
), ),

View File

@ -2,6 +2,7 @@ import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart'; import 'package:go_router/go_router.dart';
import 'package:material_symbols_icons/symbols.dart'; import 'package:material_symbols_icons/symbols.dart';
import 'package:popover/popover.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
import 'package:relative_time/relative_time.dart'; import 'package:relative_time/relative_time.dart';
import 'package:styled_widget/styled_widget.dart'; import 'package:styled_widget/styled_widget.dart';
@ -15,6 +16,7 @@ import 'package:surface/widgets/markdown_content.dart';
import 'package:gap/gap.dart'; import 'package:gap/gap.dart';
import 'package:surface/widgets/post/post_comment_list.dart'; import 'package:surface/widgets/post/post_comment_list.dart';
import 'package:surface/widgets/post/post_reaction.dart'; import 'package:surface/widgets/post/post_reaction.dart';
import 'package:surface/widgets/post/publisher_popover.dart';
class PostItem extends StatelessWidget { class PostItem extends StatelessWidget {
final SnPost data; final SnPost data;
@ -264,10 +266,28 @@ class _PostContentHeader extends StatelessWidget {
return Row( return Row(
children: [ children: [
AccountImage( GestureDetector(
child: AccountImage(
content: data.publisher.avatar, content: data.publisher.avatar,
radius: isCompact ? 12 : 20, radius: isCompact ? 12 : 20,
), ),
onTap: () {
showPopover(
context: context,
transition: PopoverTransition.other,
bodyBuilder: (context) => SizedBox(
width: 400,
child: PublisherPopoverCard(
data: data.publisher,
).padding(horizontal: 16, vertical: 16),
),
direction: PopoverDirection.bottom,
arrowHeight: 5,
arrowWidth: 15,
arrowDxOffset: -190,
);
},
),
Gap(isCompact ? 8 : 12), Gap(isCompact ? 8 : 12),
if (isCompact) if (isCompact)
Row( Row(

View File

@ -0,0 +1,99 @@
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
import 'package:gap/gap.dart';
import 'package:material_symbols_icons/symbols.dart';
import 'package:styled_widget/styled_widget.dart';
import 'package:surface/types/post.dart';
import 'package:surface/widgets/account/account_image.dart';
class PublisherPopoverCard extends StatelessWidget {
final SnPublisher data;
const PublisherPopoverCard({super.key, required this.data});
@override
Widget build(BuildContext context) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: [
Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
AccountImage(
content: data.avatar,
radius: 20,
),
Gap(16),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: [
Text(data.nick).bold(),
Text('@${data.name}').fontSize(13).opacity(0.75),
],
),
),
IconButton(
onPressed: () {},
icon: const Icon(Symbols.chevron_right),
padding: EdgeInsets.zero,
visualDensity: const VisualDensity(horizontal: -4, vertical: -4),
),
const Gap(8)
],
),
const Gap(16),
Row(
children: [
Expanded(
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text('publisherSocialPoint').tr().fontSize(13).opacity(0.75),
Text((data.totalUpvote - data.totalDownvote).toString()),
],
),
),
SizedBox(
height: 20,
child: const VerticalDivider(
thickness: 1,
),
).padding(horizontal: 8),
Expanded(
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text('publisherTotalUpvote').tr().fontSize(13).opacity(0.75),
Text(data.totalUpvote.toString()),
],
),
),
SizedBox(
height: 20,
child: const VerticalDivider(
thickness: 1,
),
).padding(horizontal: 8),
Expanded(
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text('publisherTotalDownvote')
.tr()
.fontSize(13)
.opacity(0.75),
Text(data.totalDownvote.toString()),
],
),
),
],
),
],
);
}
}

View File

@ -1330,6 +1330,14 @@ packages:
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "1.5.1" version: "1.5.1"
popover:
dependency: "direct main"
description:
name: popover
sha256: "0606f3e10f92fc0459f5c52fd917738c29e7552323b28694d50c2d3312d0e1a2"
url: "https://pub.dev"
source: hosted
version: "0.3.1"
protobuf: protobuf:
dependency: transitive dependency: transitive
description: description:

View File

@ -93,6 +93,7 @@ dependencies:
wakelock_plus: ^1.2.8 wakelock_plus: ^1.2.8
permission_handler: ^11.3.1 permission_handler: ^11.3.1
flutter_staggered_grid_view: ^0.7.0 flutter_staggered_grid_view: ^0.7.0
popover: ^0.3.1
dev_dependencies: dev_dependencies:
flutter_test: flutter_test: