Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions assets/translations/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@
"openWebsite": "Webseite öffnen",
"refresh": "Aktualisieren",
"studentClubs": "Hochschulgruppen",
"studentClubNoWebsite": "Keine Webseite angegeben",
"studentClubNoDetails": "Noch keine Details oder Webseite",
"studentClubNoDescription": "Diese Gruppe hat noch keine Beschreibung hinzugefügt.",
"studentClubSearch": "Gruppen durchsuchen",
"studentClubHasWebsite": "Mit Webseite",
"studentClubAllCategories": "Alle Kategorien",
"studentClubCategories": "Kategorien",
"studentClubNoMatches": "Keine Gruppen passen zu deinen Filtern",
"studentClubClearFilters": "Filter zurücksetzen",
"campusClubsShortcut": "Gruppen",
"campusDiscoverDescription": "Nachrichten, Filme und Hochschulgruppen.",
"campusDiscover": "Dein Campus",
Expand Down
9 changes: 9 additions & 0 deletions assets/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@
"openWebsite": "Open website",
"refresh": "Refresh",
"studentClubs": "Student clubs",
"studentClubNoWebsite": "No website listed",
"studentClubNoDetails": "No details or website yet",
"studentClubNoDescription": "This club hasn't added a description yet.",
"studentClubSearch": "Search clubs",
"studentClubHasWebsite": "Has website",
"studentClubAllCategories": "All categories",
"studentClubCategories": "Categories",
"studentClubNoMatches": "No clubs match your filters",
"studentClubClearFilters": "Clear filters",
"campusClubsShortcut": "Clubs",
"campusDiscoverDescription": "News, films and student clubs, all in one place.",
"campusDiscover": "Life on campus",
Expand Down
16 changes: 16 additions & 0 deletions lib/campusComponent/model/student_club.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,20 @@ import 'package:html/parser.dart';

