Skip to content

Commit

Permalink
feat - #238 sort links on about us team
Browse files Browse the repository at this point in the history
  • Loading branch information
mikolaj-jalocha committed Sep 27, 2024
1 parent 9584c24 commit bc67baf
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 12 deletions.
18 changes: 16 additions & 2 deletions lib/config/contact_icons.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ abstract class ContactIconsConfig {
"tiktok": Assets.svg.contactIcons.tiktok,
"discord": Assets.svg.contactIcons.discord,
};
static final iconsOrder = {
static final iconsOrderAtSciClubs = {
"maps": 1,
"tel": 2,
"mailto:": 3,
Expand All @@ -27,6 +27,20 @@ abstract class ContactIconsConfig {
"youtu": 11,
"tiktok": 12,
};
static const defaultIconOrder = 2;
static final iconsOrderAtAboutUs = {
"github": 1,
"linkedin": 2,
"facebook": 4,
"mailto:": 5,
"instagram": 6,
"https://x.com": 7,
"discord": 8,
"youtu": 9,
"tiktok": 10,
"maps": 11,
"tel": 12,
};
static const defaultIconOrderAtSciClubs = 2;
static const defaultIconOrderAtAboutUs = 3;
static final defaultIcon = Assets.svg.contactIcons.web;
}
6 changes: 3 additions & 3 deletions lib/features/about_us_view/about_us_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,13 @@ class _AboutUsView extends ConsumerWidget {
),
],
),
_ => const _AboustUsLoading(),
_ => const _AboutUsLoading(),
};
}
}

class _AboustUsLoading extends StatelessWidget {
const _AboustUsLoading();
class _AboutUsLoading extends StatelessWidget {
const _AboutUsLoading();

@override
Widget build(BuildContext context) {
Expand Down
3 changes: 2 additions & 1 deletion lib/features/about_us_view/models/about_us_details.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class AboutUsDetails {
.map(
(e) => ContactIconsModel(url: e.url),
)
.toIList();
.toIList()
.sort((a, b) => a.order.compareTo(b.order));
}
}
5 changes: 4 additions & 1 deletion lib/features/about_us_view/models/member_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ class MemberData {
}) : links = _determineLinksIcons(socialLinks);

static IList<ContactIconsModel> _determineLinksIcons(IList<String> urls) {
return urls.map((url) => ContactIconsModel(url: url)).toIList();
return urls
.map((url) => ContactIconsModel(url: url, isSciClub: false))
.toIList()
.sort((a, b) => a.order.compareTo(b.order));
}

@override
Expand Down
25 changes: 20 additions & 5 deletions lib/utils/determine_contact_icon.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,16 @@ class ContactIconsModel {
final String? text;
final String? url;
final int order;
final bool isSciClub;

ContactIconsModel({
String? text,
this.url,
this.isSciClub = true,
}) : icon = url.determineIcon(),
order = url.determineIconOrder(),
order = isSciClub
? url.determineIconOrderForSciClubs()
: url.determineIconOrderForAboutUs(),
text = text ?? url;
}

Expand All @@ -30,14 +34,25 @@ extension IconDeterminerX on String? {
: ContactIconsConfig.defaultIcon;
}

int determineIconOrder() {
int determineIconOrderForSciClubs() {
return this != null
? ContactIconsConfig.iconsOrder.entries
? ContactIconsConfig.iconsOrderAtSciClubs.entries
.firstWhereOrNull(
(e) => this!.contains(e.key),
)
?.value ??
ContactIconsConfig.defaultIconOrder
: ContactIconsConfig.defaultIconOrder;
ContactIconsConfig.defaultIconOrderAtSciClubs
: ContactIconsConfig.defaultIconOrderAtSciClubs;
}

int determineIconOrderForAboutUs() {
return this != null
? ContactIconsConfig.iconsOrderAtAboutUs.entries
.firstWhereOrNull(
(e) => this!.contains(e.key),
)
?.value ??
ContactIconsConfig.defaultIconOrderAtAboutUs
: ContactIconsConfig.defaultIconOrderAtAboutUs;
}
}

0 comments on commit bc67baf

Please sign in to comment.