Skip to content

Commit

Permalink
[App] merge NewsPage with BlogPage; [BlogPage] undelete click FAB to …
Browse files Browse the repository at this point in the history
…go top
  • Loading branch information
tastelessjolt committed Dec 28, 2018
1 parent fa2fcd9 commit a6e990b
Show file tree
Hide file tree
Showing 15 changed files with 203 additions and 160 deletions.
2 changes: 2 additions & 0 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:InstiApp/src/routes/bodypage.dart';
import 'package:InstiApp/src/routes/eventpage.dart';
import 'package:InstiApp/src/routes/feedpage.dart';
import 'package:InstiApp/src/routes/newspage.dart';
import 'package:InstiApp/src/routes/quicklinkspage.dart';
import 'package:InstiApp/src/routes/trainingblogpage.dart';
import 'package:InstiApp/src/routes/userpage.dart';
Expand Down Expand Up @@ -68,6 +69,7 @@ class MyAppState extends State<MyApp> {
case "/trainblog": return _buildRoute(settings, TrainingBlogPage());
case "/feed": return _buildRoute(settings, FeedPage());
case "/quicklinks": return _buildRoute(settings, QuickLinksPage());
case "/news": return _buildRoute(settings, NewsPage());
}
}
return _buildRoute(settings, MessPage());
Expand Down
3 changes: 1 addition & 2 deletions lib/src/api/apiclient.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import 'package:InstiApp/src/api/model/body.dart';
import 'package:InstiApp/src/api/model/event.dart';
import 'package:InstiApp/src/api/model/news_article.dart';
import 'package:InstiApp/src/api/model/notification.dart';
import 'package:InstiApp/src/api/model/venter.dart';
import 'package:InstiApp/src/api/model/venue.dart';
Expand All @@ -15,7 +14,7 @@ import 'package:InstiApp/src/api/response/image_upload_response.dart';
import 'package:InstiApp/src/api/response/news_feed_response.dart';
import 'package:http/io_client.dart';
import 'package:InstiApp/src/api/model/mess.dart';
import 'package:InstiApp/src/api/model/blogpost.dart';
import 'package:InstiApp/src/api/model/post.dart';
import 'package:InstiApp/src/api/model/user.dart';
import 'package:jaguar_resty/jaguar_resty.dart';
import 'package:jaguar_resty/jaguar_resty.dart' as resty;
Expand Down
27 changes: 0 additions & 27 deletions lib/src/api/model/news_article.dart

This file was deleted.

38 changes: 0 additions & 38 deletions lib/src/api/model/news_article.jser.dart

This file was deleted.

18 changes: 14 additions & 4 deletions lib/src/api/model/blogpost.dart → lib/src/api/model/post.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import 'package:InstiApp/src/api/model/body.dart';
import 'package:jaguar_serializer/jaguar_serializer.dart';

part 'blogpost.jser.dart';
part 'post.jser.dart';

