diff --git a/lib/redux/app/app_actions.dart b/lib/redux/actor/actor_actions.dart similarity index 80% rename from lib/redux/app/app_actions.dart rename to lib/redux/actor/actor_actions.dart index 7d677d1b..b48f9f01 100644 --- a/lib/redux/app/app_actions.dart +++ b/lib/redux/actor/actor_actions.dart @@ -1,11 +1,6 @@ import 'package:inkino/data/models/actor.dart'; import 'package:inkino/data/models/event.dart'; -class SearchQueryChangedAction { - SearchQueryChangedAction(this.query); - final String query; -} - class FetchActorAvatarsAction { FetchActorAvatarsAction(this.event); final Event event; @@ -19,4 +14,4 @@ class ActorsUpdatedAction { class ReceivedActorAvatarsAction { ReceivedActorAvatarsAction(this.actors); final List actors; -} \ No newline at end of file +} diff --git a/lib/redux/app/app_middleware.dart b/lib/redux/actor/actor_middleware.dart similarity index 72% rename from lib/redux/app/app_middleware.dart rename to lib/redux/actor/actor_middleware.dart index b4f2e0ff..49f0d1e0 100644 --- a/lib/redux/app/app_middleware.dart +++ b/lib/redux/actor/actor_middleware.dart @@ -1,13 +1,13 @@ import 'dart:async'; import 'package:inkino/data/networking/tmdb_api.dart'; -import 'package:inkino/redux/app/app_actions.dart'; +import 'package:inkino/redux/actor/actor_actions.dart'; import 'package:inkino/redux/app/app_state.dart'; import 'package:inkino/redux/common_actions.dart'; import 'package:redux/redux.dart'; -class AppMiddleware extends MiddlewareClass { - AppMiddleware(this.tmdbApi); +class ActorMiddleware extends MiddlewareClass { + ActorMiddleware(this.tmdbApi); final TMDBApi tmdbApi; @override @@ -29,8 +29,10 @@ class AppMiddleware extends MiddlewareClass { next(new UpdateActorsForEventAction(action.event, actorsWithAvatars)); next(new ReceivedActorAvatarsAction(actorsWithAvatars)); } catch (e) { - // YOLO! We don't need to handle this. If fetching actor avatars - // fails, we don't care. + // We don't need to handle this. If fetching actor avatars + // fails, we don't care: the UI just simply won't display + // any actor avatars and falls back to placeholder icons + // instead. } } } diff --git a/lib/redux/actor/actor_reducer.dart b/lib/redux/actor/actor_reducer.dart new file mode 100644 index 00000000..93035d23 --- /dev/null +++ b/lib/redux/actor/actor_reducer.dart @@ -0,0 +1,29 @@ +import 'package:inkino/data/models/actor.dart'; +import 'package:inkino/redux/actor/actor_actions.dart'; +import 'package:redux/redux.dart'; + +final actorReducer = combineTypedReducers>([ + new ReducerBinding, ActorsUpdatedAction>(_actorsUpdated), + new ReducerBinding, ReceivedActorAvatarsAction>(_receivedAvatars), +]); + +Map _actorsUpdated(Map actorsByName, action) { + var actors = {}..addAll(actorsByName); + action.actors.forEach((actor) { + actors.putIfAbsent(actor.name, () => new Actor(name: actor.name)); + }); + + return actors; +} + +Map _receivedAvatars(Map actorsByName, action) { + var actorsWithAvatars = {}..addAll(actorsByName); + action.actors.forEach((actor) { + actorsWithAvatars[actor.name] = new Actor( + name: actor.name, + avatarUrl: actor.avatarUrl, + ); + }); + + return actorsWithAvatars; +} diff --git a/lib/redux/app/app_selectors.dart b/lib/redux/actor/actor_selectors.dart similarity index 100% rename from lib/redux/app/app_selectors.dart rename to lib/redux/actor/actor_selectors.dart diff --git a/lib/redux/app/app_reducer.dart b/lib/redux/app/app_reducer.dart index 4841a57f..34b763e7 100644 --- a/lib/redux/app/app_reducer.dart +++ b/lib/redux/app/app_reducer.dart @@ -1,51 +1,16 @@ -import 'package:inkino/data/models/actor.dart'; -import 'package:inkino/redux/app/app_actions.dart'; +import 'package:inkino/redux/actor/actor_reducer.dart'; import 'package:inkino/redux/app/app_state.dart'; import 'package:inkino/redux/event/event_reducer.dart'; +import 'package:inkino/redux/search/search_reducer.dart'; import 'package:inkino/redux/show/show_reducer.dart'; import 'package:inkino/redux/theater/theater_reducer.dart'; -import 'package:redux/redux.dart'; AppState appReducer(AppState state, dynamic action) { return new AppState( - searchQuery: _searchQueryReducer(state.searchQuery, action), + searchQuery: searchQueryReducer(state.searchQuery, action), actorsByName: actorReducer(state.actorsByName, action), theaterState: theaterReducer(state.theaterState, action), showState: showReducer(state.showState, action), eventState: eventReducer(state.eventState, action), ); } - -String _searchQueryReducer(String searchQuery, action) { - if (action is SearchQueryChangedAction) { - return action.query; - } - - return searchQuery; -} - -final actorReducer = combineTypedReducers>([ - new ReducerBinding, ActorsUpdatedAction>(_actorsUpdated), - new ReducerBinding, ReceivedActorAvatarsAction>(_receivedAvatars), -]); - -Map _actorsUpdated(Map actorsByName, action) { - var actors = {}..addAll(actorsByName); - action.actors.forEach((actor) { - actors.putIfAbsent(actor.name, () => new Actor(name: actor.name)); - }); - - return actors; -} - -Map _receivedAvatars(Map actorsByName, action) { - var actorsWithAvatars = {}..addAll(actorsByName); - action.actors.forEach((actor) { - actorsWithAvatars[actor.name] = new Actor( - name: actor.name, - avatarUrl: actor.avatarUrl, - ); - }); - - return actorsWithAvatars; -} diff --git a/lib/redux/search/search_actions.dart b/lib/redux/search/search_actions.dart new file mode 100644 index 00000000..a49aa47f --- /dev/null +++ b/lib/redux/search/search_actions.dart @@ -0,0 +1,4 @@ +class SearchQueryChangedAction { + SearchQueryChangedAction(this.query); + final String query; +} diff --git a/lib/redux/search/search_reducer.dart b/lib/redux/search/search_reducer.dart new file mode 100644 index 00000000..831bdff6 --- /dev/null +++ b/lib/redux/search/search_reducer.dart @@ -0,0 +1,9 @@ +import 'package:inkino/redux/search/search_actions.dart'; + +String searchQueryReducer(String searchQuery, action) { + if (action is SearchQueryChangedAction) { + return action.query; + } + + return searchQuery; +} diff --git a/lib/redux/store.dart b/lib/redux/store.dart index a58967e6..fcadd960 100644 --- a/lib/redux/store.dart +++ b/lib/redux/store.dart @@ -3,7 +3,7 @@ import 'dart:async'; import 'package:flutter/services.dart'; import 'package:inkino/data/networking/finnkino_api.dart'; import 'package:inkino/data/networking/tmdb_api.dart'; -import 'package:inkino/redux/app/app_middleware.dart'; +import 'package:inkino/redux/actor/actor_middleware.dart'; import 'package:inkino/redux/app/app_reducer.dart'; import 'package:inkino/redux/app/app_state.dart'; import 'package:inkino/redux/event/event_middleware.dart'; @@ -22,7 +22,7 @@ Future> createStore() async { initialState: new AppState.initial(), distinct: true, middleware: [ - new AppMiddleware(tmdbApi), + new ActorMiddleware(tmdbApi), new TheaterMiddleware(rootBundle, prefs), new ShowMiddleware(finnkinoApi), new EventMiddleware(finnkinoApi), diff --git a/lib/ui/event_details/actor_scroller.dart b/lib/ui/event_details/actor_scroller.dart index 8b28d4ef..ffb56707 100644 --- a/lib/ui/event_details/actor_scroller.dart +++ b/lib/ui/event_details/actor_scroller.dart @@ -3,8 +3,8 @@ import 'package:flutter_redux/flutter_redux.dart'; import 'package:inkino/assets.dart'; import 'package:inkino/data/models/actor.dart'; import 'package:inkino/data/models/event.dart'; -import 'package:inkino/redux/app/app_actions.dart'; -import 'package:inkino/redux/app/app_selectors.dart'; +import 'package:inkino/redux/actor/actor_actions.dart'; +import 'package:inkino/redux/actor/actor_selectors.dart'; import 'package:inkino/redux/app/app_state.dart'; class ActorScroller extends StatelessWidget { diff --git a/lib/ui/main_page.dart b/lib/ui/main_page.dart index b0103eff..96bf99ca 100644 --- a/lib/ui/main_page.dart +++ b/lib/ui/main_page.dart @@ -4,8 +4,8 @@ import 'package:flutter/material.dart'; import 'package:flutter_redux/flutter_redux.dart'; import 'package:inkino/data/models/event.dart'; import 'package:inkino/data/models/theater.dart'; -import 'package:inkino/redux/app/app_actions.dart'; import 'package:inkino/redux/app/app_state.dart'; +import 'package:inkino/redux/search/search_actions.dart'; import 'package:inkino/ui/events/events_page.dart'; import 'package:inkino/ui/showtimes/showtimes_page.dart'; import 'package:inkino/ui/theater_list/inkino_drawer_header.dart'; diff --git a/test/redux/app/app_middleware_test.dart b/test/redux/actor/actor_middleware_test.dart similarity index 91% rename from test/redux/app/app_middleware_test.dart rename to test/redux/actor/actor_middleware_test.dart index 08c74279..37fc21f7 100644 --- a/test/redux/app/app_middleware_test.dart +++ b/test/redux/actor/actor_middleware_test.dart @@ -1,8 +1,8 @@ import 'package:inkino/data/models/actor.dart'; import 'package:inkino/data/models/event.dart'; import 'package:inkino/data/networking/tmdb_api.dart'; -import 'package:inkino/redux/app/app_actions.dart'; -import 'package:inkino/redux/app/app_middleware.dart'; +import 'package:inkino/redux/actor/actor_actions.dart'; +import 'package:inkino/redux/actor/actor_middleware.dart'; import 'package:inkino/redux/common_actions.dart'; import 'package:mockito/mockito.dart'; import 'package:test/test.dart'; @@ -34,11 +34,11 @@ void main() { final Function(dynamic) next = (action) => actionLog.add(action); MockTMDBApi mockTMDBApi; - AppMiddleware sut; + ActorMiddleware sut; setUp(() { mockTMDBApi = new MockTMDBApi(); - sut = new AppMiddleware(mockTMDBApi); + sut = new ActorMiddleware(mockTMDBApi); }); tearDown(() { diff --git a/test/redux/app/app_reducer_test.dart b/test/redux/actor/actor_reducer_test.dart similarity index 97% rename from test/redux/app/app_reducer_test.dart rename to test/redux/actor/actor_reducer_test.dart index 681c35cd..c46aae2e 100644 --- a/test/redux/app/app_reducer_test.dart +++ b/test/redux/actor/actor_reducer_test.dart @@ -1,5 +1,5 @@ import 'package:inkino/data/models/actor.dart'; -import 'package:inkino/redux/app/app_actions.dart'; +import 'package:inkino/redux/actor/actor_actions.dart'; import 'package:inkino/redux/app/app_reducer.dart'; import 'package:inkino/redux/app/app_state.dart'; import 'package:test/test.dart';