Skip to content

Commit

Permalink
Merge pull request #466 from bannzai/add/function/edit_history
Browse files Browse the repository at this point in the history
Implement editing history
  • Loading branch information
bannzai authored Jan 8, 2022
2 parents 9620dfa + 84412ec commit 7e8d3a0
Show file tree
Hide file tree
Showing 13 changed files with 495 additions and 15 deletions.
17 changes: 17 additions & 0 deletions lib/domain/calendar/calendar_page_store.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import 'dart:async';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:pilll/domain/calendar/calendar_card_state.dart';
import 'package:pilll/domain/calendar/components/pill_sheet_modified_history/pill_sheet_modified_history_card.dart';
import 'package:pilll/entity/pill_sheet_modified_history.dart';
import 'package:pilll/entity/pill_sheet_modified_history_value.dart';
import 'package:pilll/service/diary.dart';
import 'package:pilll/service/menstruation.dart';
import 'package:pilll/service/pill_sheet_group.dart';
Expand Down Expand Up @@ -148,4 +150,19 @@ class CalendarPageStateStore extends StateNotifier<CalendarPageState> {
}

CalendarCardState cardState(DateTime date) => CalendarCardState(date);

Future<void> editTakenValue(
DateTime actualTakenDate,
PillSheetModifiedHistory history,
PillSheetModifiedHistoryValue value,
TakenPillValue takenPillValue,
) {
return updateForEditTakenValue(
service: _pillSheetModifiedHistoryService,
actualTakenDate: actualTakenDate,
history: history,
value: value,
takenPillValue: takenPillValue,
);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:pilll/analytics.dart';
import 'package:pilll/components/atoms/font.dart';
Expand All @@ -7,16 +6,24 @@ import 'package:pilll/domain/calendar/components/pill_sheet_modified_history/com
import 'package:pilll/domain/calendar/components/pill_sheet_modified_history/components/taken_pill_action_o_list.dart';
import 'package:pilll/entity/pill_sheet.dart';
import 'package:pilll/entity/pill_sheet_modified_history_value.dart';
import 'package:pilll/error/error_alert.dart';
import 'package:pilll/util/formatter/date_time_formatter.dart';
import 'package:pilll/util/toolbar/date_and_time_picker.dart';

class PillSheetModifiedHistoryTakenPillAction extends StatelessWidget {
final Future<void> Function(
DateTime actualTakenDate,
TakenPillValue value,
)? onEdit;

final DateTime estimatedEventCausingDate;
final TakenPillValue? value;
final PillSheet? beforePillSheet;
final PillSheet? afterPillSheet;

const PillSheetModifiedHistoryTakenPillAction({
Key? key,
required this.onEdit,
required this.estimatedEventCausingDate,
required this.value,
required this.beforePillSheet,
Expand All @@ -31,10 +38,48 @@ class PillSheetModifiedHistoryTakenPillAction extends StatelessWidget {
if (value == null || afterPillSheet == null || beforePillSheet == null) {
return Container();
}

final time = DateTimeFormatter.hourAndMinute(estimatedEventCausingDate);
return GestureDetector(
onTap: () {
analytics.logEvent(name: "tapped_history_taken_action");

final onEdit = this.onEdit;
if (onEdit != null) {
showModalBottomSheet(
context: context,
builder: (BuildContext context) {
return DateAndTimePicker(
initialDateTime: estimatedEventCausingDate,
done: (dateTime) async {
analytics.logEvent(
name: "selected_date_taken_history",
parameters: {
"hour": dateTime.hour,
"minute": dateTime.minute
});

try {
await onEdit(dateTime, value);
final date =
DateTimeFormatter.slashYearAndMonthAndDayAndTime(
dateTime);
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
duration: Duration(seconds: 2),
content: Text("$dateに変更しました"),
),
);
Navigator.pop(context);
} catch (error) {
showErrorAlert(context,
message: '更新に失敗しました。通信環境をお確かめの上、再度変更してください');
}
},
);
},
);
}
},
child: Container(
child: Padding(
Expand All @@ -59,6 +104,7 @@ class PillSheetModifiedHistoryTakenPillAction extends StatelessWidget {
child: Text(
time,
style: TextStyle(
decoration: TextDecoration.underline,
letterSpacing: 1.5,
color: TextColor.main,
fontSize: 15,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ class CalendarPillSheetModifiedHistoryCard extends StatelessWidget {
scrollPhysics: NeverScrollableScrollPhysics(),
pillSheetModifiedHistories:
state.pillSheetModifiedHistories,
onEditTakenPillAction: store.editTakenValue,
),
),
if (state.moreButtonIsShown)
Expand All @@ -115,6 +116,7 @@ class CalendarPillSheetModifiedHistoryCard extends StatelessWidget {
scrollPhysics: NeverScrollableScrollPhysics(),
pillSheetModifiedHistories:
state.pillSheetModifiedHistories,
onEditTakenPillAction: null,
),
),
Positioned.fill(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import 'package:pilll/domain/calendar/components/pill_sheet_modified_history/com
import 'package:pilll/domain/calendar/components/pill_sheet_modified_history/components/pill_sheet_modified_history_revert_taken_pill_action.dart';
import 'package:pilll/domain/calendar/components/pill_sheet_modified_history/components/pill_sheet_modified_history_taken_pill_action.dart';
import 'package:pilll/entity/pill_sheet_modified_history.dart';
import 'package:pilll/entity/pill_sheet_modified_history_value.dart';
import 'package:pilll/util/datetime/date_compare.dart';

class CalendarPillSheetModifiedHistoryListModel {
Expand All @@ -27,11 +28,19 @@ class CalendarPillSheetModifiedHistoryList extends StatelessWidget {
final ScrollPhysics scrollPhysics;
final List<PillSheetModifiedHistory> pillSheetModifiedHistories;

final Future<void> Function(
DateTime actualTakenDate,
PillSheetModifiedHistory history,
PillSheetModifiedHistoryValue value,
TakenPillValue takenPillValue,
)? onEditTakenPillAction;

const CalendarPillSheetModifiedHistoryList({
Key? key,
required this.padding,
required this.scrollPhysics,
required this.pillSheetModifiedHistories,
required this.onEditTakenPillAction,
}) : super(key: key);

List<CalendarPillSheetModifiedHistoryListModel> get models {
Expand Down Expand Up @@ -116,6 +125,12 @@ class CalendarPillSheetModifiedHistoryList extends StatelessWidget {
);
case PillSheetModifiedActionType.takenPill:
return PillSheetModifiedHistoryTakenPillAction(
onEdit: onEditTakenPillAction == null
? null
: (actualDateTime, takenPillValue) {
return onEditTakenPillAction!(actualDateTime,
history, history.value, takenPillValue);
},
estimatedEventCausingDate:
history.estimatedEventCausingDate,
value: history.value.takenPill,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class PillSheetModifiedHistoriesPage extends HookConsumerWidget {
scrollPhysics: AlwaysScrollableScrollPhysics(),
pillSheetModifiedHistories:
state.pillSheetModifiedHistories,
onEditTakenPillAction: store.editTakenValue,
),
),
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@ import 'dart:async';
import 'dart:math';

import 'package:pilll/domain/pill_sheet_modified_history/pill_sheet_modified_history_state.dart';
import 'package:pilll/entity/pill_sheet_modified_history.dart';
import 'package:pilll/entity/pill_sheet_modified_history_value.dart';
import 'package:pilll/service/pill_sheet_modified_history.dart';
import 'package:riverpod/riverpod.dart';

final pillSheetModifiedHistoryStoreProvider = StateNotifierProvider.autoDispose<PillSheetModifiedHistoryStateStore, PillSheetModifiedHistoryState>(
final pillSheetModifiedHistoryStoreProvider = StateNotifierProvider.autoDispose<
PillSheetModifiedHistoryStateStore, PillSheetModifiedHistoryState>(
(ref) => PillSheetModifiedHistoryStateStore(
ref.watch(pillSheetModifiedHistoryServiceProvider),
),
Expand Down Expand Up @@ -65,4 +68,19 @@ class PillSheetModifiedHistoryStateStore
isLoading: false);
_subscribe();
}

Future<void> editTakenValue(
DateTime actualTakenDate,
PillSheetModifiedHistory history,
PillSheetModifiedHistoryValue value,
TakenPillValue takenPillValue,
) {
return updateForEditTakenValue(
service: _pillSheetModifiedHistoryService,
actualTakenDate: actualTakenDate,
history: history,
value: value,
takenPillValue: takenPillValue,
);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// coverage:ignore-file
// GENERATED CODE - DO NOT MODIFY BY HAND
// ignore_for_file: type=lint
// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target

part of 'premium_introduction_state.dart';
Expand Down
2 changes: 1 addition & 1 deletion lib/entity/pill_sheet_modified_history.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ part 'pill_sheet_modified_history.g.dart';
part 'pill_sheet_modified_history.freezed.dart';

class PillSheetModifiedHistoryFirestoreKeys {
static final createdAt = "createdAt";
static final estimatedEventCausingDate = "estimatedEventCausingDate";
}

enum PillSheetModifiedActionType {
Expand Down
28 changes: 28 additions & 0 deletions lib/entity/pill_sheet_modified_history_value.dart
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,40 @@ class TakenPillValue with _$TakenPillValue {
required DateTime afterLastTakenDate,
required int beforeLastTakenPillNumber,
required int afterLastTakenPillNumber,
TakenPillEditedValue? edited,
}) = _TakenPillValue;

factory TakenPillValue.fromJson(Map<String, dynamic> json) =>
_$TakenPillValueFromJson(json);
}

@freezed
class TakenPillEditedValue with _$TakenPillEditedValue {
@JsonSerializable(explicitToJson: true)
const factory TakenPillEditedValue({
@JsonKey(
fromJson: NonNullTimestampConverter.timestampToDateTime,
toJson: NonNullTimestampConverter.dateTimeToTimestamp,
)
required DateTime createdDate,
@JsonKey(
fromJson: NonNullTimestampConverter.timestampToDateTime,
toJson: NonNullTimestampConverter.dateTimeToTimestamp,
)
required DateTime actualTakenDate,
//
@JsonKey(
fromJson: NonNullTimestampConverter.timestampToDateTime,
toJson: NonNullTimestampConverter.dateTimeToTimestamp,
)
required DateTime historyRecordedDate,
}) = _TakenPillEditedValue;
const TakenPillEditedValue._();

factory TakenPillEditedValue.fromJson(Map<String, dynamic> json) =>
_$TakenPillEditedValueFromJson(json);
}

@freezed
class RevertTakenPillValue with _$RevertTakenPillValue {
const RevertTakenPillValue._();
Expand Down
Loading

0 comments on commit 7e8d3a0

Please sign in to comment.