Skip to content
Merged
Show file tree
Hide file tree
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
5 changes: 2 additions & 3 deletions lib/api/state/actions/advancement_actions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,9 @@ class RefreshAdvancementAction extends RefreshListAction<AdvancementModel> {
RefreshAdvancementAction() : super(_modelList);
}

/// Loads the first page of the advancements, or the next one when some are
/// loaded.
/// Loads the first page of the advancements when none is loaded.
class InitAdvancementAction extends InitListAction<AdvancementModel> {
InitAdvancementAction() : super(_modelList, LoadMoreAdvancementsAction.new);
InitAdvancementAction() : super(_modelList);
}

/// Appends the next page of the advancements. While it loads,
Expand Down
5 changes: 2 additions & 3 deletions lib/api/state/actions/attribute_actions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,9 @@ class RefreshAttributeAction extends RefreshListAction<AttributeModel> {
RefreshAttributeAction() : super(_modelList);
}

/// Loads the first page of the attributes, or the next one when some are
/// loaded.
/// Loads the first page of the attributes when none is loaded.
class InitAttributeAction extends InitListAction<AttributeModel> {
InitAttributeAction() : super(_modelList, LoadMoreAttributesAction.new);
InitAttributeAction() : super(_modelList);
}

/// Appends the next page of the attributes. While it loads,
Expand Down
5 changes: 2 additions & 3 deletions lib/api/state/actions/block_state_actions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,9 @@ class RefreshBlockStateAction extends RefreshListAction<BlockStateModel> {
RefreshBlockStateAction() : super(_modelList);
}

/// Loads the first page of the blockstates, or the next one when some are
/// loaded.
/// Loads the first page of the blockstates when none is loaded.
class InitBlockStateAction extends InitListAction<BlockStateModel> {
InitBlockStateAction() : super(_modelList, LoadMoreBlockStatesAction.new);
InitBlockStateAction() : super(_modelList);
}

/// Appends the next page of the blockstates. While it loads,
Expand Down
5 changes: 2 additions & 3 deletions lib/api/state/actions/expression/expression_actions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,9 @@ class RefreshExpressionAction extends RefreshListAction<ExpressionModel> {
RefreshExpressionAction() : super(_modelList);
}

/// Loads the first page of the expressions, or the next one when some are
/// loaded.
/// Loads the first page of the expressions when none is loaded.
class InitExpressionAction extends InitListAction<ExpressionModel> {
InitExpressionAction() : super(_modelList, LoadMoreExpressionsAction.new);
InitExpressionAction() : super(_modelList);
}

/// Appends the next page of the expressions. While it loads,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ class RefreshExpressionFunctionAction
RefreshExpressionFunctionAction() : super(_modelList);
}

/// Loads the first page of the functions, or the next one when some are loaded.
/// Loads the first page of the functions when none is loaded.
class InitExpressionFunctionAction
extends InitListAction<ExpressionFunctionModel> {
InitExpressionFunctionAction()
: super(_modelList, LoadMoreExpressionFunctionsAction.new);
: super(_modelList);
}

/// Appends the next page of the functions. While it loads,
Expand Down
4 changes: 2 additions & 2 deletions lib/api/state/actions/font/font_actions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ class RefreshFontAction extends RefreshListAction<FontModel> {
RefreshFontAction() : super(_modelList);
}

/// Loads the first page of the fonts, or the next one when some are loaded.
/// Loads the first page of the fonts when none is loaded.
class InitFontAction extends InitListAction<FontModel> {
InitFontAction() : super(_modelList, LoadMoreFontsAction.new);
InitFontAction() : super(_modelList);
}

/// Appends the next page of the fonts. While it loads,
Expand Down
4 changes: 2 additions & 2 deletions lib/api/state/actions/item_actions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ class RefreshItemAction extends RefreshListAction<ItemModel> {
RefreshItemAction() : super(_modelList);
}

/// Loads the first page of the items, or the next one when some are loaded.
/// Loads the first page of the items when none is loaded.
class InitItemAction extends InitListAction<ItemModel> {
InitItemAction() : super(_modelList, LoadMoreItemsAction.new);
InitItemAction() : super(_modelList);
}

/// Appends the next page of the items. While it loads,
Expand Down
32 changes: 19 additions & 13 deletions lib/api/state/actions/paginated_loading.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,33 @@ class ModelList<T extends DataModel> {
size: of(state).requestSize,
projectId: state.selectedProject?.id,
);

/// Requests the first page of the open project and puts it in place of the
/// list, unless [currentState] shows another project opened while it
/// loaded: the page then belongs to the project that was left.
Future<AppState?> replaceWithFirstPage(
AppState Function() currentState,
) async {
final String? projectId = currentState().selectedProject?.id;
final PaginatedResult<T> page = await firstPage(currentState());
if (currentState().selectedProject?.id != projectId) return null;
return withList(currentState(), page);
}
}

