feat(apps): refine login consent and calendar day/month UX
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
import 'package:social_app/core/api/i_api_client.dart';
|
||||
import 'package:social_app/core/cache/cache_invalidator.dart';
|
||||
import 'package:social_app/core/di/injection.dart';
|
||||
|
||||
import '../calendar_api.dart';
|
||||
import '../models/schedule_item_model.dart';
|
||||
@@ -37,11 +39,15 @@ class CalendarService {
|
||||
}
|
||||
|
||||
Future<ScheduleItemModel> addEvent(ScheduleItemModel event) async {
|
||||
return _api.create(event);
|
||||
final created = await _api.create(event);
|
||||
_invalidateEventCache(created);
|
||||
return created;
|
||||
}
|
||||
|
||||
Future<ScheduleItemModel> updateEvent(ScheduleItemModel event) async {
|
||||
return _api.update(event);
|
||||
final updated = await _api.update(event);
|
||||
_invalidateEventCache(updated);
|
||||
return updated;
|
||||
}
|
||||
|
||||
Future<ScheduleItemModel?> archiveEvent(String id) async {
|
||||
@@ -49,10 +55,38 @@ class CalendarService {
|
||||
if (event == null) {
|
||||
return null;
|
||||
}
|
||||
return updateEvent(event.copyWith(status: ScheduleStatus.archived));
|
||||
final updatedEvent = await updateEvent(
|
||||
event.copyWith(status: ScheduleStatus.archived),
|
||||
);
|
||||
_invalidateEventCache(updatedEvent);
|
||||
return updatedEvent;
|
||||
}
|
||||
|
||||
void _invalidateEventCache(ScheduleItemModel event) {
|
||||
try {
|
||||
final invalidator = sl<CacheInvalidator>();
|
||||
var current = DateTime(
|
||||
event.startAt.year,
|
||||
event.startAt.month,
|
||||
event.startAt.day,
|
||||
);
|
||||
final end = DateTime(
|
||||
event.endAt?.year ?? event.startAt.year,
|
||||
event.endAt?.month ?? event.startAt.month,
|
||||
event.endAt?.day ?? event.startAt.day,
|
||||
);
|
||||
while (!current.isAfter(end)) {
|
||||
invalidator.invalidateCalendarDay(current);
|
||||
current = current.add(const Duration(days: 1));
|
||||
}
|
||||
} catch (_) {}
|
||||
}
|
||||
|
||||
Future<void> deleteEvent(String id) async {
|
||||
final event = await getEventById(id);
|
||||
if (event != null) {
|
||||
_invalidateEventCache(event);
|
||||
}
|
||||
await _api.delete(id);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user