Skip to content

Commit

Permalink
drop: Act v1
Browse files Browse the repository at this point in the history
wip replace: `Act`
wip drop: EntityV1

wip #377
  • Loading branch information
zin- committed Sep 7, 2024
1 parent 579e755 commit c56bd1c
Show file tree
Hide file tree
Showing 19 changed files with 105 additions and 160 deletions.
4 changes: 2 additions & 2 deletions lib/act_counter/act_counter.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import 'package:collection/collection.dart';
import 'package:mem/act_counter/home_widget.dart';

import 'package:mem/core/act.dart';
import 'package:mem/core/date_and_time/date_and_time.dart';
import 'package:mem/core/date_and_time/date_and_time_period.dart';
import 'package:mem/repositories/act_entity.dart';
import 'package:mem/repositories/mem.dart';

class ActCounter implements HomeWidget {
Expand All @@ -23,7 +23,7 @@ class ActCounter implements HomeWidget {

ActCounter(this.memId, this.name, this.actCount, this.updatedAt);

ActCounter.from(SavedMemV1 savedMem, Iterable<SavedAct> savedActs)
ActCounter.from(SavedMemV1 savedMem, Iterable<SavedActEntity> savedActs)
: memId = savedMem.id,
name = savedMem.name,
actCount = savedActs.length,
Expand Down
20 changes: 8 additions & 12 deletions lib/act_counter/act_counter_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,10 @@ class ActCounterClient {
await _actCounterRepository.receive(
ActCounterEntity.from(
await _memRepository.ship(id: memId).then((v) => v.single.toV1()),
await _actRepository
.ship(
memId: memId,
period: ActCounter.period(DateAndTime.now()),
)
.then((v) => v.map((e) => e.toV1())),
await _actRepository.ship(
memId: memId,
period: ActCounter.period(DateAndTime.now()),
),
),
);
},
Expand All @@ -47,12 +45,10 @@ class ActCounterClient {
await _actCounterRepository.replace(
ActCounterEntity.from(
await _memRepository.ship(id: memId).then((v) => v.single.toV1()),
await _actRepository
.ship(
memId: memId,
period: ActCounter.period(when),
)
.then((v) => v.map((e) => e.toV1())),
await _actRepository.ship(
memId: memId,
period: ActCounter.period(when),
),
),
);
},
Expand Down
34 changes: 14 additions & 20 deletions lib/acts/act_service.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'package:collection/collection.dart';
import 'package:mem/core/act.dart';
import 'package:mem/core/date_and_time/date_and_time.dart';
import 'package:mem/core/date_and_time/date_and_time_period.dart';
import 'package:mem/logger/log_service.dart';
Expand All @@ -16,7 +15,7 @@ class ListWithTotalCount<T> {
class ActService {
final ActRepository _actRepository;

Future<ListWithTotalCount<SavedAct>> fetch(
Future<ListWithTotalCount<SavedActEntity>> fetch(
int? memId,
int offset,
int limit,
Expand All @@ -29,7 +28,7 @@ class ActService {
offset: offset,
limit: limit,
))
.map((e) => e.toV1())
// .map((e) => e.toV1())
.toList(),
await _actRepository.count(memId: memId),
),
Expand All @@ -40,22 +39,21 @@ class ActService {
},
);

Future<SavedAct> start(
Future<SavedActEntity> start(
int memId,
DateAndTime when,
) =>
i(
() async => (await _actRepository.receive(
() async => await _actRepository.receive(
ActEntity(memId, DateAndTimePeriod(start: when)),
))
.toV1(),
),
{
'memId': memId,
'when': when,
},
);

Future<SavedAct> finish(
Future<SavedActEntity> finish(
int memId,
DateAndTime when,
) =>
Expand All @@ -69,23 +67,21 @@ class ActService {
.firstOrNull;

if (active == null) {
return (await _actRepository.receive(
return await _actRepository.receive(
ActEntity(
memId,
DateAndTimePeriod(
start: when,
end: when,
),
),
))
.toV1();
);
} else {
return (await _actRepository.replace(
return await _actRepository.replace(
active.copiedWith(
period: () => active.period.copiedWith(when),
),
))
.toV1();
);
}
},
{
Expand All @@ -94,17 +90,15 @@ class ActService {
},
);

Future<SavedAct> edit(SavedAct savedAct) => i(
() async =>
(await _actRepository.replace(SavedActEntity.fromV1(savedAct)))
.toV1(),
Future<SavedActEntity> edit(SavedActEntity savedAct) => i(
() async => await _actRepository.replace(savedAct),
{
'savedAct': savedAct,
},
);

Future<SavedAct> delete(int actId) => i(
() async => (await _actRepository.waste(id: actId)).single.toV1(),
Future<SavedActEntity> delete(int actId) => i(
() async => (await _actRepository.waste(id: actId)).single,
{
'actId': actId,
},
Expand Down
10 changes: 5 additions & 5 deletions lib/acts/actions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:mem/core/act.dart';
import 'package:mem/core/date_and_time/date_and_time.dart';
import 'package:mem/core/date_and_time/date_and_time_period.dart';
import 'package:mem/logger/log_service.dart';
import 'package:mem/repositories/act_entity.dart';
import 'package:mem/repositories/act_repository.dart';

import 'client.dart';
Expand All @@ -12,14 +13,13 @@ import 'states.dart';
final _actsClient = ActsClient();
final _actRepository = ActRepository();

final loadActList = FutureProvider.autoDispose.family<List<SavedAct>, int?>(
final loadActList =
FutureProvider.autoDispose.family<List<SavedActEntity>, int?>(
(ref, memId) => v(
() async {
// TODO 全件取得する場合、件数的な不安がある
// 1週間分とかにしとくか?
final acts = await _actRepository
.ship(memId: memId)
.then((value) => value.map((e) => e.toV1()).toList());
final acts = await _actRepository.ship(memId: memId);

ref.watch(actsProvider.notifier).upsertAll(
acts,
Expand Down Expand Up @@ -55,7 +55,7 @@ final startActBy = Provider.autoDispose.family<Act, int>(
),
);

final finishActBy = Provider.autoDispose.family<SavedAct, int>(
final finishActBy = Provider.autoDispose.family<SavedActEntity, int>(
(ref, memId) => v(
() {
final now = DateAndTime.now();
Expand Down
16 changes: 8 additions & 8 deletions lib/acts/client.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import 'package:mem/acts/act_service.dart';
import 'package:mem/core/act.dart';
import 'package:mem/core/date_and_time/date_and_time.dart';
import 'package:mem/logger/log_service.dart';
import 'package:mem/notifications/notification_client.dart';
import 'package:mem/repositories/act_entity.dart';

class ListWithTotalPage<T> {
final List<T> list;
Expand All @@ -16,7 +16,7 @@ class ActsClient {

final NotificationClient _notificationClient;

Future<ListWithTotalPage<SavedAct>> fetch(
Future<ListWithTotalPage<SavedActEntity>> fetch(
int? memId,
int page,
) =>
Expand All @@ -43,7 +43,7 @@ class ActsClient {
},
);

Future<SavedAct> start(
Future<SavedActEntity> start(
int memId,
DateAndTime when,
) =>
Expand All @@ -61,8 +61,8 @@ class ActsClient {
},
);

Future<SavedAct> edit(
SavedAct savedAct,
Future<SavedActEntity> edit(
SavedActEntity savedAct,
) =>
i(
() async {
Expand All @@ -81,7 +81,7 @@ class ActsClient {
},
);

Future pause(
Future<void> pause(
int memId,
DateAndTime when,
) =>
Expand All @@ -97,7 +97,7 @@ class ActsClient {
},
);

Future<SavedAct> finish(
Future<SavedActEntity> finish(
int memId,
DateAndTime when,
) =>
Expand All @@ -117,7 +117,7 @@ class ActsClient {
},
);

Future<SavedAct> delete(int actId) => i(
Future<SavedActEntity> delete(int actId) => i(
() async {
final deleted = await _actService.delete(actId);

Expand Down
8 changes: 3 additions & 5 deletions lib/acts/line_chart/line_chart_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,9 @@ class ActLineChartPage extends ConsumerWidget {
child: AsyncValueView(
loadActList(_memId),
(loaded) => LineChartWrapper(
ActsSummary(
ref
.watch(actListProvider(_memId))
.where((element) => element.memId == _memId),
),
ActsSummary(ref
.watch(actListProvider(_memId))
.where((element) => element.memId == _memId)),
),
),
),
Expand Down
2 changes: 1 addition & 1 deletion lib/acts/list/act_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class ActList extends ConsumerWidget {
_memId,
ref.watch(dateViewProvider),
ref.watch(timeViewProvider),
ref.watch(actListProvider(_memId)) ?? [],
ref.watch(actListProvider(_memId)),
(_memId == null ? ref.watch(memListProvider) : []),
_scrollController,
);
Expand Down
8 changes: 5 additions & 3 deletions lib/acts/list/add_act_fab.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:mem/acts/actions.dart';
import 'package:mem/acts/states.dart';
import 'package:mem/core/act.dart';
import 'package:mem/repositories/act_entity.dart';

class ActFab extends ConsumerWidget {
final int _memId;
Expand All @@ -19,14 +19,16 @@ class ActFab extends ConsumerWidget {
() => ref.read(actListProvider(_memId).notifier).upsertAll(
[ref.read(startActBy(_memId))],
(tmp, item) =>
tmp is SavedAct && item is SavedAct && tmp.id == item.id,
tmp is SavedActEntity &&
item is SavedActEntity &&
tmp.id == item.id,
),
);
} else {
return _FinishActFab(
() => ref.read(actListProvider(_memId).notifier).removeWhere(
(element) =>
element is SavedAct &&
element is SavedActEntity &&
element.id ==
ref.read(finishActBy(activeActList.last.memId)).id,
),
Expand Down
3 changes: 2 additions & 1 deletion lib/acts/list/item/builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:collection/collection.dart';
import 'package:flutter/material.dart';
import 'package:mem/core/act.dart';
import 'package:mem/logger/log_service.dart';
import 'package:mem/repositories/act_entity.dart';
import 'package:mem/repositories/mem.dart';

import 'total_act_time_item.dart';
Expand Down Expand Up @@ -36,7 +37,7 @@ class ActListItemBuilder {
);
} else {
final act = _actListWithDatetime.value[index];
if (act is SavedAct) {
if (act is SavedActEntity) {
return ActListItemView(
act,
_memList
Expand Down
10 changes: 6 additions & 4 deletions lib/acts/list/item/editing_act_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:mem/acts/states.dart';
import 'package:mem/components/date_and_time/date_and_time_period_view.dart';
import 'package:mem/core/act.dart';
import 'package:mem/core/date_and_time/date_and_time_period.dart';
import 'package:mem/logger/log_service.dart';
import 'package:mem/repositories/act_entity.dart';

import 'actions.dart';
import 'states.dart';
Expand All @@ -23,7 +23,7 @@ class EditingActDialog extends ConsumerWidget {
(pickedPeriod) => v(
() => ref.read(editingActProvider(_actId).notifier).updatedBy(
editingAct.copiedWith(
pickedPeriod == null ? null : () => pickedPeriod,
period: pickedPeriod == null ? null : () => pickedPeriod,
),
),
pickedPeriod,
Expand All @@ -33,14 +33,16 @@ class EditingActDialog extends ConsumerWidget {
() => ref.read(actListProvider(editingAct.memId).notifier).upsertAll(
[ref.read(editAct(_actId))],
(tmp, item) =>
tmp is SavedAct && item is SavedAct && tmp.id == item.id,
tmp is SavedActEntity &&
item is SavedActEntity &&
tmp.id == item.id,
)),
);
}
}

class _EditingActDialogComponent extends StatelessWidget {
final SavedAct _editingAct;
final SavedActEntity _editingAct;
final Function(DateAndTimePeriod? picked) _onPeriodChanged;
final Function() _onDeleteTapped;
final Function() _onSaveTapped;
Expand Down
4 changes: 2 additions & 2 deletions lib/acts/list/item/states.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:mem/acts/states.dart';
import 'package:mem/components/value_state_notifier.dart';
import 'package:mem/core/act.dart';
import 'package:mem/logger/log_service.dart';
import 'package:mem/repositories/act_entity.dart';

final editingActProvider = StateNotifierProvider.autoDispose
.family<ValueStateNotifier<SavedAct>, SavedAct, int>(
.family<ValueStateNotifier<SavedActEntity>, SavedActEntity, int>(
(ref, actId) => v(
() => ValueStateNotifier(
ref.read(actsProvider).singleWhere((act) => act.id == actId),
Expand Down
4 changes: 2 additions & 2 deletions lib/acts/list/item/view.dart
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import 'package:flutter/material.dart';
import 'package:mem/components/date_and_time/date_and_time_period_view.dart';
import 'package:mem/core/act.dart';
import 'package:mem/logger/log_service.dart';
import 'package:mem/repositories/act_entity.dart';

import 'editing_act_dialog.dart';

class ActListItemView extends StatelessWidget {
final SavedAct _act;
final SavedActEntity _act;

// Act一覧の要素に対してMemがあったら名前を表示するという実装は合っているだろうか?
final String? _memName;
Expand Down
Loading

0 comments on commit c56bd1c

Please sign in to comment.