Skip to content

Commit

Permalink
Merge pull request #258 from aeecleclair/column-refresher
Browse files Browse the repository at this point in the history
Optimisation: Column refresher
  • Loading branch information
guillaumetavernier authored Feb 4, 2024
2 parents 11f2385 + f248cae commit 2aa00a5
Show file tree
Hide file tree
Showing 5 changed files with 313 additions and 253 deletions.
80 changes: 42 additions & 38 deletions lib/advert/ui/pages/admin_page/admin_advert_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,46 +21,50 @@ class AdminAdvertCard extends HookConsumerWidget {

@override
Widget build(BuildContext context, WidgetRef ref) {
return Stack(
children: [
AdvertCard(onTap: onTap, advert: advert),
Positioned(
right: 15,
child: Container(
margin: const EdgeInsets.only(top: 30),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
GestureDetector(
onTap: onEdit,
child: CardButton(
colors: [
Colors.grey.shade100,
Colors.grey.shade400,
],
shadowColor: Colors.grey.shade300.withOpacity(0.2),
child:
const HeroIcon(HeroIcons.pencil, color: Colors.black),
),
),
const SizedBox(width: 20),
WaitingButton(
onTap: onDelete,
builder: (child) => CardButton(
colors: const [
AdvertColorConstants.redGradient1,
AdvertColorConstants.redGradient2,
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 30),
child: Stack(
children: [
AdvertCard(onTap: onTap, advert: advert),
Positioned(
top: 10,
right: 15,
child: Container(
margin: const EdgeInsets.only(top: 30),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
GestureDetector(
onTap: onEdit,
child: CardButton(
colors: [
Colors.grey.shade100,
Colors.grey.shade400,
],
shadowColor:
AdvertColorConstants.redGradient2.withOpacity(0.2),
child: child),
child: const HeroIcon(HeroIcons.trash, color: Colors.white),
),
],
shadowColor: Colors.grey.shade300.withOpacity(0.2),
child:
const HeroIcon(HeroIcons.pencil, color: Colors.black),
),
),
const SizedBox(width: 20),
WaitingButton(
onTap: onDelete,
builder: (child) => CardButton(
colors: const [
AdvertColorConstants.redGradient1,
AdvertColorConstants.redGradient2,
],
shadowColor:
AdvertColorConstants.redGradient2.withOpacity(0.2),
child: child),
child: const HeroIcon(HeroIcons.trash, color: Colors.white),
),
],
),
),
),
)
],
)
],
),
);
}
}
176 changes: 86 additions & 90 deletions lib/advert/ui/pages/admin_page/admin_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import 'package:myecl/advert/router.dart';
import 'package:myecl/advert/ui/components/announcer_bar.dart';
import 'package:myecl/tools/ui/builders/async_child.dart';
import 'package:myecl/tools/ui/layouts/card_layout.dart';
import 'package:myecl/tools/ui/layouts/refresher.dart';
import 'package:myecl/tools/ui/layouts/column_refresher.dart';
import 'package:myecl/tools/ui/widgets/dialog.dart';
import 'package:qlevar_router/qlevar_router.dart';

