.github
.vscode
android
assets
buildtools
ios
lib
database
models
pods
call.dart
call.freezed.dart
call.g.dart
chat_summary.dart
chat_summary.g.dart
config.dart
config.freezed.dart
config.g.dart
database.dart
event_calendar.dart
event_calendar.g.dart
message.dart
network.dart
theme.dart
userinfo.dart
websocket.dart
websocket.freezed.dart
websocket.g.dart
screens
services
widgets
firebase_options.dart
main.dart
route.dart
route.gr.dart
linux
macos
web
windows
.gitignore
.metadata
README.md
analysis_options.yaml
build.yaml
devtools_options.yaml
firebase.json
pubspec.lock
pubspec.yaml
56 lines
1.5 KiB
Dart
56 lines
1.5 KiB
Dart
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
|
import 'package:island/models/activity.dart';
|
|
import 'package:island/pods/network.dart';
|
|
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
|
|
|
part 'event_calendar.g.dart';
|
|
|
|
/// Query parameters for fetching event calendar data
|
|
class EventCalendarQuery {
|
|
/// Username to fetch calendar for, null means current user ('me')
|
|
final String? uname;
|
|
|
|
/// Year to fetch calendar for
|
|
final int year;
|
|
|
|
/// Month to fetch calendar for
|
|
final int month;
|
|
|
|
const EventCalendarQuery({
|
|
required this.uname,
|
|
required this.year,
|
|
required this.month,
|
|
});
|
|
|
|
@override
|
|
bool operator ==(Object other) =>
|
|
identical(this, other) ||
|
|
other is EventCalendarQuery &&
|
|
runtimeType == other.runtimeType &&
|
|
uname == other.uname &&
|
|
year == other.year &&
|
|
month == other.month;
|
|
|
|
@override
|
|
int get hashCode => uname.hashCode ^ year.hashCode ^ month.hashCode;
|
|
}
|
|
|
|
/// Provider for fetching event calendar data
|
|
/// This can be used anywhere in the app where calendar data is needed
|
|
@riverpod
|
|
Future<List<SnEventCalendarEntry>> eventCalendar(
|
|
Ref ref,
|
|
EventCalendarQuery query,
|
|
) async {
|
|
final client = ref.watch(apiClientProvider);
|
|
final resp = await client.get('/accounts/${query.uname ?? 'me'}/calendar',
|
|
queryParameters: {
|
|
'year': query.year,
|
|
'month': query.month,
|
|
},
|
|
);
|
|
return resp.data
|
|
.map((e) => SnEventCalendarEntry.fromJson(e))
|
|
.cast<SnEventCalendarEntry>()
|
|
.toList();
|
|
} |