class BlogPost {
class Post {
@Alias("id")
String postID;

Expand All @@ -19,8 +20,17 @@ class BlogPost {
String published;
}

class PlacementBlogPost extends BlogPost{}
class TrainingBlogPost extends BlogPost{}
class PlacementBlogPost extends Post{}
class TrainingBlogPost extends Post{}


class NewsArticle extends Post {
@Alias("body")
Body body;
}

@GenSerializer()
class NewsArticleSerializer extends Serializer<NewsArticle> with _$NewsArticleSerializer {}

@GenSerializer()
class PlacementBlogPostSerializer extends Serializer<PlacementBlogPost> with _$PlacementBlogPostSerializer {}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions lib/src/api/model/serializers.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright (c) 2015, Google Inc. Please see the AUTHORS file for details.
library serializers;

import 'package:InstiApp/src/api/model/news_article.dart';
import 'package:InstiApp/src/api/model/notification.dart';
import 'package:InstiApp/src/api/model/role.dart';
import 'package:InstiApp/src/api/model/venter.dart';
Expand All @@ -13,7 +12,7 @@ import 'package:InstiApp/src/api/model/user.dart';
import 'package:InstiApp/src/api/model/body.dart';
import 'package:InstiApp/src/api/model/event.dart';
import 'package:InstiApp/src/api/model/mess.dart';
import 'package:InstiApp/src/api/model/blogpost.dart';
import 'package:InstiApp/src/api/model/post.dart';

JsonRepo standardSerializers = JsonRepo(serializers: [
// Mess menu
Expand Down
44 changes: 21 additions & 23 deletions lib/src/blocs/blog_bloc.dart
Original file line number Diff line number Diff line change
@@ -1,38 +1,33 @@
import 'dart:collection';

import 'package:flutter/foundation.dart';
import 'package:InstiApp/src/api/model/blogpost.dart';
import 'package:InstiApp/src/api/model/post.dart';
import 'package:InstiApp/src/blocs/ia_bloc.dart';
import 'package:rxdart/rxdart.dart';
import 'package:markdown/markdown.dart' as markdown;
import 'dart:math';

enum BlogType{
Placement,
Training
}
enum PostType { Placement, Training, NewsArticle }

class BlogBloc {
class PostBloc {
// Streams
Stream<UnmodifiableListView<BlogPost>> get blog =>
_blogSubject.stream;
final _blogSubject =
BehaviorSubject<UnmodifiableListView<BlogPost>>();
Stream<UnmodifiableListView<Post>> get blog => _blogSubject.stream;
final _blogSubject = BehaviorSubject<UnmodifiableListView<Post>>();

Sink<int> get inPostIndex => _indexController.sink;
PublishSubject<int> _indexController = PublishSubject<int>();

// Params
int _noOfPostsPerPage = 20;
String query = "";
String query = "";

// parent bloc
InstiAppBloc bloc;

// Training or Placement
final BlogType blogType;
// Training or Placement or News Article
final PostType postType;

BlogBloc(this.bloc, {@required this.blogType}) {
PostBloc(this.bloc, {@required this.postType}) {
_setIndexListener();
}

Expand All @@ -43,7 +38,7 @@ class BlogBloc {
.listen(_handleIndexes);
}

final _fetchPages = <int, List<BlogPost>>{};
final _fetchPages = <int, List<Post>>{};

final _pagesBeingFetched = Set<int>();

Expand All @@ -67,8 +62,12 @@ class BlogBloc {
return "${week[dt.weekday - 1]}, ${month[dt.month - 1]} ${dt.day.toString()}${dt.year == DateTime.now().year ? "" : dt.year.toString()}, ${dt.hour.toString().padLeft(2, '0')}:${dt.minute.toString().padLeft(2, '0')}:${dt.second.toString().padLeft(2, '0')}";
}

Future<List<BlogPost>> getBlogPage(int page) async {
var httpGetFunc = blogType == BlogType.Placement ? bloc.client.getPlacementBlogFeed : bloc.client.getTrainingBlogFeed;
Future<List<Post>> getBlogPage(int page) async {
var httpGetFunc = {
PostType.Placement: bloc.client.getPlacementBlogFeed,
PostType.Training: bloc.client.getTrainingBlogFeed,
PostType.NewsArticle: bloc.client.getNews
}[postType];
var posts = await httpGetFunc(bloc.getSessionIdHeader(),
page * _noOfPostsPerPage, _noOfPostsPerPage, query);
var tableParse = markdown.TableSyntax();
Expand All @@ -94,9 +93,8 @@ class BlogBloc {
// Remember that we are fetching it
_pagesBeingFetched.add(pageIndex);
// Fetch it
getBlogPage(pageIndex)
.then((List<BlogPost> fetchedPage) =>
_handleFetchedPage(fetchedPage, pageIndex));
getBlogPage(pageIndex).then((List<Post> fetchedPage) =>
_handleFetchedPage(fetchedPage, pageIndex));
}
}
});
Expand All @@ -107,7 +105,7 @@ class BlogBloc {
/// 1) record it
/// 2) notify everyone who might be interested in knowing it
///
void _handleFetchedPage(List<BlogPost> page, int pageIndex) {
void _handleFetchedPage(List<Post> page, int pageIndex) {
// Remember the page
_fetchPages[pageIndex] = page;
// Remove it from the ones being fetched
Expand All @@ -118,7 +116,7 @@ class BlogBloc {
// which respect the sequence (since MovieCard are in sequence)
// therefore, we need to iterate through the pages that are
// actually fetched and stop if there is a gap.
List<BlogPost> posts = <BlogPost>[];
List<Post> posts = <Post>[];
List<int> pageIndexes = _fetchPages.keys.toList();

final int minPageIndex = pageIndexes.reduce(min);
Expand All @@ -139,7 +137,7 @@ class BlogBloc {

// Only notify when there are posts
if (posts.length > 0) {
_blogSubject.add(UnmodifiableListView<BlogPost>(posts));
_blogSubject.add(UnmodifiableListView<Post>(posts));
}
}

Expand Down
18 changes: 12 additions & 6 deletions lib/src/blocs/ia_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ class InstiAppBloc {
final _eventsSubject = BehaviorSubject<UnmodifiableListView<Event>>();

// Sub Blocs
BlogBloc placementBloc;
BlogBloc trainingBloc;
PostBloc placementBloc;
PostBloc trainingBloc;
PostBloc newsBloc;
DrawerBloc drawerState;

// actual current state
Expand All @@ -41,13 +42,18 @@ class InstiAppBloc {

InstiAppBloc() {
globalClient = IOClient();
placementBloc = BlogBloc(this, blogType: BlogType.Placement);
trainingBloc = BlogBloc(this, blogType: BlogType.Training);
placementBloc = PostBloc(this, postType: PostType.Placement);
trainingBloc = PostBloc(this, postType: PostType.Training);
newsBloc = PostBloc(this, postType: PostType.NewsArticle);
drawerState = DrawerBloc(homepageName, highlightPageIndexVal: 3);
}

BlogBloc getBlogBloc(BlogType blogType) {
return blogType == BlogType.Placement ? placementBloc : trainingBloc;
PostBloc getPostsBloc(PostType blogType) {
return {
PostType.Placement: placementBloc,
PostType.Training: trainingBloc,
PostType.NewsArticle: newsBloc,
}[blogType];
}

String getSessionIdHeader() {
Expand Down
4 changes: 4 additions & 0 deletions lib/src/drawer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,12 @@ class _BottomDrawerState extends State<BottomDrawer> {
1: NavListTile(
icon: OMIcons.rssFeed,
title: "News",
selected: true,
onTap: () {
changeSelection(1, drawerState);
var navi = Navigator.of(context);
navi.pop();
navi.pushNamed('/news');
},
),
2: NavListTile(
Expand Down
Loading

0 comments on commit a6e990b

Please sign in to comment.