-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(science-clubs): add new filters section
- Loading branch information
1 parent
9544be4
commit 0b7a3d9
Showing
47 changed files
with
1,456 additions
and
679 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import "package:flutter/material.dart"; | ||
import "package:freezed_annotation/freezed_annotation.dart"; | ||
|
||
import "../../../theme/hex_color.dart"; | ||
import "../../../utils/colors_sort.dart"; | ||
import "../../topwr_mockup/config/ui_config.dart"; | ||
|
||
part "department.freezed.dart"; | ||
part "department.g.dart"; | ||
|
||
@freezed | ||
class Department with _$Department { | ||
const factory Department({ | ||
required String name, | ||
required String code, | ||
String? betterCode, | ||
String? gradientStart, | ||
String? gradientEnd, | ||
}) = _Department; | ||
|
||
const Department._(); | ||
|
||
factory Department.fromJson(Map<String, Object?> json) => | ||
_$DepartmentFromJson(json); | ||
|
||
LinearGradient get gradient => LinearGradient( | ||
colors: [ | ||
HexColor( | ||
gradientStart ?? DepartmentsConfig.defaultColorFirst, | ||
), | ||
HexColor( | ||
gradientEnd ?? DepartmentsConfig.defaultColorSecond, | ||
), | ||
]..sortByLightness(), | ||
); | ||
} | ||
|
||
extension GetDepartmentsCodeX on Department? { | ||
static const _fallbackCode = 0; | ||
|
||
int extractIntFromStrCode() { | ||
if (this != null && this!.code.length >= 2) { | ||
return int.tryParse(this!.code.substring(1)) ?? _fallbackCode; | ||
} | ||
return _fallbackCode; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import "package:cloud_firestore/cloud_firestore.dart"; | ||
import "package:fast_immutable_collections/fast_immutable_collections.dart"; | ||
import "package:riverpod_annotation/riverpod_annotation.dart"; | ||
|
||
import "../../../config/firebase.dart"; | ||
import "../models/department.dart"; | ||
|
||
part "department_repo.g.dart"; | ||
|
||
@Riverpod(keepAlive: true) | ||
class DepartmentRepo extends _$DepartmentRepo { | ||
late final _collection = FirebaseFirestore.instance | ||
.collection(FirebaseConfig.departments) | ||
.withConverter<Department>( | ||
fromFirestore: (snapshots, _) => Department.fromJson(snapshots.data()!), | ||
toFirestore: (model, _) => model.toJson(), | ||
); | ||
|
||
@override | ||
FutureOr<IList<Department>> build() async { | ||
final data = await _collection.get(); | ||
return data.docs.map((e) => e.data()).toIList().sort( | ||
(a, b) => a.extractIntFromStrCode().compareTo( | ||
b.extractIntFromStrCode(), | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
...eatures/topwr_mockup/features/sci_clubs_tab/controller/science_clubs_view_controller.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import "package:riverpod_annotation/riverpod_annotation.dart"; | ||
|
||
import "../../../../../utils/contains_lower_case.dart"; | ||
import "../../../../../utils/where_non_null_iterable.dart"; | ||
import "../../../../firebase/models/sci_club.dart"; | ||
import "../../../../firebase/repositories/sci_clubs_repo.dart"; | ||
import "../../science_clubs_filters/filters_controller.dart"; | ||
|
||
part "science_clubs_view_controller.g.dart"; | ||
|
||
@riverpod | ||
class SearchScienceClubsController extends _$SearchScienceClubsController { | ||
@override | ||
String build() => ""; | ||
|
||
void onTextChanged(String newValue) { | ||
state = newValue; | ||
} | ||
} | ||
|
||
@riverpod | ||
Future<Iterable<SciClub?>?> _sciClubsFilteredByTextQuery( | ||
_SciClubsFilteredByTextQueryRef ref, | ||
) async { | ||
final originalList = await ref.watch(sciClubsRepoProvider.future); | ||
final query = ref.watch(searchScienceClubsControllerProvider); | ||
return originalList.where( | ||
(element) => | ||
element.name.containsLowerCase(query) || | ||
element.department.containsLowerCase(query), | ||
); | ||
} | ||
|
||
@riverpod | ||
Future<Iterable<SciClub?>?> scienceClubsListController( | ||
ScienceClubsListControllerRef ref, | ||
) async { | ||
final sciClubs = | ||
(await ref.watch(_sciClubsFilteredByTextQueryProvider.future)) | ||
.whereNonNull; | ||
|
||
if (!ref.watch(areFiltersEnabledProvider)) { | ||
return sciClubs; | ||
} | ||
|
||
final selectedTags = | ||
ref.watch(selectedTagControllerProvider).map((it) => it.name); | ||
|
||
final selectedDepartments = | ||
ref.watch(selectedDepartmentControllerProvider).map((it) => it.name); | ||
|
||
final selectedTypes = | ||
ref.watch(selectedTypeControllerProvider).map((it) => it.toJson()); | ||
|
||
final filteredByTypes = selectedTypes.isEmpty | ||
? sciClubs | ||
: sciClubs.whereNonNull.where( | ||
(club) => selectedTypes.contains(club.type?.toJsonVal()), | ||
); | ||
|
||
final filteredByDepartments = selectedDepartments.isEmpty | ||
? filteredByTypes | ||
: filteredByTypes.where( | ||
(club) => selectedDepartments.contains(club.department), | ||
); | ||
|
||
final filteredByTags = selectedTags.isEmpty | ||
? filteredByDepartments | ||
: filteredByDepartments.where( | ||
(club) => club.tags.whereNonNull.any(selectedTags.contains), | ||
); | ||
|
||
return filteredByTags; | ||
} |
53 changes: 0 additions & 53 deletions
53
...res/topwr_mockup/features/sci_clubs_tab/controller/scientific_circles_tab_controller.dart
This file was deleted.
Oops, something went wrong.
18 changes: 0 additions & 18 deletions
18
lib/features/topwr_mockup/features/sci_clubs_tab/controller/selected_tag_controller.dart
This file was deleted.
Oops, something went wrong.
27 changes: 27 additions & 0 deletions
27
lib/features/topwr_mockup/features/sci_clubs_tab/science_clubs_view.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import "package:flutter/material.dart"; | ||
import "package:flutter_riverpod/flutter_riverpod.dart"; | ||
|
||
import "../../../../utils/context_extensions.dart"; | ||
import "../../widgets/search_box_app_bar.dart"; | ||
import "../science_clubs_filters/widgets/filters_fab.dart"; | ||
import "controller/science_clubs_view_controller.dart"; | ||
import "widgets/science_clubs_list.dart"; | ||
|
||
class ScienceClubsView extends ConsumerWidget { | ||
const ScienceClubsView({super.key}); | ||
|
||
@override | ||
Widget build(BuildContext context, WidgetRef ref) { | ||
return Scaffold( | ||
appBar: SearchBoxAppBar( | ||
context, | ||
title: context.localize.study_circles, | ||
onQueryChanged: ref | ||
.watch(searchScienceClubsControllerProvider.notifier) | ||
.onTextChanged, | ||
), | ||
floatingActionButton: const FiltersFAB(), | ||
body: const ScienceClubsList(), | ||
); | ||
} | ||
} |
Oops, something went wrong.