/// Loads the first page of [list] when none is loaded, and the next page
/// otherwise. The overview dispatches it when it opens.
/// Loads the first page of [list] when none is loaded. The overview
/// dispatches it when it opens; further pages are loaded by scrolling, so a
/// list that already has a page is left alone.
abstract class InitListAction<T extends DataModel>
extends ReduxAction<AppState> {
InitListAction(this.list, this.loadMore);
InitListAction(this.list);

final ModelList<T> list;

/// Builds the load-more action of the same list.
final ReduxAction<AppState> Function() loadMore;

@override
Future<AppState?> reduce() async {
if (list.of(state).items.isEmpty) {
return list.withList(state, await list.firstPage(state));
}
await dispatchAndWait(loadMore());
return null;
if (list.of(state).items.isNotEmpty) return null;
return list.replaceWithFirstPage(() => state);
}
}

Expand Down Expand Up @@ -87,8 +94,7 @@ abstract class RefreshListAction<T extends DataModel>
final ModelList<T> list;

@override
Future<AppState?> reduce() async =>
list.withList(state, await list.firstPage(state));
Future<AppState?> reduce() => list.replaceWithFirstPage(() => state);
}

/// What the list actions share when loading a [PaginatedResult] page by page.
Expand Down
5 changes: 2 additions & 3 deletions lib/api/state/actions/sound/sound_actions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,9 @@ class RefreshSoundAction extends RefreshListAction<SoundEventModel> {
RefreshSoundAction() : super(_modelList);
}

/// Loads the first page of the sound events, or the next one when some are
/// loaded.
/// Loads the first page of the sound events when none is loaded.
class InitSoundAction extends InitListAction<SoundEventModel> {
InitSoundAction() : super(_modelList, LoadMoreSoundEventsAction.new);
InitSoundAction() : super(_modelList);
}

/// Appends the next page of the sound events. While it loads,
Expand Down
1 change: 1 addition & 0 deletions test/api/state/actions/advancement_actions_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ void main() {
selectedOf: (state) => state.selectedAdvancement,
withSelected: (state, model) => state.copyWith(selectedAdvancement: model),
init: InitAdvancementAction.new,
loadMore: LoadMoreAdvancementsAction.new,
refresh: RefreshAdvancementAction.new,
add: AdvancementAddAction.new,
remove: AdvancementRemoveAction.new,
Expand Down
1 change: 1 addition & 0 deletions test/api/state/actions/attribute_actions_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ void main() {
selectedOf: (state) => state.selectedAttribute,
withSelected: (state, model) => state.copyWith(selectedAttribute: model),
init: InitAttributeAction.new,
loadMore: LoadMoreAttributesAction.new,
refresh: RefreshAttributeAction.new,
add: AttributeAddAction.new,
remove: AttributeRemoveAction.new,
Expand Down
1 change: 1 addition & 0 deletions test/api/state/actions/block_state_actions_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ void main() {
selectedOf: (state) => state.selectedBlockState,
withSelected: (state, model) => state.copyWith(selectedBlockState: model),
init: InitBlockStateAction.new,
loadMore: LoadMoreBlockStatesAction.new,
refresh: RefreshBlockStateAction.new,
add: BlockStateAddAction.new,
remove: BlockStateRemoveAction.new,
Expand Down
4 changes: 2 additions & 2 deletions test/api/state/actions/expression_actions_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ void main() {
);

test(
'InitExpressionAction loads the next page after the loaded ones',
'LoadMoreExpressionsAction loads the next page after the loaded ones',
() async {
final store = Store<AppState>(
initialState: AppState(
Expand All @@ -87,7 +87,7 @@ void main() {
),
);

await store.dispatchAndWait(InitExpressionAction());
await store.dispatchAndWait(LoadMoreExpressionsAction());

expect(store.state.expressions.items.map((e) => e.id), ['e1', 'e2']);
expect(store.isWaiting(LoadMoreExpressionsAction), isFalse);
Expand Down
1 change: 1 addition & 0 deletions test/api/state/actions/font_actions_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ void main() {
selectedOf: (state) => state.selectedFont,
withSelected: (state, model) => state.copyWith(selectedFont: model),
init: InitFontAction.new,
loadMore: LoadMoreFontsAction.new,
refresh: RefreshFontAction.new,
add: FontAddAction.new,
remove: FontRemoveAction.new,
Expand Down
1 change: 1 addition & 0 deletions test/api/state/actions/item_actions_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ void main() {
selectedOf: (state) => state.selectedItem,
withSelected: (state, model) => state.copyWith(selectedItem: model),
init: InitItemAction.new,
loadMore: LoadMoreItemsAction.new,
refresh: RefreshItemAction.new,
add: ItemAddAction.new,
remove: ItemRemoveAction.new,
Expand Down
1 change: 1 addition & 0 deletions test/api/state/actions/sound_actions_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ void main() {
selectedOf: (state) => state.selectedSoundEvent,
withSelected: (state, model) => state.copyWith(selectedSoundEvent: model),
init: InitSoundAction.new,
loadMore: LoadMoreSoundEventsAction.new,
refresh: RefreshSoundAction.new,
add: SoundAddAction.new,
remove: SoundRemoveAction.new,
Expand Down
Loading
Loading