Skip to content

Commit

Permalink
Add English Support to Student Clubs (#278)
Browse files Browse the repository at this point in the history
  • Loading branch information
jakobkoerber authored Sep 25, 2024
1 parent b1fb13e commit d9047ec
Show file tree
Hide file tree
Showing 10 changed files with 131 additions and 33 deletions.
38 changes: 37 additions & 1 deletion lib/base/networking/apis/tumdev/campus_backend.pb.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4350,12 +4350,21 @@ class GetCanteenHeadCountReply extends $pb.GeneratedMessage {
}

class ListStudentClubRequest extends $pb.GeneratedMessage {
factory ListStudentClubRequest() => create();
factory ListStudentClubRequest({
Language? language,
}) {
final $result = create();
if (language != null) {
$result.language = language;
}
return $result;
}
ListStudentClubRequest._() : super();
factory ListStudentClubRequest.fromBuffer($core.List<$core.int> i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromBuffer(i, r);
factory ListStudentClubRequest.fromJson($core.String i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromJson(i, r);

static final $pb.BuilderInfo _i = $pb.BuilderInfo(_omitMessageNames ? '' : 'ListStudentClubRequest', package: const $pb.PackageName(_omitMessageNames ? '' : 'api'), createEmptyInstance: create)
..e<Language>(1, _omitFieldNames ? '' : 'language', $pb.PbFieldType.OE, defaultOrMaker: Language.German, valueOf: Language.valueOf, enumValues: Language.values)
..hasRequiredFields = false
;

Expand All @@ -4379,6 +4388,17 @@ class ListStudentClubRequest extends $pb.GeneratedMessage {
@$core.pragma('dart2js:noInline')
static ListStudentClubRequest getDefault() => _defaultInstance ??= $pb.GeneratedMessage.$_defaultFor<ListStudentClubRequest>(create);
static ListStudentClubRequest? _defaultInstance;

/// Language of the student clubs and categories
/// Defaults to german
@$pb.TagNumber(1)
Language get language => $_getN(0);
@$pb.TagNumber(1)
set language(Language v) { setField(1, v); }
@$pb.TagNumber(1)
$core.bool hasLanguage() => $_has(0);
@$pb.TagNumber(1)
void clearLanguage() => clearField(1);
}

class ListStudentClubReply extends $pb.GeneratedMessage {
Expand Down Expand Up @@ -4526,6 +4546,7 @@ class StudentClubCollection extends $pb.GeneratedMessage {
$core.String? title,
$core.String? description,
$core.Iterable<StudentClub>? clubs,
$fixnum.Int64? unstableCollectionId,
}) {
final $result = create();
if (title != null) {
Expand All @@ -4537,6 +4558,9 @@ class StudentClubCollection extends $pb.GeneratedMessage {
if (clubs != null) {
$result.clubs.addAll(clubs);
}
if (unstableCollectionId != null) {
$result.unstableCollectionId = unstableCollectionId;
}
return $result;
}
StudentClubCollection._() : super();
Expand All @@ -4547,6 +4571,7 @@ class StudentClubCollection extends $pb.GeneratedMessage {
..aOS(1, _omitFieldNames ? '' : 'title')
..aOS(2, _omitFieldNames ? '' : 'description')
..pc<StudentClub>(3, _omitFieldNames ? '' : 'clubs', $pb.PbFieldType.PM, subBuilder: StudentClub.create)
..a<$fixnum.Int64>(4, _omitFieldNames ? '' : 'unstableCollectionId', $pb.PbFieldType.OU6, defaultOrMaker: $fixnum.Int64.ZERO)
..hasRequiredFields = false
;

Expand Down Expand Up @@ -4591,6 +4616,17 @@ class StudentClubCollection extends $pb.GeneratedMessage {

@$pb.TagNumber(3)
$core.List<StudentClub> get clubs => $_getList(2);

/// id of the collection.
/// Might not be stable over time because of scraping
@$pb.TagNumber(4)
$fixnum.Int64 get unstableCollectionId => $_getI64(3);
@$pb.TagNumber(4)
set unstableCollectionId($fixnum.Int64 v) { $_setInt64(3, v); }
@$pb.TagNumber(4)
$core.bool hasUnstableCollectionId() => $_has(3);
@$pb.TagNumber(4)
void clearUnstableCollectionId() => clearField(4);
}


Expand Down
15 changes: 15 additions & 0 deletions lib/base/networking/apis/tumdev/campus_backend.pbenum.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,21 @@ class DeviceType extends $pb.ProtobufEnum {
const DeviceType._($core.int v, $core.String n) : super(v, n);
}

class Language extends $pb.ProtobufEnum {
static const Language German = Language._(0, _omitEnumNames ? '' : 'German');
static const Language English = Language._(1, _omitEnumNames ? '' : 'English');

static const $core.List<Language> values = <Language> [
German,
English,
];

static final $core.Map<$core.int, Language> _byValue = $pb.ProtobufEnum.initByValue(values);
static Language? valueOf($core.int value) => _byValue[value];

const Language._($core.int v, $core.String n) : super(v, n);
}

class CreateFeedbackRequest_Recipient extends $pb.ProtobufEnum {
static const CreateFeedbackRequest_Recipient TUM_DEV = CreateFeedbackRequest_Recipient._(0, _omitEnumNames ? '' : 'TUM_DEV');
static const CreateFeedbackRequest_Recipient TUM_CONTACT = CreateFeedbackRequest_Recipient._(1, _omitEnumNames ? '' : 'TUM_CONTACT');
Expand Down
26 changes: 24 additions & 2 deletions lib/base/networking/apis/tumdev/campus_backend.pbjson.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,19 @@ const DeviceType$json = {
final $typed_data.Uint8List deviceTypeDescriptor = $convert.base64Decode(
'CgpEZXZpY2VUeXBlEgcKA0lPUxAAEgsKB0FORFJPSUQQARILCgdXSU5ET1dTEAI=');

@$core.Deprecated('Use languageDescriptor instead')
const Language$json = {
'1': 'Language',
'2': [
{'1': 'German', '2': 0},
{'1': 'English', '2': 1},
],
};

/// Descriptor for `Language`. Decode as a `google.protobuf.EnumDescriptorProto`.
final $typed_data.Uint8List languageDescriptor = $convert.base64Decode(
'CghMYW5ndWFnZRIKCgZHZXJtYW4QABILCgdFbmdsaXNoEAE=');

@$core.Deprecated('Use createDeviceRequestDescriptor instead')
const CreateDeviceRequest$json = {
'1': 'CreateDeviceRequest',
Expand Down Expand Up @@ -913,11 +926,18 @@ final $typed_data.Uint8List getCanteenHeadCountReplyDescriptor = $convert.base64
@$core.Deprecated('Use listStudentClubRequestDescriptor instead')
const ListStudentClubRequest$json = {
'1': 'ListStudentClubRequest',
'2': [
{'1': 'language', '3': 1, '4': 1, '5': 14, '6': '.api.Language', '9': 0, '10': 'language', '17': true},
],
'8': [
{'1': '_language'},
],
};

/// Descriptor for `ListStudentClubRequest`. Decode as a `google.protobuf.DescriptorProto`.
final $typed_data.Uint8List listStudentClubRequestDescriptor = $convert.base64Decode(
'ChZMaXN0U3R1ZGVudENsdWJSZXF1ZXN0');
'ChZMaXN0U3R1ZGVudENsdWJSZXF1ZXN0Ei4KCGxhbmd1YWdlGAEgASgOMg0uYXBpLkxhbmd1YW'
'dlSABSCGxhbmd1YWdliAEBQgsKCV9sYW5ndWFnZQ==');

@$core.Deprecated('Use listStudentClubReplyDescriptor instead')
const ListStudentClubReply$json = {
Expand Down Expand Up @@ -962,12 +982,14 @@ const StudentClubCollection$json = {
{'1': 'title', '3': 1, '4': 1, '5': 9, '10': 'title'},
{'1': 'description', '3': 2, '4': 1, '5': 9, '10': 'description'},
{'1': 'clubs', '3': 3, '4': 3, '5': 11, '6': '.api.StudentClub', '10': 'clubs'},
{'1': 'unstable_collection_id', '3': 4, '4': 1, '5': 4, '10': 'unstableCollectionId'},
],
};

/// Descriptor for `StudentClubCollection`. Decode as a `google.protobuf.DescriptorProto`.
final $typed_data.Uint8List studentClubCollectionDescriptor = $convert.base64Decode(
'ChVTdHVkZW50Q2x1YkNvbGxlY3Rpb24SFAoFdGl0bGUYASABKAlSBXRpdGxlEiAKC2Rlc2NyaX'
'B0aW9uGAIgASgJUgtkZXNjcmlwdGlvbhImCgVjbHVicxgDIAMoCzIQLmFwaS5TdHVkZW50Q2x1'
'YlIFY2x1YnM=');
'YlIFY2x1YnMSNAoWdW5zdGFibGVfY29sbGVjdGlvbl9pZBgEIAEoBFIUdW5zdGFibGVDb2xsZW'
'N0aW9uSWQ=');

5 changes: 4 additions & 1 deletion lib/campusComponent/service/student_club_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@ import 'package:campus_flutter/main.dart';

class StudentClubService {
static Future<(DateTime?, List<StudentClubCollection>)> fetchStudentClubs(
Language? language,
bool forceRefresh,
) async {
final start = DateTime.now();
GrpcClient grpcClient = getIt<GrpcClient>();
final response = await grpcClient.listStudentClub(
ListStudentClubRequest(),
ListStudentClubRequest(
language: language,
),
);
return (start, response.collections);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'package:campus_flutter/base/enums/error_handling_view_type.dart';
import 'package:campus_flutter/base/errorHandling/error_handling_router.dart';
import 'package:campus_flutter/base/routing/routes.dart';
import 'package:campus_flutter/base/util/delayed_loading_indicator.dart';
import 'package:campus_flutter/base/util/url_launcher.dart';
Expand All @@ -20,10 +22,10 @@ class StudentClubWidgetView extends ConsumerStatefulWidget {

class _StudentClubWidgetViewState extends ConsumerState<StudentClubWidgetView> {
@override
void initState() {
ref.read(studentClubViewModel).fetchStudentClubs(false);
void didChangeDependencies() {
ref.read(studentClubViewModel).fetchStudentClubs(false, context);
ref.read(movieViewModel).fetch(false);
super.initState();
super.didChangeDependencies();
}

@override
Expand Down Expand Up @@ -77,9 +79,10 @@ class _StudentClubWidgetViewState extends ConsumerState<StudentClubWidgetView> {
),
);
} else if (snapshot.hasError) {
return const Card(
child: DelayedLoadingIndicator(
name: "Student Clubs",
return Card(
child: ErrorHandlingRouter(
error: Error(),
errorHandlingViewType: ErrorHandlingViewType.textOnly,
),
);
} else {
Expand Down
10 changes: 8 additions & 2 deletions lib/campusComponent/viewmodel/student_club_viewmodel.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import 'package:campus_flutter/base/networking/apis/tumdev/campus_backend.pb.dart';
import 'package:campus_flutter/campusComponent/service/student_club_service.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:rxdart/rxdart.dart';

Expand All @@ -11,8 +13,12 @@ class StudentClubViewModel {
final BehaviorSubject<List<StudentClub>?> suggestions =
BehaviorSubject.seeded(null);

Future fetchStudentClubs(bool forceRefresh) {
return StudentClubService.fetchStudentClubs(forceRefresh).then(
Future fetchStudentClubs(bool forceRefresh, BuildContext context) {
final currentLanguage = context.locale.languageCode == "de"
? Language.German
: Language.English;
return StudentClubService.fetchStudentClubs(currentLanguage, forceRefresh)
.then(
(value) {
collections.add(value.$2);
final studentClubs = value.$2.expand((e) => e.clubs).toList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class StudentClubSearchViewModel implements SearchViewModel<StudentClubSearch> {
required String query,
}) async {
if (studentClubData.isEmpty) {
return StudentClubService.fetchStudentClubs(forcedRefresh).then(
return StudentClubService.fetchStudentClubs(null, forcedRefresh).then(
(value) {
studentClubData = value.$2
.expand((e) => e.clubs)
Expand Down
15 changes: 14 additions & 1 deletion protos/tumdev/campus_backend.proto
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,17 @@ message GetCanteenHeadCountReply {
// A time stamp indicating how up to date the response is. Only valid in case percent != -1.
google.protobuf.Timestamp timestamp = 4;
}
message ListStudentClubRequest {}

enum Language {
German = 0;
English = 1;
}

message ListStudentClubRequest {
// Language of the student clubs and categories
// Defaults to german
optional Language language = 1;
}
message ListStudentClubReply {
repeated StudentClubCollection collections = 1;
}
Expand All @@ -582,4 +592,7 @@ message StudentClubCollection {
string title = 1;
string description = 2;
repeated StudentClub clubs = 3;
// id of the collection.
// Might not be stable over time because of scraping
uint64 unstable_collection_id = 4;
}
36 changes: 18 additions & 18 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -648,10 +648,10 @@ packages:
dependency: "direct main"
description:
name: get_it
sha256: d85128a5dae4ea777324730dc65edd9c9f43155c109d5cc0a69cab74139fbac1
sha256: ff97e5e7b2e82e63c82f5658c6ba2605ea831f0f7489b0d2fb255d817ec4eb5e
url: "https://pub.dev"
source: hosted
version: "7.7.0"
version: "8.0.0"
glob:
dependency: transitive
description:
Expand Down Expand Up @@ -696,10 +696,10 @@ packages:
dependency: transitive
description:
name: google_maps_flutter_android
sha256: "36e75af1d0bd4c7391eacdaedf9ca7632c5b9709c5ec618b04489b79ea2b3f82"
sha256: "10cf27bee8c560f8e69992b3a0f27ddf1d7acbea622ddb13ef3f587848a73f26"
url: "https://pub.dev"
source: hosted
version: "2.14.6"
version: "2.14.7"
google_maps_flutter_ios:
dependency: transitive
description:
Expand Down Expand Up @@ -1169,18 +1169,18 @@ packages:
dependency: "direct main"
description:
name: quick_actions
sha256: b17da113df7a7005977f64adfa58ccc49c829d3ccc6e8e770079a8c7fbf2da9e
sha256: "2c1d9a91f3218b4e987a7e1e95ba0415b7f48a2cb3ffacc027a1e3d3c117223f"
url: "https://pub.dev"
source: hosted
version: "1.0.7"
version: "1.0.8"
quick_actions_android:
dependency: transitive
description:
name: quick_actions_android
sha256: "54a581491b90ff2e1be94af84a40c05e806e232184bb32afa2df57b07c4d6882"
sha256: "6932eeb970c6f7aed60708faf0ecea7068af84ee642c3bf308a0629abe90399b"
url: "https://pub.dev"
source: hosted
version: "1.0.15"
version: "1.0.16"
quick_actions_ios:
dependency: transitive
description:
Expand Down Expand Up @@ -1462,34 +1462,34 @@ packages:
dependency: "direct main"
description:
name: syncfusion_flutter_calendar
sha256: c501e463e69ed6f69323ead6b3b47873e5f25d00ec481fe2429f9ebbac92271b
sha256: "992d51b58453362df5ef789f3ffc89ede1f52e6788fe71e342c2ef5c2a6b58eb"
url: "https://pub.dev"
source: hosted
version: "27.1.48"
version: "27.1.50"
syncfusion_flutter_charts:
dependency: "direct main"
description:
name: syncfusion_flutter_charts
sha256: cdc207291ad0caf34cb9e20caa8938ff65f67a413b3a86a14d3a7b341a772100
sha256: "68eac622c9ad73618ddddbb5b8185792f590258e7400cf1f606c97f892c4a724"
url: "https://pub.dev"
source: hosted
version: "27.1.48"
version: "27.1.50"
syncfusion_flutter_core:
dependency: "direct main"
description:
name: syncfusion_flutter_core
sha256: "4347f4d2f5d89461df2c53e6fbf53aef38c7f05ed79b0760d935fb1ec836213b"
sha256: efbc44bdef33bf8f469c5ac7830df9631972721e157021db14bd78cdb1047fe1
url: "https://pub.dev"
source: hosted
version: "27.1.48"
version: "27.1.50"
syncfusion_flutter_datepicker:
dependency: "direct main"
description:
name: syncfusion_flutter_datepicker
sha256: "239331a866e57794925d29f9a68af0f52b2d1942001588e11f49729de2c670b0"
sha256: c54e0f4a56e713f68b4bdcac36f23c68cf35f3b0a02f0a9abb230c42ab64b3c6
url: "https://pub.dev"
source: hosted
version: "27.1.48"
version: "27.1.50"
synchronized:
dependency: transitive
description:
Expand Down Expand Up @@ -1606,10 +1606,10 @@ packages:
dependency: transitive
description:
name: url_launcher_macos
sha256: "9a1a42d5d2d95400c795b2914c36fdcb525870c752569438e4ebb09a2b5d90de"
sha256: "769549c999acdb42b8bcfa7c43d72bf79a382ca7441ab18a808e101149daf672"
url: "https://pub.dev"
source: hosted
version: "3.2.0"
version: "3.2.1"
url_launcher_platform_interface:
dependency: transitive
description:
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ dependencies:
rxdart: ^0.28.0
go_router: ^14.0.1
flutter_riverpod: ^2.3.6
get_it: ^7.6.0
get_it: ^8.0.0

# user interface
shimmer: ^3.0.0
Expand Down

0 comments on commit d9047ec

Please sign in to comment.