mirror of
				https://gitlab.com/comunic/comunicmobile
				synced 2025-11-04 04:04:18 +00:00 
			
		
		
		
	Handle comments notifications
This commit is contained in:
		
							
								
								
									
										62
									
								
								lib/ui/routes/single_post_route.dart
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										62
									
								
								lib/ui/routes/single_post_route.dart
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,62 @@
 | 
			
		||||
import 'package:comunic/helpers/posts_helper.dart';
 | 
			
		||||
import 'package:comunic/lists/posts_list.dart';
 | 
			
		||||
import 'package:comunic/ui/widgets/posts_list_widget.dart';
 | 
			
		||||
import 'package:comunic/utils/intl_utils.dart';
 | 
			
		||||
import 'package:flutter/cupertino.dart';
 | 
			
		||||
import 'package:flutter/material.dart';
 | 
			
		||||
 | 
			
		||||
/// Single post route
 | 
			
		||||
///
 | 
			
		||||
/// @author Pierre HUBERT
 | 
			
		||||
 | 
			
		||||
class SinglePostRoute extends StatelessWidget {
 | 
			
		||||
  final int postID;
 | 
			
		||||
 | 
			
		||||
  const SinglePostRoute({
 | 
			
		||||
    Key key,
 | 
			
		||||
    @required this.postID,
 | 
			
		||||
  })  : assert(postID != null),
 | 
			
		||||
        super(key: key);
 | 
			
		||||
 | 
			
		||||
  @override
 | 
			
		||||
  Widget build(BuildContext context) {
 | 
			
		||||
    return Scaffold(
 | 
			
		||||
      appBar: AppBar(
 | 
			
		||||
        title: Text(tr("Post")),
 | 
			
		||||
      ),
 | 
			
		||||
      body: _SinglePostRouteBody(postID: postID),
 | 
			
		||||
    );
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
class _SinglePostRouteBody extends StatefulWidget {
 | 
			
		||||
  final int postID;
 | 
			
		||||
 | 
			
		||||
  const _SinglePostRouteBody({
 | 
			
		||||
    Key key,
 | 
			
		||||
    @required this.postID,
 | 
			
		||||
  })  : assert(postID != null),
 | 
			
		||||
        super(key: key);
 | 
			
		||||
 | 
			
		||||
  @override
 | 
			
		||||
  __SinglePostRouteBodyState createState() => __SinglePostRouteBodyState();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
class __SinglePostRouteBodyState extends State<_SinglePostRouteBody> {
 | 
			
		||||
  Future<PostsList> _getPost() async {
 | 
			
		||||
    try {
 | 
			
		||||
      return PostsList()..add(await PostsHelper().getSingle(widget.postID));
 | 
			
		||||
    } on Exception catch (e) {
 | 
			
		||||
      print(e);
 | 
			
		||||
      return null;
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @override
 | 
			
		||||
  Widget build(BuildContext context) {
 | 
			
		||||
    return PostsListWidget(
 | 
			
		||||
      getPostsList: _getPost,
 | 
			
		||||
      showPostsTarget: true,
 | 
			
		||||
    );
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
@@ -8,6 +8,7 @@ import 'package:comunic/models/notification.dart' as n;
 | 
			
		||||
import 'package:comunic/ui/widgets/account_image_widget.dart';
 | 
			
		||||
import 'package:comunic/utils/date_utils.dart';
 | 
			
		||||
import 'package:comunic/utils/intl_utils.dart';
 | 
			
		||||
import 'package:comunic/utils/navigation_utils.dart';
 | 
			
		||||
import 'package:comunic/utils/ui_utils.dart';
 | 
			
		||||
import 'package:flutter/material.dart';
 | 
			
		||||
 | 
			
		||||
@@ -242,6 +243,7 @@ class _NotificationTile extends StatelessWidget {
 | 
			
		||||
      leading: AccountImageWidget(
 | 
			
		||||
        user: srcUser,
 | 
			
		||||
      ),
 | 
			
		||||
      onTap: () => _onTap(context),
 | 
			
		||||
      title: Text(message),
 | 
			
		||||
      subtitle: Text(diffTimeFromNowToStr(notification.timeCreate)),
 | 
			
		||||
      trailing: PopupMenuButton<_PopupMenuActions>(
 | 
			
		||||
@@ -263,4 +265,12 @@ class _NotificationTile extends StatelessWidget {
 | 
			
		||||
        break;
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  void _onTap(BuildContext context) {
 | 
			
		||||
    if (notification.onElemType == n.NotificationElementType.POST) {
 | 
			
		||||
      openPostFullScreen(notification.onElemId, context);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // TODO : mark the notification as seen
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -76,9 +76,7 @@ class _PostsListWidgetState extends State<PostsListWidget> {
 | 
			
		||||
 | 
			
		||||
  /// Load the list of posts
 | 
			
		||||
  Future<void> _loadPostsList({bool getOlder = false}) async {
 | 
			
		||||
 | 
			
		||||
    if(_loading)
 | 
			
		||||
      return;
 | 
			
		||||
    if (_loading) return;
 | 
			
		||||
 | 
			
		||||
    _loading = true;
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user