Skip to content

Commit 76079d8

Browse files
committed
chore: display time
1 parent 4f9470b commit 76079d8

File tree

25 files changed

+533
-153
lines changed

25 files changed

+533
-153
lines changed

frontend/app_flowy/lib/workspace/application/grid/cell/cell_service/context_builder.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
part of 'cell_service.dart';
22

33
typedef GridCellContext = _GridCellContext<Cell, String>;
4-
typedef GridSelectOptionCellContext = _GridCellContext<SelectOptionContext, String>;
5-
typedef GridDateCellContext = _GridCellContext<Cell, DateCellPersistenceData>;
4+
typedef GridSelectOptionCellContext = _GridCellContext<SelectOptionCellData, String>;
5+
typedef GridDateCellContext = _GridCellContext<DateCellData, DateCellPersistenceData>;
66

77
class GridCellContextBuilder {
88
final GridCellCache _cellCache;
@@ -26,7 +26,7 @@ class GridCellContextBuilder {
2626
return GridDateCellContext(
2727
gridCell: _gridCell,
2828
cellCache: _cellCache,
29-
cellDataLoader: CellDataLoader(gridCell: _gridCell),
29+
cellDataLoader: DateCellDataLoader(gridCell: _gridCell),
3030
cellDataPersistence: NumberCellDataPersistence(gridCell: _gridCell),
3131
);
3232
case FieldType.Number:
@@ -154,8 +154,8 @@ class _GridCellContext<T, D> extends Equatable {
154154
return _fieldService.getTypeOptionData(fieldType: fieldType);
155155
}
156156

157-
void saveCellData(D data) {
158-
cellDataPersistence.save(data);
157+
Future<Option<FlowyError>> saveCellData(D data) {
158+
return cellDataPersistence.save(data);
159159
}
160160

161161
void _loadData() {

frontend/app_flowy/lib/workspace/application/grid/cell/cell_service/data_loader.dart

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,42 @@ class CellDataLoader extends _GridCellDataLoader<Cell> {
5959
GridCellDataConfig get config => _config;
6060
}
6161

62-
class SelectOptionCellDataLoader extends _GridCellDataLoader<SelectOptionContext> {
62+
class DateCellDataLoader extends _GridCellDataLoader<DateCellData> {
63+
final GridCell gridCell;
64+
DateCellDataLoader({
65+
required this.gridCell,
66+
});
67+
68+
@override
69+
GridCellDataConfig get config => DefaultCellDataConfig();
70+
71+
@override
72+
Future<DateCellData?> loadData() {
73+
final payload = CellIdentifierPayload.create()
74+
..gridId = gridCell.gridId
75+
..fieldId = gridCell.field.id
76+
..rowId = gridCell.rowId;
77+
78+
return GridEventGetDateCellData(payload).send().then((result) {
79+
return result.fold(
80+
(data) => data,
81+
(err) {
82+
Log.error(err);
83+
return null;
84+
},
85+
);
86+
});
87+
}
88+
}
89+
90+
class SelectOptionCellDataLoader extends _GridCellDataLoader<SelectOptionCellData> {
6391
final SelectOptionService service;
6492
final GridCell gridCell;
6593
SelectOptionCellDataLoader({
6694
required this.gridCell,
6795
}) : service = SelectOptionService(gridCell: gridCell);
6896
@override
69-
Future<SelectOptionContext?> loadData() async {
97+
Future<SelectOptionCellData?> loadData() async {
7098
return service.getOpitonContext().then((result) {
7199
return result.fold(
72100
(data) => data,

frontend/app_flowy/lib/workspace/application/grid/cell/cell_service/data_persistence.dart

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
part of 'cell_service.dart';
22

33
abstract class _GridCellDataPersistence<D> {
4-
void save(D data);
4+
Future<Option<FlowyError>> save(D data);
55
}
66

77
class CellDataPersistence implements _GridCellDataPersistence<String> {
@@ -13,16 +13,19 @@ class CellDataPersistence implements _GridCellDataPersistence<String> {
1313
final CellService _cellService = CellService();
1414

1515
@override
16-
void save(String data) {
17-
_cellService
18-
.updateCell(
16+
Future<Option<FlowyError>> save(String data) async {
17+
final fut = _cellService.updateCell(
1918
gridId: gridCell.gridId,
2019
fieldId: gridCell.field.id,
2120
rowId: gridCell.rowId,
2221
data: data,
23-
)
24-
.then((result) {
25-
result.fold((l) => null, (err) => Log.error(err));
22+
);
23+
24+
return fut.then((result) {
25+
return result.fold(
26+
(l) => none(),
27+
(err) => Some(err),
28+
);
2629
});
2730
}
2831
}
@@ -39,7 +42,7 @@ class NumberCellDataPersistence implements _GridCellDataPersistence<DateCellPers
3942
});
4043

4144
@override
42-
void save(DateCellPersistenceData data) {
45+
Future<Option<FlowyError>> save(DateCellPersistenceData data) {
4346
var payload = DateChangesetPayload.create()..cellIdentifier = _cellIdentifier(gridCell);
4447

4548
final date = (data.date.millisecondsSinceEpoch ~/ 1000).toString();
@@ -49,8 +52,11 @@ class NumberCellDataPersistence implements _GridCellDataPersistence<DateCellPers
4952
payload.time = data.time!;
5053
}
5154

52-
GridEventUpdateDateCell(payload).send().then((result) {
53-
result.fold((l) => null, (err) => Log.error(err));
55+
return GridEventUpdateDateCell(payload).send().then((result) {
56+
return result.fold(
57+
(l) => none(),
58+
(err) => Some(err),
59+
);
5460
});
5561
}
5662
}

frontend/app_flowy/lib/workspace/application/grid/cell/date_cal_bloc.dart

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import 'package:app_flowy/workspace/application/grid/field/field_service.dart';
22
import 'package:flowy_sdk/log.dart';
33
import 'package:flowy_sdk/protobuf/flowy-error/errors.pb.dart';
4-
import 'package:flowy_sdk/protobuf/flowy-grid-data-model/grid.pb.dart' show Cell;
54
import 'package:flowy_sdk/protobuf/flowy-grid/date_type_option.pb.dart';
65
import 'package:flutter_bloc/flutter_bloc.dart';
76
import 'package:freezed_annotation/freezed_annotation.dart';
@@ -10,6 +9,7 @@ import 'dart:async';
109
import 'cell_service/cell_service.dart';
1110
import 'package:dartz/dartz.dart';
1211
import 'package:protobuf/protobuf.dart';
12+
import 'package:fixnum/fixnum.dart' as $fixnum;
1313
part 'date_cal_bloc.freezed.dart';
1414

1515
class DateCalBloc extends Bloc<DateCalEvent, DateCalState> {
@@ -18,9 +18,9 @@ class DateCalBloc extends Bloc<DateCalEvent, DateCalState> {
1818

1919
DateCalBloc({
2020
required DateTypeOption dateTypeOption,
21-
required DateTime? selectedDay,
21+
required DateCellData? cellData,
2222
required this.cellContext,
23-
}) : super(DateCalState.initial(dateTypeOption, selectedDay)) {
23+
}) : super(DateCalState.initial(dateTypeOption, cellData)) {
2424
on<DateCalEvent>(
2525
(event, emit) async {
2626
await event.when(
@@ -142,7 +142,7 @@ class DateCalEvent with _$DateCalEvent {
142142
const factory DateCalEvent.setDateFormat(DateFormat dateFormat) = _DateFormat;
143143
const factory DateCalEvent.setIncludeTime(bool includeTime) = _IncludeTime;
144144
const factory DateCalEvent.setTime(String time) = _Time;
145-
const factory DateCalEvent.didReceiveCellUpdate(Cell cell) = _DidReceiveCellUpdate;
145+
const factory DateCalEvent.didReceiveCellUpdate(DateCellData data) = _DidReceiveCellUpdate;
146146
}
147147

148148
@freezed
@@ -158,10 +158,13 @@ class DateCalState with _$DateCalState {
158158

159159
factory DateCalState.initial(
160160
DateTypeOption dateTypeOption,
161-
DateTime? selectedDay,
161+
DateCellData? cellData,
162162
) {
163163
Option<DateCellPersistenceData> dateData = none();
164-
if (selectedDay != null) {
164+
final time = cellData?.time ?? "";
165+
if (cellData != null) {
166+
final timestamp = $fixnum.Int64.parseInt(cellData.date).toInt();
167+
final selectedDay = DateTime.fromMillisecondsSinceEpoch(timestamp * 1000);
165168
dateData = Some(DateCellPersistenceData(date: selectedDay));
166169
}
167170

@@ -170,7 +173,7 @@ class DateCalState with _$DateCalState {
170173
format: CalendarFormat.month,
171174
focusedDay: DateTime.now(),
172175
dateData: dateData,
173-
time: "",
176+
time: time,
174177
inputTimeError: none(),
175178
);
176179
}

frontend/app_flowy/lib/workspace/application/grid/cell/date_cell_bloc.dart

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
import 'package:flowy_sdk/protobuf/flowy-grid-data-model/grid.pb.dart' show Cell, Field;
1+
import 'package:flowy_sdk/protobuf/flowy-grid-data-model/grid.pb.dart' show Field;
2+
import 'package:flowy_sdk/protobuf/flowy-grid/date_type_option.pb.dart';
23
import 'package:flutter_bloc/flutter_bloc.dart';
34
import 'package:freezed_annotation/freezed_annotation.dart';
45
import 'dart:async';
56
import 'cell_service/cell_service.dart';
7+
import 'package:dartz/dartz.dart';
68
part 'date_cell_bloc.freezed.dart';
79

810
class DateCellBloc extends Bloc<DateCellEvent, DateCellState> {
@@ -15,7 +17,7 @@ class DateCellBloc extends Bloc<DateCellEvent, DateCellState> {
1517
event.when(
1618
initial: () => _startListening(),
1719
selectDate: (DateCellPersistenceData value) => cellContext.saveCellData(value),
18-
didReceiveCellUpdate: (Cell value) => emit(state.copyWith(content: value.content)),
20+
didReceiveCellUpdate: (DateCellData value) => emit(state.copyWith(data: Some(value))),
1921
didReceiveFieldUpdate: (Field value) => emit(state.copyWith(field: value)),
2022
);
2123
},
@@ -34,9 +36,9 @@ class DateCellBloc extends Bloc<DateCellEvent, DateCellState> {
3436

3537
void _startListening() {
3638
_onCellChangedFn = cellContext.startListening(
37-
onCellChanged: ((cell) {
39+
onCellChanged: ((data) {
3840
if (!isClosed) {
39-
add(DateCellEvent.didReceiveCellUpdate(cell));
41+
add(DateCellEvent.didReceiveCellUpdate(data));
4042
}
4143
}),
4244
);
@@ -47,19 +49,28 @@ class DateCellBloc extends Bloc<DateCellEvent, DateCellState> {
4749
class DateCellEvent with _$DateCellEvent {
4850
const factory DateCellEvent.initial() = _InitialCell;
4951
const factory DateCellEvent.selectDate(DateCellPersistenceData data) = _SelectDay;
50-
const factory DateCellEvent.didReceiveCellUpdate(Cell cell) = _DidReceiveCellUpdate;
52+
const factory DateCellEvent.didReceiveCellUpdate(DateCellData data) = _DidReceiveCellUpdate;
5153
const factory DateCellEvent.didReceiveFieldUpdate(Field field) = _DidReceiveFieldUpdate;
5254
}
5355

5456
@freezed
5557
class DateCellState with _$DateCellState {
5658
const factory DateCellState({
57-
required String content,
59+
required Option<DateCellData> data,
5860
required Field field,
5961
}) = _DateCellState;
6062

61-
factory DateCellState.initial(GridDateCellContext context) => DateCellState(
62-
field: context.field,
63-
content: context.getCellData()?.content ?? "",
64-
);
63+
factory DateCellState.initial(GridDateCellContext context) {
64+
final cellData = context.getCellData();
65+
Option<DateCellData> data = none();
66+
67+
if (cellData != null) {
68+
data = Some(cellData);
69+
}
70+
71+
return DateCellState(
72+
field: context.field,
73+
data: data,
74+
);
75+
}
6576
}

frontend/app_flowy/lib/workspace/application/grid/cell/select_option_service.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,13 @@ class SelectOptionService {
5353
return GridEventUpdateSelectOption(payload).send();
5454
}
5555

56-
Future<Either<SelectOptionContext, FlowyError>> getOpitonContext() {
56+
Future<Either<SelectOptionCellData, FlowyError>> getOpitonContext() {
5757
final payload = CellIdentifierPayload.create()
5858
..gridId = gridId
5959
..fieldId = fieldId
6060
..rowId = rowId;
6161

62-
return GridEventGetSelectOptionContext(payload).send();
62+
return GridEventGetSelectOptionCellData(payload).send();
6363
}
6464

6565
Future<Either<void, FlowyError>> select({required String optionId}) {

frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/date_cell/calendar.dart

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import 'package:flutter/material.dart';
1616
import 'package:flutter_bloc/flutter_bloc.dart';
1717
import 'package:table_calendar/table_calendar.dart';
1818
import 'package:app_flowy/workspace/application/grid/prelude.dart';
19-
import 'package:fixnum/fixnum.dart' as $fixnum;
2019

2120
final kToday = DateTime.now();
2221
final kFirstDay = DateTime(kToday.year, kToday.month - 3, kToday.day);
@@ -41,19 +40,18 @@ class CellCalendar with FlowyOverlayDelegate {
4140
result.fold(
4241
(data) {
4342
final typeOptionData = DateTypeOption.fromBuffer(data);
44-
DateTime? selectedDay;
45-
final cellData = cellContext.getCellData()?.data;
43+
// DateTime? selectedDay;
44+
// final cellData = cellContext.getCellData();
4645

47-
if (cellData != null) {
48-
final timestamp = $fixnum.Int64.parseInt(cellData).toInt();
49-
selectedDay = DateTime.fromMillisecondsSinceEpoch(timestamp * 1000);
50-
}
46+
// if (cellData != null) {
47+
// final timestamp = $fixnum.Int64.parseInt(cellData).toInt();
48+
// selectedDay = DateTime.fromMillisecondsSinceEpoch(timestamp * 1000);
49+
// }
5150

5251
final calendar = _CellCalendarWidget(
5352
onSelected: onSelected,
5453
cellContext: cellContext,
5554
dateTypeOption: typeOptionData,
56-
selectedDay: selectedDay,
5755
);
5856

5957
FlowyOverlay.of(context).insertWithAnchor(
@@ -90,26 +88,26 @@ class CellCalendar with FlowyOverlayDelegate {
9088
class _CellCalendarWidget extends StatelessWidget {
9189
final GridDateCellContext cellContext;
9290
final DateTypeOption dateTypeOption;
93-
final DateTime? selectedDay;
9491
final void Function(DateCellPersistenceData) onSelected;
9592

9693
const _CellCalendarWidget({
9794
required this.onSelected,
9895
required this.cellContext,
9996
required this.dateTypeOption,
100-
this.selectedDay,
10197
Key? key,
10298
}) : super(key: key);
10399

104100
@override
105101
Widget build(BuildContext context) {
106102
final theme = context.watch<AppTheme>();
107103
return BlocProvider(
108-
create: (context) => DateCalBloc(
109-
dateTypeOption: dateTypeOption,
110-
selectedDay: selectedDay,
111-
cellContext: cellContext,
112-
)..add(const DateCalEvent.initial()),
104+
create: (context) {
105+
return DateCalBloc(
106+
dateTypeOption: dateTypeOption,
107+
cellData: cellContext.getCellData(),
108+
cellContext: cellContext,
109+
)..add(const DateCalEvent.initial());
110+
},
113111
child: BlocConsumer<DateCalBloc, DateCalState>(
114112
listener: (context, state) {
115113
state.dateData.fold(

frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/date_cell/date_cell.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,10 @@ class _DateCellState extends State<DateCell> {
6262
child: MouseRegion(
6363
opaque: false,
6464
cursor: SystemMouseCursors.click,
65-
child: Align(alignment: alignment, child: FlowyText.medium(state.content, fontSize: 12)),
65+
child: Align(
66+
alignment: alignment,
67+
child: FlowyText.medium(state.data.foldRight("", (data, _) => data.date), fontSize: 12),
68+
),
6669
),
6770
),
6871
);

0 commit comments

Comments
 (0)