Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix tagline issue #1209

Merged
merged 1 commit into from
Mar 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions lib/feed/view/feed_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,8 @@ class _FeedViewState extends State<FeedView> {
/// List of post ids to queue for removal. The ids in this list allow us to remove posts in a staggered method
List<int> queuedForRemoval = [];

String? tagline;

@override
void initState() {
super.initState();
Expand Down Expand Up @@ -299,6 +301,11 @@ class _FeedViewState extends State<FeedView> {
List<PostViewMedia> postViewMedias = state.postViewMedias;
List<CommentView> commentViews = state.commentViews;

if (state.status == FeedStatus.initial) {
final GetSiteResponse? site = context.read<AuthBloc>().state.getSiteResponse;
tagline = site?.taglines[Random().nextInt(site.taglines.length)].content;
}

return RefreshIndicator(
onRefresh: () async {
HapticFeedback.mediumImpact();
Expand Down Expand Up @@ -330,7 +337,7 @@ class _FeedViewState extends State<FeedView> {
SliverToBoxAdapter(
child: Visibility(
visible: state.feedType == FeedType.general && state.status != FeedStatus.initial,
child: const TagLine(),
child: tagline?.isNotEmpty == true ? TagLine(tagline: tagline!) : Container(),
),
),
if (state.fullCommunityView != null)
Expand Down Expand Up @@ -593,20 +600,13 @@ class FeedHeader extends StatelessWidget {
}

class TagLine extends StatelessWidget {
const TagLine({super.key});
final String tagline;

const TagLine({super.key, required this.tagline});

@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
final taglineToShowCache = Cache<String>();

final fullSiteView = context.read<AuthBloc>().state.getSiteResponse;
if (fullSiteView == null || fullSiteView.taglines.isEmpty) return Container();

String tagline = taglineToShowCache.getOrSet(() {
String tagline = fullSiteView.taglines[Random().nextInt(fullSiteView.taglines.length)].content;
return tagline;
}, const Duration(seconds: 1));

final bool taglineIsLong = tagline.length > 200;

Expand Down
Loading