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: infinite paging for FF series #1727

Merged
merged 27 commits into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
4c3b499
fix: infinite paging for FF series
phuocbitmark Jun 4, 2024
7de04ac
Merge branch 'develop' into ff_series_pageview
phuocbitmark Jun 5, 2024
f718985
Merge branch 'develop' into ff_series_pageview
phuocbitmark Jun 5, 2024
93160e5
fix: load all artwork for exhibition detail page:
phuocbitmark Jun 5, 2024
282f3b2
Merge branch 'develop' into ff_series_pageview
phuocbitmark Jun 5, 2024
31b9db3
Merge branch 'develop' into ff_series_pageview
phuocbitmark Jun 5, 2024
0f59eb2
Merge branch 'develop' into ff_series_pageview
phuocbitmark Jun 5, 2024
26c5b85
unit test
phuocbitmark Jun 6, 2024
2df6be5
Merge branch 'develop' into ff_series_pageview
phuocbitmark Jun 6, 2024
9f18912
fix: paging
phuocbitmark Jun 6, 2024
e1f0e1f
lint
phuocbitmark Jun 7, 2024
e7350e1
Merge branch 'develop' into ff_series_pageview
phuocbitmark Jun 7, 2024
adde827
paging for source exhibition
phuocbitmark Jun 7, 2024
4e745e3
Merge branch 'develop' into ff_series_pageview
phuocbitmark Jun 9, 2024
a78469c
exhibition detail bloc: load 1 page of artwork, fix pagesize
phuocbitmark Jun 9, 2024
6ab37ca
fix: get series first artwork
phuocbitmark Jun 10, 2024
b03d825
fix: source exhibition artworks
phuocbitmark Jun 10, 2024
0fa23ba
fix: sublist
phuocbitmark Jun 10, 2024
7995f46
lint
phuocbitmark Jun 10, 2024
6d150a5
Merge branch 'develop' into ff_series_pageview
phuocbitmark Jun 10, 2024
35ae6f9
fix: total series artwork
phuocbitmark Jun 10, 2024
9728240
unit test
phuocbitmark Jun 10, 2024
4e581a4
Merge branch 'develop' into ff_series_pageview
phuocbitmark Jun 10, 2024
ec34d8b
Update assets
hoangbtmrk Jun 10, 2024
624e6a7
fix: view text past exhibition
phuocbitmark Jun 10, 2024
f25556c
Merge branch 'ff_series_pageview' of github.com:bitmark-inc/autonomy-…
phuocbitmark Jun 10, 2024
bcca5dd
fix: double loading
phuocbitmark Jun 10, 2024
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
6 changes: 4 additions & 2 deletions lib/gateway/feralfile_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import 'package:autonomy_flutter/model/ff_account.dart';
import 'package:autonomy_flutter/model/ff_exhibition.dart';
import 'package:autonomy_flutter/model/ff_exhibition_artworks_response.dart';
import 'package:autonomy_flutter/model/ff_list_response.dart';
import 'package:autonomy_flutter/model/ff_series.dart';
import 'package:dio/dio.dart';
import 'package:retrofit/retrofit.dart';
Expand Down Expand Up @@ -64,9 +64,11 @@ abstract class FeralFileApi {
Future<ExhibitionResponse> getFeaturedExhibition();

@GET('/api/artworks')
Future<ArtworksResponse> getListArtworks({
Future<FeralFileListResponse<Artwork>> getListArtworks({
@Query('exhibitionID') String? exhibitionId,
@Query('seriesID') String? seriesId,
@Query('offset') int? offset,
@Query('limit') int? limit,
@Query('includeActiveSwap') bool includeActiveSwap = true,
@Query('sortBy') String sortBy = 'index',
@Query('sortOrder') String sortOrder = 'ASC',
Expand Down
13 changes: 9 additions & 4 deletions lib/gateway/feralfile_api.g.dart

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

20 changes: 0 additions & 20 deletions lib/model/ff_exhibition_artworks_response.dart

This file was deleted.

59 changes: 59 additions & 0 deletions lib/model/ff_list_response.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
class FeralFileListResponse<T> {
final List<T> result;
final Paging paging;

FeralFileListResponse({required this.result, required this.paging});

factory FeralFileListResponse.fromJson(
Map<String, dynamic> json,
T Function(Map<String, dynamic>) fromJson,
) =>
FeralFileListResponse(
result: (json['result'] as List<dynamic>)
.map((e) => fromJson(e as Map<String, dynamic>))
.toList(),
paging: Paging.fromJson(json['paging']),
);

Map<String, dynamic> toJson(Map<String, dynamic> Function(T) toJson) => {
'result': result.map((e) => toJson(e)).toList(),
'paging': paging.toJson(),
};

FeralFileListResponse<T> copyWith({
List<T>? result,
Paging? paging,
}) =>
FeralFileListResponse<T>(
result: result ?? this.result,
paging: paging ?? this.paging,
);
}

class Paging {
final int offset;
final int limit;
final int total;

Paging({
required this.offset,
required this.limit,
required this.total,
});

factory Paging.fromJson(Map<String, dynamic> json) => Paging(
offset: json['offset'],
limit: json['limit'],
total: json['total'],
);

Map<String, dynamic> toJson() => {
'offset': offset,
'limit': limit,
'total': total,
};
}

extension PagingExtension on Paging {
bool get shouldLoadMore => offset + limit < total;
}
33 changes: 30 additions & 3 deletions lib/screen/exhibition_details/exhibition_detail_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,17 @@
import 'package:autonomy_flutter/au_bloc.dart';
import 'package:autonomy_flutter/model/ff_account.dart';
import 'package:autonomy_flutter/model/ff_exhibition.dart';
import 'package:autonomy_flutter/model/ff_list_response.dart';
import 'package:autonomy_flutter/screen/exhibition_details/exhibition_detail_state.dart';
import 'package:autonomy_flutter/service/feralfile_service.dart';
import 'package:autonomy_flutter/util/log.dart';

class ExhibitionDetailBloc
extends AuBloc<ExhibitionDetailEvent, ExhibitionDetailState> {
final FeralFileService _feralFileService;

static const int _limit = 300;

ExhibitionDetailBloc(this._feralFileService)
: super(ExhibitionDetailState()) {
on<GetExhibitionDetailEvent>((event, emit) async {
Expand All @@ -18,10 +22,33 @@ class ExhibitionDetailBloc
_feralFileService.getExhibitionArtworks(event.exhibitionId,
withSeries: true)
]);
final exhibitionDetail = ExhibitionDetail(
exhibition: result[0] as Exhibition,
artworks: result[1] as List<Artwork>);
final exhibition = result[0] as Exhibition;
final artworks = result[1] as FeralFileListResponse<Artwork>;
final exhibitionDetail =
ExhibitionDetail(exhibition: exhibition, artworks: artworks.result);
emit(state.copyWith(exhibitionDetail: exhibitionDetail));

if (artworks.paging.shouldLoadMore) {
add(LoadMoreArtworkEvent(artworks.paging.limit, _limit));
hoangbtmrk marked this conversation as resolved.
Show resolved Hide resolved
}
});

on<LoadMoreArtworkEvent>((event, emit) async {
log.info(
'LoadMoreArtworkEvent: offset=${event.offset}, limit=${event.limit}');
final result = await _feralFileService.getExhibitionArtworks(
state.exhibitionDetail!.exhibition.id,
withSeries: true,
offset: event.offset,
limit: event.limit);
final exhibitionDetail = state.exhibitionDetail!.copyWith(
artworks: state.exhibitionDetail!.artworks! + result.result,
);
emit(state.copyWith(exhibitionDetail: exhibitionDetail));

if (result.paging.shouldLoadMore) {
add(LoadMoreArtworkEvent(event.offset + event.limit, event.limit));
phuocbitmark marked this conversation as resolved.
Show resolved Hide resolved
}
});
}
}
7 changes: 7 additions & 0 deletions lib/screen/exhibition_details/exhibition_detail_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ class GetExhibitionDetailEvent extends ExhibitionDetailEvent {
final String exhibitionId;
}

class LoadMoreArtworkEvent extends ExhibitionDetailEvent {
final int offset;
final int limit;

LoadMoreArtworkEvent(this.offset, this.limit);
}

class ExhibitionDetailState {
ExhibitionDetailState({this.exhibitionDetail});

Expand Down
24 changes: 2 additions & 22 deletions lib/screen/feralfile_series/feralfile_series_bloc.dart
Original file line number Diff line number Diff line change
@@ -1,39 +1,19 @@
import 'package:autonomy_flutter/au_bloc.dart';
import 'package:autonomy_flutter/model/ff_account.dart';
import 'package:autonomy_flutter/model/ff_exhibition.dart';
phuocbitmark marked this conversation as resolved.
Show resolved Hide resolved
import 'package:autonomy_flutter/model/ff_series.dart';
import 'package:autonomy_flutter/screen/feralfile_series/feralfile_series_state.dart';
import 'package:autonomy_flutter/service/feralfile_service.dart';
import 'package:autonomy_flutter/util/exhibition_ext.dart';

class FeralFileSeriesBloc
extends AuBloc<FeralFileSeriesEvent, FeralFileSeriesState> {
final FeralFileService _feralFileService;

FeralFileSeriesBloc(this._feralFileService) : super(FeralFileSeriesState()) {
on<FeralFileSeriesGetSeriesEvent>((event, emit) async {
final result = await Future.wait([
_feralFileService.getExhibition(event.exhibitionId),
_feralFileService.getSeriesArtworks(event.seriesId,
exhibitionID: event.exhibitionId, withSeries: true),
_feralFileService.getSeries(event.seriesId,
exhibitionID: event.exhibitionId),
]);
final exhibition = result[0] as Exhibition;
final artworks = result[1] as List<Artwork>;
final series = result[2] as FFSeries;
final exhibitionDetail = ExhibitionDetail(
exhibition: exhibition,
artworks: artworks,
);
final tokenIds = artworks
.map((e) => exhibitionDetail.getArtworkTokenId(e) ?? '')
.toList();
final series = await _feralFileService.getSeries(event.seriesId,
exhibitionID: event.exhibitionId);
emit(state.copyWith(
exhibitionDetail: exhibitionDetail,
series: series,
artworks: artworks,
tokenIds: tokenIds,
));
});
}
Expand Down
Loading
Loading