Fix state refresh issue on converting to album

Signed-off-by: Neeraj Gupta <254676+ua741@users.noreply.github.com>
This commit is contained in:
Neeraj Gupta 2023-08-04 13:11:23 +05:30
parent bdd47e61a3
commit d968ef64db

View file

@ -68,6 +68,7 @@ enum AlbumPopupAction {
setCover,
addPhotos,
pinAlbum,
removeLink,
}
class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {
@ -77,9 +78,12 @@ class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {
String? _appBarTitle;
late CollectionActions collectionActions;
final GlobalKey shareButtonKey = GlobalKey();
bool isQuickLink = false;
late GalleryType galleryType;
@override
void initState() {
super.initState();
_selectedFilesListener = () {
setState(() {});
};
@ -90,7 +94,7 @@ class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {
setState(() {});
});
_appBarTitle = widget.title;
super.initState();
galleryType = widget.type;
}
@override
@ -102,15 +106,15 @@ class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {
@override
Widget build(BuildContext context) {
return widget.type == GalleryType.homepage
return galleryType == GalleryType.homepage
? const SizedBox.shrink()
: AppBar(
backgroundColor: widget.type == GalleryType.homepage
backgroundColor: galleryType == GalleryType.homepage
? const Color(0x00000000)
: null,
elevation: 0,
centerTitle: false,
title: widget.type == GalleryType.homepage
title: galleryType == GalleryType.homepage
? const SizedBox.shrink()
: TextButton(
child: Text(
@ -127,11 +131,13 @@ class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {
}
Future<dynamic> _renameAlbum(BuildContext context) async {
final bool isQuickLink = widget.type == GalleryType.quickLink;
if (widget.type != GalleryType.ownedCollection && widget.type !=
GalleryType.quickLink) {
showToast(context, 'Type of galler ${widget.type} is not supported for '
'rename',);
if (galleryType != GalleryType.ownedCollection &&
galleryType != GalleryType.quickLink) {
showToast(
context,
'Type of galler $galleryType is not supported for '
'rename',
);
return;
}
final result = await showTextInputDialog(
@ -152,6 +158,11 @@ class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {
await CollectionsService.instance.rename(widget.collection!, text);
if (mounted) {
_appBarTitle = text;
if (isQuickLink) {
// update the gallery type to owned collection so that correct
// actions are shown
galleryType = GalleryType.ownedCollection;
}
setState(() {});
}
} catch (e, s) {
@ -265,12 +276,12 @@ class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {
return actions;
}
final int userID = Configuration.instance.getUserID()!;
final bool isQuickLink = widget.type == GalleryType.quickLink;
if ((widget.type == GalleryType.ownedCollection ||
widget.type == GalleryType.sharedCollection ||
widget.type == GalleryType.quickLink) &&
isQuickLink = widget.collection?.isQuickLinkCollection() ?? false;
if ((galleryType == GalleryType.ownedCollection ||
galleryType == GalleryType.sharedCollection ||
isQuickLink) &&
widget.collection?.type != CollectionType.favorites) {
final bool canAddFiles = widget.type == GalleryType.ownedCollection ||
final bool canAddFiles = galleryType == GalleryType.ownedCollection ||
widget.collection!.getRole(userID) ==
CollectionParticipantRole.collaborator;
if (canAddFiles) {
@ -291,8 +302,7 @@ class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {
message: "Share",
child: IconButton(
icon: Icon(
widget.type == GalleryType.quickLink
? Icons.link_outlined
isQuickLink ? Icons.link_outlined
: Icons.people_outlined,
),
onPressed: () async {
@ -303,7 +313,7 @@ class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {
);
}
final List<PopupMenuItem<AlbumPopupAction>> items = [];
if (widget.type == GalleryType.ownedCollection || isQuickLink) {
if (galleryType == GalleryType.ownedCollection || isQuickLink) {
if (widget.collection!.type != CollectionType.favorites) {
items.add(
PopupMenuItem(
@ -340,8 +350,9 @@ class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {
);
}
}
if (widget.type == GalleryType.ownedCollection ||
widget.type == GalleryType.sharedCollection || isQuickLink) {
if (galleryType == GalleryType.ownedCollection ||
galleryType == GalleryType.sharedCollection ||
isQuickLink) {
items.add(
PopupMenuItem(
value: AlbumPopupAction.map,
@ -437,7 +448,9 @@ class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {
if (widget.collection!.type != CollectionType.favorites) {
items.add(
PopupMenuItem(
value: AlbumPopupAction.delete,
value: isQuickLink
? AlbumPopupAction.removeLink
: AlbumPopupAction.delete,
child: Row(
children: [
const Icon(Icons.delete_outline),
@ -452,7 +465,7 @@ class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {
}
} // ownedCollection open ends
if (widget.type == GalleryType.sharedCollection) {
if (galleryType == GalleryType.sharedCollection) {
final bool hasShareeArchived = widget.collection!.hasShareeArchived();
items.add(
PopupMenuItem(
@ -489,7 +502,7 @@ class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {
),
);
}
if (widget.type == GalleryType.localFolder) {
if (galleryType == GalleryType.localFolder) {
items.add(
PopupMenuItem(
value: AlbumPopupAction.freeUpSpace,
@ -652,11 +665,11 @@ class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {
final collection = widget.collection;
try {
if (collection == null ||
(widget.type != GalleryType.ownedCollection &&
widget.type != GalleryType.sharedCollection &&
widget.type != GalleryType.quickLink)) {
(galleryType != GalleryType.ownedCollection &&
galleryType != GalleryType.sharedCollection &&
!isQuickLink)) {
throw Exception(
"Cannot share empty collection of typex ${widget.type}",
"Cannot share empty collection of type $galleryType",
);
}
if (Configuration.instance.getUserID() == widget.collection!.owner!.id) {