2023-05-25 05:52:43 +02:00
|
|
|
import 'package:flutter/material.dart';
|
2023-09-10 14:51:18 +02:00
|
|
|
import 'package:flutter_hooks/flutter_hooks.dart';
|
2023-05-25 05:52:43 +02:00
|
|
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
2023-11-29 06:17:29 +02:00
|
|
|
import 'package:immich_mobile/extensions/asyncvalue_extensions.dart';
|
2023-05-25 05:52:43 +02:00
|
|
|
import 'package:immich_mobile/modules/home/ui/asset_grid/immich_asset_grid.dart';
|
2023-11-13 17:54:41 +02:00
|
|
|
import 'package:immich_mobile/modules/partner/providers/partner.provider.dart';
|
2023-05-25 05:52:43 +02:00
|
|
|
import 'package:immich_mobile/shared/models/user.dart';
|
|
|
|
import 'package:immich_mobile/shared/providers/asset.provider.dart';
|
2023-11-13 17:54:41 +02:00
|
|
|
import 'package:immich_mobile/shared/ui/immich_toast.dart';
|
2023-05-25 05:52:43 +02:00
|
|
|
|
|
|
|
class PartnerDetailPage extends HookConsumerWidget {
|
|
|
|
const PartnerDetailPage({Key? key, required this.partner}) : super(key: key);
|
|
|
|
|
|
|
|
final User partner;
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
|
|
|
final assets = ref.watch(assetsProvider(partner.isarId));
|
2023-11-13 17:54:41 +02:00
|
|
|
final inTimeline = useState(partner.inTimeline);
|
|
|
|
bool toggleInProcess = false;
|
2023-05-25 05:52:43 +02:00
|
|
|
|
2023-09-10 14:51:18 +02:00
|
|
|
useEffect(
|
|
|
|
() {
|
|
|
|
ref.read(assetProvider.notifier).getPartnerAssets(partner);
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
[],
|
|
|
|
);
|
|
|
|
|
2023-11-13 17:54:41 +02:00
|
|
|
void toggleInTimeline() async {
|
|
|
|
if (toggleInProcess) return;
|
|
|
|
toggleInProcess = true;
|
|
|
|
try {
|
|
|
|
final ok = await ref
|
|
|
|
.read(partnerSharedWithProvider.notifier)
|
|
|
|
.updatePartner(partner, inTimeline: !inTimeline.value);
|
|
|
|
if (ok) {
|
|
|
|
inTimeline.value = !inTimeline.value;
|
|
|
|
final action = inTimeline.value ? "shown on" : "hidden from";
|
|
|
|
ImmichToast.show(
|
|
|
|
context: context,
|
|
|
|
toastType: ToastType.success,
|
|
|
|
durationInSecond: 1,
|
|
|
|
msg: "${partner.name}'s assets $action your timeline",
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
ImmichToast.show(
|
|
|
|
context: context,
|
|
|
|
toastType: ToastType.error,
|
|
|
|
durationInSecond: 1,
|
|
|
|
msg: "Failed to toggle the timeline setting",
|
|
|
|
);
|
|
|
|
}
|
|
|
|
} finally {
|
|
|
|
toggleInProcess = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-25 05:52:43 +02:00
|
|
|
return Scaffold(
|
|
|
|
appBar: AppBar(
|
2023-11-12 03:03:32 +02:00
|
|
|
title: Text(partner.name),
|
2023-05-25 05:52:43 +02:00
|
|
|
elevation: 0,
|
|
|
|
centerTitle: false,
|
2023-11-13 17:54:41 +02:00
|
|
|
actions: [
|
|
|
|
IconButton(
|
|
|
|
onPressed: toggleInTimeline,
|
|
|
|
icon: Icon(
|
|
|
|
inTimeline.value ? Icons.collections : Icons.collections_outlined,
|
|
|
|
),
|
|
|
|
tooltip: "Show/hide photos on your main timeline",
|
|
|
|
),
|
|
|
|
],
|
2023-05-25 05:52:43 +02:00
|
|
|
),
|
2023-11-29 06:17:29 +02:00
|
|
|
body: assets.widgetWhen(
|
|
|
|
onData: (renderList) => renderList.isEmpty
|
2023-05-25 05:52:43 +02:00
|
|
|
? Padding(
|
|
|
|
padding: const EdgeInsets.all(16),
|
|
|
|
child: Text(
|
2023-11-12 03:03:32 +02:00
|
|
|
"It seems ${partner.name} does not have any photos...\n"
|
2023-05-25 05:52:43 +02:00
|
|
|
"Or your server version does not match the app version."),
|
|
|
|
)
|
|
|
|
: ImmichAssetGrid(
|
|
|
|
renderList: renderList,
|
2023-09-10 14:51:18 +02:00
|
|
|
onRefresh: () =>
|
|
|
|
ref.read(assetProvider.notifier).getPartnerAssets(partner),
|
2023-05-25 05:52:43 +02:00
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|