Skip to content

Commit

Permalink
Cancel previous request on search
Browse files Browse the repository at this point in the history
  • Loading branch information
Ziedelth committed May 6, 2024
1 parent 3f1ad81 commit b63fb5e
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 4 deletions.
1 change: 1 addition & 0 deletions lib/components/episodes/anime_episode_component.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class AnimeEpisodeComponent extends StatelessWidget {
topLeft: Radius.circular(16),
bottomLeft: Radius.circular(16),
),
fit: BoxFit.cover,
height: 130,
),
),
Expand Down
3 changes: 3 additions & 0 deletions lib/components/episodes/episode_image.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ import 'package:flutter/material.dart';
class EpisodeImage extends StatelessWidget {
final EpisodeMappingDto episode;
final BorderRadius borderRadius;
final BoxFit fit;
final double width;
final double height;

const EpisodeImage({
super.key,
required this.episode,
required this.borderRadius,
this.fit = BoxFit.fill,
this.width = double.infinity,
this.height = double.infinity,
});
Expand All @@ -23,6 +25,7 @@ class EpisodeImage extends StatelessWidget {
children: [
ImageComponent(
uuid: episode.uuid,
fit: fit,
borderRadius: borderRadius,
width: width,
height: height,
Expand Down
4 changes: 3 additions & 1 deletion lib/components/image_component.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:flutter/material.dart';

class ImageComponent extends StatelessWidget {
final String uuid;
final BoxFit fit;
final String type;
final BorderRadius borderRadius;
final double width;
Expand All @@ -12,6 +13,7 @@ class ImageComponent extends StatelessWidget {
const ImageComponent({
super.key,
required this.uuid,
this.fit = BoxFit.fill,
this.type = 'image',
this.borderRadius = BorderRadius.zero,
this.width = double.infinity,
Expand All @@ -25,7 +27,7 @@ class ImageComponent extends StatelessWidget {
child: CachedNetworkImage(
imageUrl: '${Constant.apiUrl}/v1/attachments?uuid=$uuid&type=$type',
filterQuality: FilterQuality.high,
fit: BoxFit.cover,
fit: fit,
width: width,
height: height,
placeholder: (context, url) => Container(
Expand Down
10 changes: 8 additions & 2 deletions lib/controllers/anime_search_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class AnimeSearchController {
final scrollController = ScrollController();
final streamController = StreamController<List<AnimeDto>>.broadcast();
int page = 1;
Timer? _timer;
bool isLoading = false;
bool canLoadMore = true;
String query = '';
Expand All @@ -31,12 +32,17 @@ class AnimeSearchController {
});
}

Future<void> search(String query) async {
void search(String query) {
this.query = query;
animes.clear();
streamController.add(animes);
page = 1;
await nextPage();

_timer?.cancel();
_timer = Timer(
const Duration(milliseconds: 250),
() => nextPage(),
);
}

void dispose() {
Expand Down
3 changes: 3 additions & 0 deletions lib/utils/constant.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
class Constant {
static const apiUrl = 'https://api.shikkanime.fr';
static const baseUrl = 'https://www.shikkanime.fr';

// static const apiUrl = 'http://192.168.1.71:37100/api';
// static const baseUrl = 'http://192.168.1.71:37100';
}
1 change: 0 additions & 1 deletion lib/views/search_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ class _SearchViewState extends State<SearchView> {
],
onChanged: (query) {
AnimeSearchController.instance.search(query);

setState(() {});
},
),
Expand Down

0 comments on commit b63fb5e

Please sign in to comment.