🐛 Bug fixes due to post editor changes

This commit is contained in:
LittleSheep 2025-03-08 16:04:51 +08:00
parent 5c483bd3b8
commit 92f7e92018
5 changed files with 50 additions and 22 deletions

View File

@ -69,6 +69,7 @@ final _appRoutes = [
path: '/write',
name: 'postEditor',
builder: (context, state) => PostEditorScreen(
mode: state.uri.queryParameters['mode'],
postEditId: int.tryParse(
state.uri.queryParameters['editing'] ?? '',
),

View File

@ -55,6 +55,7 @@ class PostEditorExtra {
}
class PostEditorScreen extends StatefulWidget {
final String? mode;
final int? postEditId;
final int? postReplyId;
final int? postRepostId;
@ -62,6 +63,7 @@ class PostEditorScreen extends StatefulWidget {
const PostEditorScreen({
super.key,
required this.mode,
required this.postEditId,
required this.postReplyId,
required this.postRepostId,
@ -226,6 +228,9 @@ class _PostEditorScreenState extends State<PostEditorScreen>
_registerHotKey();
_fetchRealms();
_fetchPublishers();
if (widget.mode != null) {
_writeController.setMode(widget.mode!);
}
_tabController.addListener(() {
if (_tabController.indexIsChanging) {
_writeController.setMode(kPostTypeAliases[_tabController.index]);
@ -270,7 +275,7 @@ class _PostEditorScreenState extends State<PostEditorScreen>
),
const Gap(8),
],
bottom: _writeController.isNotEmpty
bottom: _writeController.isNotEmpty || widget.mode != null
? null
: TabBar(
controller: _tabController,

View File

@ -61,7 +61,7 @@ class _AppSharingListenerState extends State<AppSharingListener> {
onTap: () {
GoRouter.of(context).pushNamed(
'postEditor',
pathParameters: {
queryParameters: {
'mode': 'stories',
},
extra: PostEditorExtra(

View File

@ -1038,8 +1038,10 @@ class _PostContentHeader extends StatelessWidget {
onTap: () {
GoRouter.of(context).pushNamed(
'postEditor',
pathParameters: {'mode': data.typePlural},
queryParameters: {'editing': data.id.toString()},
queryParameters: {
'editing': data.id.toString(),
'mode': data.typePlural,
},
);
},
),
@ -1066,8 +1068,10 @@ class _PostContentHeader extends StatelessWidget {
onTap: () {
GoRouter.of(context).pushNamed(
'postEditor',
pathParameters: {'mode': 'stories'},
queryParameters: {'replying': data.id.toString()},
queryParameters: {
'replying': data.id.toString(),
'mode': data.typePlural,
},
);
},
),
@ -1082,8 +1086,10 @@ class _PostContentHeader extends StatelessWidget {
onTap: () {
GoRouter.of(context).pushNamed(
'postEditor',
pathParameters: {'mode': 'stories'},
queryParameters: {'reposting': data.id.toString()},
queryParameters: {
'reposting': data.id.toString(),
'mode': 'stories',
},
);
},
),

View File

@ -25,7 +25,8 @@ class PostMiniEditor extends StatefulWidget {
}
class _PostMiniEditorState extends State<PostMiniEditor> {
final PostWriteController _writeController = PostWriteController(doLoadFromTemporary: false);
final PostWriteController _writeController =
PostWriteController(doLoadFromTemporary: false);
bool _isFetching = false;
@ -44,8 +45,9 @@ class _PostMiniEditorState extends State<PostMiniEditor> {
resp.data?.map((e) => SnPublisher.fromJson(e)) ?? [],
);
final beforeId = config.prefs.getInt('int_last_publisher_id');
_writeController
.setPublisher(_publishers?.where((ele) => ele.id == beforeId).firstOrNull ?? _publishers?.firstOrNull);
_writeController.setPublisher(
_publishers?.where((ele) => ele.id == beforeId).firstOrNull ??
_publishers?.firstOrNull);
} catch (err) {
if (!mounted) return;
context.showErrorDialog(err);
@ -99,11 +101,17 @@ class _PostMiniEditorState extends State<PostMiniEditor> {
Expanded(
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
crossAxisAlignment:
CrossAxisAlignment.start,
children: [
Text(item.nick).textStyle(Theme.of(context).textTheme.bodyMedium!),
Text(item.nick).textStyle(
Theme.of(context)
.textTheme
.bodyMedium!),
Text('@${item.name}')
.textStyle(Theme.of(context).textTheme.bodySmall!)
.textStyle(Theme.of(context)
.textTheme
.bodySmall!)
.fontSize(12),
],
),
@ -120,7 +128,8 @@ class _PostMiniEditorState extends State<PostMiniEditor> {
CircleAvatar(
radius: 16,
backgroundColor: Colors.transparent,
foregroundColor: Theme.of(context).colorScheme.onSurface,
foregroundColor:
Theme.of(context).colorScheme.onSurface,
child: const Icon(Symbols.add),
),
const Gap(8),
@ -129,7 +138,8 @@ class _PostMiniEditorState extends State<PostMiniEditor> {
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text('publishersNew').tr().textStyle(Theme.of(context).textTheme.bodyMedium!),
Text('publishersNew').tr().textStyle(
Theme.of(context).textTheme.bodyMedium!),
],
),
),
@ -140,7 +150,9 @@ class _PostMiniEditorState extends State<PostMiniEditor> {
value: _writeController.publisher,
onChanged: (SnPublisher? value) {
if (value == null) {
GoRouter.of(context).pushNamed('accountPublisherNew').then((value) {
GoRouter.of(context)
.pushNamed('accountPublisherNew')
.then((value) {
if (value == true) {
_publishers = null;
_fetchPublishers();
@ -176,7 +188,8 @@ class _PostMiniEditorState extends State<PostMiniEditor> {
),
border: InputBorder.none,
),
onTapOutside: (_) => FocusManager.instance.primaryFocus?.unfocus(),
onTapOutside: (_) =>
FocusManager.instance.primaryFocus?.unfocus(),
),
),
const Gap(8),
@ -185,7 +198,8 @@ class _PostMiniEditorState extends State<PostMiniEditor> {
TweenAnimationBuilder<double>(
tween: Tween(begin: 0, end: _writeController.progress),
duration: Duration(milliseconds: 300),
builder: (context, value, _) => LinearProgressIndicator(value: value, minHeight: 2),
builder: (context, value, _) =>
LinearProgressIndicator(value: value, minHeight: 2),
)
else if (_writeController.isBusy)
const LinearProgressIndicator(value: null, minHeight: 2),
@ -200,15 +214,17 @@ class _PostMiniEditorState extends State<PostMiniEditor> {
onPressed: () {
GoRouter.of(context).pushNamed(
'postEditor',
pathParameters: {'mode': 'stories'},
queryParameters: {
if (widget.postReplyId != null) 'replying': widget.postReplyId.toString(),
if (widget.postReplyId != null)
'replying': widget.postReplyId.toString(),
'mode': 'stories',
},
);
},
),
TextButton.icon(
onPressed: (_writeController.isBusy || _writeController.publisher == null)
onPressed: (_writeController.isBusy ||
_writeController.publisher == null)
? null
: () {
_writeController.sendPost(context).then((_) {