Skip to content

Commit

Permalink
feat(thread): Show thread draft state on top of thread page
Browse files Browse the repository at this point in the history
  • Loading branch information
realth000 committed Sep 7, 2024
1 parent b0ffe62 commit ec03280
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 17 deletions.
9 changes: 9 additions & 0 deletions lib/features/thread/bloc/thread_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,14 @@ class ThreadBloc extends Bloc<ThreadEvent, ThreadState> with LoggerMixin {
subject: subject,
);
}

final isDraft = threadDataNode
?.querySelector('div#postlist h1.ts > span')
?.nodes
.firstOrNull
?.text
?.contains('草稿');

final threadState = ThreadState(
tid: threadID,
pid: state.pid,
Expand All @@ -357,6 +365,7 @@ class ThreadBloc extends Bloc<ThreadEvent, ThreadState> with LoggerMixin {
onlyVisibleUid:
(clearOnlyVisibleUid ?? false) ? null : state.onlyVisibleUid,
reverseOrder: state.reverseOrder,
isDraft: isDraft ?? false,
);

return threadState;
Expand Down
4 changes: 4 additions & 0 deletions lib/features/thread/bloc/thread_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class ThreadState with ThreadStateMappable {
this.threadType,
this.onlyVisibleUid,
this.reverseOrder,
this.isDraft = false,
});

/// Status.
Expand Down Expand Up @@ -101,4 +102,7 @@ class ThreadState with ThreadStateMappable {
/// * Force set to asc order if `false`.
/// * Not force order if `null`.
final bool? reverseOrder;

/// Indicating current thread is a draft or not.
final bool isDraft;
}
1 change: 1 addition & 0 deletions lib/features/thread/view/thread_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ class _ThreadPageState extends State<ThreadPage>
useDivider: true,
postList: state.postList,
canLoadMore: state.canLoadMore,
isDraft: state.isDraft,
),
),
_buildReplyBar(context, state),
Expand Down
36 changes: 22 additions & 14 deletions lib/features/thread/widgets/post_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:super_sliver_list/super_sliver_list.dart';
import 'package:tsdm_client/constants/layout.dart';
import 'package:tsdm_client/extensions/list.dart';
import 'package:tsdm_client/features/jump_page/cubit/jump_page_cubit.dart';
import 'package:tsdm_client/features/thread/bloc/thread_bloc.dart';
import 'package:tsdm_client/i18n/strings.g.dart';
Expand All @@ -22,6 +23,7 @@ class PostList extends StatefulWidget {
required this.widgetBuilder,
required this.canLoadMore,
required this.scrollController,
required this.isDraft,
this.title,
this.pageNumber = 1,
this.useDivider = false,
Expand Down Expand Up @@ -64,6 +66,9 @@ class PostList extends StatefulWidget {
/// Useful in some "find post" situation.
final int? initialPostID;

/// Is thread in draft state.
final bool isDraft;

@override
State<PostList> createState() => _PostListState();
}
Expand Down Expand Up @@ -155,28 +160,31 @@ class _PostListState extends State<PostList> with LoggerMixin {
double shrinkOffset,
double expandHeight,
) {
final infoTextStyle = Theme.of(context)
.textTheme
.labelLarge
?.copyWith(color: Theme.of(context).colorScheme.outline);
if (_listScrollController.offset <= expandHeight) {
return Padding(
padding: edgeInsetsL12R12B12,
child: Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
children: <Widget>[
if (widget.isDraft)
Text(
'[${context.t.threadPage.draft}]',
style: infoTextStyle,
),
Text(
'[${context.t.threadPage.title} ${widget.threadID ?? ""}]',
style: Theme.of(context)
.textTheme
.labelLarge
?.copyWith(color: Theme.of(context).colorScheme.outline),
),
sizedBoxW4H4,
Text(
'[${_threadType ?? ""}]',
style: Theme.of(context)
.textTheme
.labelLarge
?.copyWith(color: Theme.of(context).colorScheme.outline),
style: infoTextStyle,
),
],
if (_threadType != null && _threadType!.isNotEmpty)
Text(
'[${_threadType!}]',
style: infoTextStyle,
),
].insertBetween(sizedBoxW4H4),
),
);
}
Expand Down
3 changes: 2 additions & 1 deletion lib/i18n/strings.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,8 @@
"closed": "Thread is closed",
"needLogin": "Need login",
"replySuccess": "Reply success",
"replyFailed": "Failed to reply: $err"
"replyFailed": "Failed to reply: $err",
"draft": "Draft"
},
"noticePage": {
"title": "Notifications",
Expand Down
3 changes: 2 additions & 1 deletion lib/i18n/strings_zh-CN.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,8 @@
"closed": "帖子已关闭",
"needLogin": "需要登录",
"replySuccess": "回复成功",
"replyFailed": "回复失败:$err"
"replyFailed": "回复失败:$err",
"draft": "草稿"
},
"noticePage": {
"title": "通知",
Expand Down
3 changes: 2 additions & 1 deletion lib/i18n/strings_zh-TW.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,8 @@
"closed": "貼文已關閉",
"needLogin": "需要登入",
"replySuccess": "回覆成功",
"replyFailed": "回覆失敗:$err"
"replyFailed": "回覆失敗:$err",
"draft": "草稿"
},
"noticePage": {
"title": "通知",
Expand Down

0 comments on commit ec03280

Please sign in to comment.