Expand All @@ -32,100 +32,96 @@ class AdvertAdminPage extends HookConsumerWidget {
final selectedAnnouncers = ref.watch(announcerProvider);
final selectedAnnouncersNotifier = ref.read(announcerProvider.notifier);
return AdvertTemplate(
child: Refresher(
onRefresh: () async {
await advertListNotifier.loadAdverts();
await userAnnouncerListNotifier.loadMyAnnouncerList();
},
child: AsyncChild(
value: advertList,
builder: (context, advertData) => AsyncChild(
value: userAnnouncerList,
builder: (context, userAnnouncerData) {
final userAnnouncerAdvert = advertData.where((advert) =>
userAnnouncerData
.where((element) =>
advert.announcer.id == element.id)
.isNotEmpty);
final sortedUserAnnouncerAdverts = userAnnouncerAdvert
.toList()
.sortedBy((element) => element.date)
.reversed;
final filteredSortedUserAnnouncerAdverts =
sortedUserAnnouncerAdverts
.where((advert) =>
selectedAnnouncers
.where((e) => advert.announcer.id == e.id)
.isNotEmpty ||
selectedAnnouncers.isEmpty)
.toList();
return Column(
children: [
const AnnouncerBar(
useUserAnnouncers: true,
multipleSelect: true,
),
GestureDetector(
child: AsyncChild(
value: advertList,
builder: (context, advertData) => AsyncChild(
value: userAnnouncerList,
builder: (context, userAnnouncerData) {
final userAnnouncerAdvert = advertData.where((advert) =>
userAnnouncerData
.where((element) => advert.announcer.id == element.id)
.isNotEmpty);
final sortedUserAnnouncerAdverts = userAnnouncerAdvert
.toList()
.sortedBy((element) => element.date)
.reversed;
final filteredSortedUserAnnouncerAdverts =
sortedUserAnnouncerAdverts
.where((advert) =>
selectedAnnouncers
.where((e) => advert.announcer.id == e.id)
.isNotEmpty ||
selectedAnnouncers.isEmpty)
.toList();
return ColumnRefresher(
onRefresh: () async {
await advertListNotifier.loadAdverts();
await userAnnouncerListNotifier.loadMyAnnouncerList();
},
children: [
const AnnouncerBar(
useUserAnnouncers: true,
multipleSelect: true,
),
GestureDetector(
onTap: () {
advertNotifier.setAdvert(Advert.empty());
QR.to(AdvertRouter.root +
AdvertRouter.admin +
AdvertRouter.addEditAdvert);
},
child: CardLayout(
margin: const EdgeInsets.only(
bottom: 10, top: 20, left: 30, right: 30),
width: 300,
height: 100,
colors: [
Colors.white,
Colors.grey.shade100,
],
shadowColor: Colors.grey.withOpacity(0.2),
child: Center(
child: HeroIcon(
HeroIcons.plus,
size: 40,
color: Colors.grey.shade500,
))),
),
...filteredSortedUserAnnouncerAdverts.map(
(advert) => AdminAdvertCard(
onTap: () {
advertNotifier.setAdvert(Advert.empty());
advertNotifier.setAdvert(advert);
QR.to(AdvertRouter.root + AdvertRouter.detail);
},
onEdit: () {
QR.to(AdvertRouter.root +
AdvertRouter.admin +
AdvertRouter.addEditAdvert);
advertNotifier.setAdvert(advert);
selectedAnnouncersNotifier.clearAnnouncer();
selectedAnnouncersNotifier
.addAnnouncer(advert.announcer);
},
child: CardLayout(
margin: const EdgeInsets.only(
bottom: 10, top: 20, left: 30, right: 30),
width: 300,
height: 100,
colors: [
Colors.white,
Colors.grey.shade100,
],
shadowColor: Colors.grey.withOpacity(0.2),
child: Center(
child: HeroIcon(
HeroIcons.plus,
size: 40,
color: Colors.grey.shade500,
))),
),
...filteredSortedUserAnnouncerAdverts.map(
(advert) => AdminAdvertCard(
onTap: () {
advertNotifier.setAdvert(advert);
QR.to(
AdvertRouter.root + AdvertRouter.detail);
},
onEdit: () {
QR.to(AdvertRouter.root +
AdvertRouter.admin +
AdvertRouter.addEditAdvert);
advertNotifier.setAdvert(advert);
selectedAnnouncersNotifier.clearAnnouncer();
selectedAnnouncersNotifier
.addAnnouncer(advert.announcer);
},
onDelete: () async {
await showDialog(
context: context,
builder: (context) {
return CustomDialogBox(
title: AdvertTextConstants.deleting,
descriptions:
AdvertTextConstants.deleteAdvert,
onYes: () {
advertListNotifier
.deleteAdvert(advert);
},
);
});
},
advert: advert),
),
],
);
},
))),
onDelete: () async {
await showDialog(
context: context,
builder: (context) {
return CustomDialogBox(
title: AdvertTextConstants.deleting,
descriptions:
AdvertTextConstants.deleteAdvert,
onYes: () {
advertListNotifier.deleteAdvert(advert);
},
);
});
},
advert: advert),
),
],
);
},
)),
);
}
}
Loading

0 comments on commit 2aa00a5

Please sign in to comment.