extension ParsedStudentClub on StudentClub {
String get parsedName => parseFragment(name).text ?? name;

String get parsedDescription =>
(parseFragment(description).text ?? description).trim();

bool get hasParsedDescription => parsedDescription.isNotEmpty;

bool get hasLink => linkUrl.trim().isNotEmpty;

String get linkDomain {
final url = linkUrl.trim();
final host = Uri.tryParse(url)?.host ?? '';
if (host.isEmpty) return url;
return host.startsWith('www.') ? host.substring(4) : host;
}

bool get hasDetails => hasParsedDescription || hasLink;
}
267 changes: 210 additions & 57 deletions lib/campusComponent/screen/student_clubs_screen.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import 'package:campus_flutter/base/networking/apis/tumdev/campus_backend.pb.dart';
import 'package:campus_flutter/base/util/url_launcher.dart';
import 'package:campus_flutter/campusComponent/model/student_club.dart';
import 'package:campus_flutter/campusComponent/model/student_club_collection.dart';
import 'package:campus_flutter/campusComponent/view/studentClub/student_club_card_view.dart';
import 'package:campus_flutter/campusComponent/view/studentClub/student_club_list_tile.dart';
import 'package:campus_flutter/campusComponent/view/shared/campus_collection_view.dart';
import 'package:campus_flutter/campusComponent/viewmodel/student_club_viewmodel.dart';
import 'package:easy_localization/easy_localization.dart';
Expand All @@ -16,6 +18,12 @@ class StudentClubsScreen extends ConsumerStatefulWidget {

class _StudentClubsScreenState extends ConsumerState<StudentClubsScreen> {
Locale? _locale;
final _search = TextEditingController();
String? _category;
bool _hasWebsite = false;

/// Lower-cased name and description, parsed once per club.
final _searchText = Expando<String>();

@override
void didChangeDependencies() {
Expand All @@ -31,77 +39,222 @@ class _StudentClubsScreenState extends ConsumerState<StudentClubsScreen> {
_locale = locale;
}

@override
void dispose() {
_search.dispose();
super.dispose();
}

Future<void> _refresh() async =>
await ref.read(studentClubViewModel).fetchStudentClubs(true, context);

bool get _isFiltering => _search.text.trim().isNotEmpty || _hasWebsite;

bool _matches(StudentClub club) {
if (_hasWebsite && !club.hasLink) return false;
final query = _search.text.trim().toLowerCase();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small simplification: could we normalize the query once per filtering pass rather than once for every club? Also, the Expando caches the parsed text for searching, while the row and sheet still parse descriptions repeatedly through the extension getters. For this collection size, computing the description once per widget build may be sufficient; if we keep a broader cache, it would be nice to have one clear place where display/search text is prepared. No need for a larger state-management change here.

if (query.isEmpty) return true;
final text = _searchText[club] ??=
'${club.parsedName}\n${club.parsedDescription}'.toLowerCase();
return text.contains(query);
}

void _clearFilters() => setState(() {
_search.clear();
_hasWebsite = false;
_category = null;
});

void _pickCategory(
List<({String title, List<StudentClub> clubs})> categories,
String? selected,
) => showModalBottomSheet<void>(
context: context,
showDragHandle: true,
isScrollControlled: true,
useSafeArea: true,
builder: (context) {
Widget option(String? title, String label, int count) => ListTile(
selected: title == selected,
leading: Icon(title == selected ? Icons.check : null),
title: Text(label),
trailing: Text('$count'),
onTap: () {
setState(() => _category = title);
Navigator.pop(context);
},
);
return ListView(
shrinkWrap: true,
padding: const EdgeInsets.only(bottom: 16),
children: [
Padding(
padding: const EdgeInsets.fromLTRB(24, 0, 24, 8),
child: Text(
context.tr('studentClubCategories'),
style: Theme.of(context).textTheme.titleLarge,
),
),
option(
null,
context.tr('studentClubAllCategories'),
categories.fold(0, (sum, category) => sum + category.clubs.length),
),
for (final category in categories)
option(category.title, category.title, category.clubs.length),
],
);
},
);

Widget _header(
List<({String title, List<StudentClub> clubs})> categories,
String? selected,
) {
// The app's chip theme only colours the label, so icons follow it.
final onChip = ChipTheme.of(context).labelStyle?.color;
return Padding(
padding: const EdgeInsets.fromLTRB(16, 8, 16, 0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
TextField(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would Flutter's SearchBar work here instead of styling a TextField as a search bar? It seems like a good fit for filtering the existing list and would let us use the standard search styling/theming. I think keeping the controller and filtering state local to this screen is appropriate; we wouldn't need a SearchAnchor or the app's global-search view model. This is a consistency suggestion rather than a functional concern.

controller: _search,
onChanged: (_) => setState(() {}),
onTapOutside: (_) => FocusScope.of(context).unfocus(),
textInputAction: TextInputAction.search,
decoration: InputDecoration(
hintText: context.tr('studentClubSearch'),
prefixIcon: const Icon(Icons.search),
suffixIcon: _search.text.isEmpty
? null
: IconButton(
onPressed: () => setState(_search.clear),
tooltip: MaterialLocalizations.of(context)
.deleteButtonTooltip,
icon: const Icon(Icons.clear),
),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(28),
),
isDense: true,
),
),
const SizedBox(height: 8),
Row(
children: [
Flexible(
child: FilterChip(
label: Row(
mainAxisSize: MainAxisSize.min,
children: [
Flexible(
child: Text(
selected ?? context.tr('studentClubAllCategories'),
overflow: TextOverflow.ellipsis,
),
),
Icon(Icons.arrow_drop_down, size: 18, color: onChip),
],
),
selected: selected != null,
onSelected: (_) => _pickCategory(categories, selected),
),
),
const SizedBox(width: 8),
// Leaves at least half the row to the category on narrow screens.
ConstrainedBox(
constraints: BoxConstraints(
maxWidth: MediaQuery.sizeOf(context).width / 2,
),
child: FilterChip(
avatar: Icon(Icons.link, color: onChip),
label: Text(
context.tr('studentClubHasWebsite'),
overflow: TextOverflow.ellipsis,
),
selected: _hasWebsite,
onSelected: (value) => setState(() => _hasWebsite = value),
),
),
],
),
],
),
);
}

@override
Widget build(BuildContext context) => StreamBuilder(
stream: ref.watch(studentClubViewModel).collections,
builder: (context, snapshot) {
final collections = snapshot.data ?? [];
Widget collection(int? index) {
final items = index == null ? null : collections[index].clubs;
return CampusCollectionView(
final categories = [
for (final collection in collections)
(
title: collection.parsedTitle,
clubs: collection.clubs.where(_matches).toList(),
),
];
final selected = categories
.where((category) => category.title == _category)
.firstOrNull;
final sections = [
for (final category in selected == null ? categories : [selected])
CampusCollectionSection(
title: category.title,
trailing: '${category.clubs.length}',
itemCount: category.clubs.length,
itemBuilder: (context, index) =>
StudentClubListTile(studentClub: category.clubs[index]),
),
];

return Scaffold(
appBar: AppBar(
title: Text(context.tr('studentClubs')),
actions: [
IconButton(
onPressed: _refresh,
tooltip: context.tr('refresh'),
icon: const Icon(Icons.refresh),
),
IconButton(
onPressed: () => UrlLauncher.urlString(
context.locale.languageCode == 'de'
? 'https://www.sv.tum.de/sv/hochschulgruppen/'
: 'https://www.sv.tum.de/en/sv/student-groups/',
ref,
),
tooltip: context.tr('openWebsite'),
icon: const Icon(Icons.open_in_new),
),
],
),
body: CampusCollectionView(
label: context.tr('studentClubs'),
icon: Icons.groups_outlined,
storageKey: index == null
? 'clubs-empty'
: 'clubs-${collections[index].parsedTitle}',
storageKey: 'clubs-${selected?.title ?? 'all'}',
onRefresh: _refresh,
hasData: snapshot.hasData,
error: snapshot.error,
stackTrace: snapshot.stackTrace,

itemCount: items?.length ?? 0,
minimumCardWidth: 160,
cardAspectRatio: 1,
cardHeight: StudentClubCardView.heightFor(context),
itemBuilder: (context, index) =>
StudentClubCardView(studentClub: items![index]),
);
}

return DefaultTabController(
length: collections.length,
child: Scaffold(
appBar: AppBar(
title: Text(context.tr('studentClubs')),
actions: [
IconButton(
onPressed: _refresh,
tooltip: context.tr('refresh'),
icon: const Icon(Icons.refresh),
),
IconButton(
onPressed: () => UrlLauncher.urlString(
context.locale.languageCode == 'de'
? 'https://www.sv.tum.de/sv/hochschulgruppen/'
: 'https://www.sv.tum.de/en/sv/student-groups/',
ref,
),
tooltip: context.tr('openWebsite'),
icon: const Icon(Icons.open_in_new),
),
],
bottom: collections.isEmpty
? null
: TabBar(
isScrollable: true,
tabAlignment: TabAlignment.start,
tabs: [
for (final collection in collections)
Tab(text: collection.parsedTitle),
],
),
),
body: collections.isEmpty
? collection(null)
: TabBarView(
children: [
for (var index = 0; index < collections.length; index++)
collection(index),
],
),
sections: sections,
header: collections.isEmpty
? null
: _header(categories, selected?.title),
emptyMessage: _isFiltering
? context.tr('studentClubNoMatches')
: null,
emptyAction: _isFiltering
? TextButton.icon(
onPressed: _clearFilters,
icon: const Icon(Icons.filter_alt_off_outlined),
label: Text(context.tr('studentClubClearFilters')),
)
: null,
minimumCardWidth: 340,
),
);
},
Expand Down
Loading
Loading