Skip to content

Commit

Permalink
fix(overseerr): rehydrate missing cached media content when required …
Browse files Browse the repository at this point in the history
…after cache ejection
  • Loading branch information
JagandeepBrar committed Feb 19, 2022
1 parent 77097de commit b09353b
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 22 deletions.
2 changes: 1 addition & 1 deletion lib/core/mixins/load_callback.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ mixin LunaLoadCallbackMixin<T extends StatefulWidget> on State<T> {
@override
void initState() {
super.initState();
WidgetsBinding.instance!.addPostFrameCallback((_) => loadCallback());
WidgetsBinding.instance?.addPostFrameCallback((_) => loadCallback());
}

Future<void> loadCallback();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,6 @@ class _State extends State<OverseerrRequestsListView> {
if (_requests.isNotEmpty) {
_requests.forEach((request) {
int id = request.media!.tmdbId!;
switch (request.type!) {
case OverseerrMediaType.MOVIE:
context.read<OverseerrState>().fetchMovie(id);
break;
case OverseerrMediaType.TV:
context.read<OverseerrState>().fetchSeries(id);
break;
}
});
}

Expand Down
60 changes: 47 additions & 13 deletions lib/modules/overseerr/routes/requests/widgets/request_tile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,50 +2,82 @@ import 'package:flutter/material.dart';
import 'package:lunasea/core.dart';
import 'package:lunasea/modules/overseerr.dart';

class OverseerrRequestTile extends StatelessWidget {
class OverseerrRequestTile extends StatefulWidget {
final OverseerrRequest request;

const OverseerrRequestTile({
Key? key,
required this.request,
}) : super(key: key);

@override
State<OverseerrRequestTile> createState() => _State();
}

class _State extends State<OverseerrRequestTile> with LunaLoadCallbackMixin {
bool _loaded = false;

@override
Future<void> loadCallback() async {
int id = widget.request.media!.tmdbId!;
switch (widget.request.type!) {
case OverseerrMediaType.MOVIE:
if (mounted) await context.read<OverseerrState>().fetchMovie(id);
break;
case OverseerrMediaType.TV:
if (mounted) await context.read<OverseerrState>().fetchSeries(id);
break;
}
if (mounted) setState(() => _loaded = true);
}

@override
Widget build(BuildContext context) {
if (!_loaded) return _loadingBlock();

return Selector<OverseerrState,
Tuple2<Future<OverseerrMovie?>, Future<OverseerrSeries?>>>(
selector: (_, state) => Tuple2(
state.getMovie(request.media!.tmdbId!),
state.getSeries(request.media!.tmdbId!),
state.getMovie(widget.request.media!.tmdbId!),
state.getSeries(widget.request.media!.tmdbId!),
),
builder: (context, data, _) => FutureBuilder(
future: Future.wait([data.item1, data.item2]),
builder: (context, AsyncSnapshot<List> snapshot) {
if (snapshot.hasData) {
switch (request.type!) {
switch (widget.request.type!) {
case OverseerrMediaType.MOVIE:
return _movieBlock(context, snapshot.data![0]);
if (snapshot.data?[0] != null)
return _movieBlock(context, snapshot.data![0]);
break;
case OverseerrMediaType.TV:
return _seriesBlock(context, snapshot.data![1]);
if (snapshot.data?[1] != null)
return _seriesBlock(context, snapshot.data![1]);
break;
}
}
return const LunaBlock(skeletonEnabled: true, skeletonSubtitles: 3);
return _loadingBlock();
},
),
);
}

Widget _loadingBlock() {
return const LunaBlock(skeletonEnabled: true, skeletonSubtitles: 3);
}

Widget _movieBlock(BuildContext context, OverseerrMovie movie) {
return LunaBlock(
title: movie.lunaTitle(),
body: [
TextSpan(text: movie.lunaYear()),
TextSpan(text: request.lunaRequestedBy()),
TextSpan(text: widget.request.lunaRequestedBy()),
TextSpan(
text: request.lunaRequestStatus(),
text: widget.request.lunaRequestStatus(),
style: TextStyle(
fontWeight: LunaUI.FONT_WEIGHT_BOLD,
color: request.status.lunaColour(request.lunaMediaStatus()),
color: widget.request.status
.lunaColour(widget.request.lunaMediaStatus()),
),
),
],
Expand All @@ -62,12 +94,14 @@ class OverseerrRequestTile extends StatelessWidget {
title: series.lunaTitle(),
body: [
TextSpan(text: series.lunaYear()),
TextSpan(text: request.lunaRequestedBy()),
TextSpan(text: widget.request.lunaRequestedBy()),
TextSpan(
text: request.lunaRequestStatus(),
text: widget.request.lunaRequestStatus(),
style: TextStyle(
fontWeight: LunaUI.FONT_WEIGHT_BOLD,
color: request.status.lunaColour(request.lunaMediaStatus()),
color: widget.request.status.lunaColour(
widget.request.lunaMediaStatus(),
),
),
),
],
Expand Down

0 comments on commit b09353b

Please sign in to comment.