Merge pull request #862 from AppFlowy-IO/feat/open_card_detail

chore: open card detail
This commit is contained in:
Nathan.fooo 2022-08-16 18:37:51 +08:00 committed by GitHub
commit 9ea2e1d4cb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 69 additions and 29 deletions

View File

@ -23,7 +23,6 @@ class BoardCardBloc extends Bloc<BoardCardEvent, BoardCardState> {
}) : _rowService = RowFFIService(
gridId: gridId,
blockId: dataController.rowPB.blockId,
rowId: dataController.rowPB.id,
),
_dataController = dataController,
super(BoardCardState.initial(
@ -34,9 +33,6 @@ class BoardCardBloc extends Bloc<BoardCardEvent, BoardCardState> {
initial: (_InitialRow value) async {
await _startListening();
},
createRow: (_CreateRow value) {
_rowService.createRow();
},
didReceiveCells: (_DidReceiveCells value) async {
final cells = value.gridCellMap.values
.map((e) => GridCellEquatable(e.field))
@ -61,7 +57,6 @@ class BoardCardBloc extends Bloc<BoardCardEvent, BoardCardState> {
RowInfo rowInfo() {
return RowInfo(
gridId: _rowService.gridId,
blockId: _rowService.blockId,
fields: UnmodifiableListView(
state.cells.map((cell) => cell._field).toList(),
),
@ -83,7 +78,6 @@ class BoardCardBloc extends Bloc<BoardCardEvent, BoardCardState> {
@freezed
class BoardCardEvent with _$BoardCardEvent {
const factory BoardCardEvent.initial() = _InitialRow;
const factory BoardCardEvent.createRow() = _CreateRow;
const factory BoardCardEvent.didReceiveCells(
GridCellMap gridCellMap, RowsChangedReason reason) = _DidReceiveCells;
}

View File

@ -1,11 +1,20 @@
// ignore_for_file: unused_field
import 'dart:collection';
import 'package:app_flowy/plugins/board/application/card/card_data_controller.dart';
import 'package:app_flowy/plugins/grid/application/row/row_cache.dart';
import 'package:app_flowy/plugins/grid/application/field/field_cache.dart';
import 'package:app_flowy/plugins/grid/application/row/row_data_controller.dart';
import 'package:app_flowy/plugins/grid/presentation/widgets/cell/cell_builder.dart';
import 'package:app_flowy/plugins/grid/presentation/widgets/row/row_detail.dart';
import 'package:appflowy_board/appflowy_board.dart';
import 'package:flowy_infra_ui/widget/error_page.dart';
import 'package:flowy_sdk/protobuf/flowy-folder/view.pb.dart';
import 'package:flowy_sdk/protobuf/flowy-grid/block_entities.pb.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import '../../grid/application/row/row_cache.dart';
import '../application/board_bloc.dart';
import 'card/card.dart';
import 'card/card_cell_builder.dart';
@ -123,9 +132,36 @@ class BoardContent extends StatelessWidget {
onEditEditing: (rowId) {
context.read<BoardBloc>().add(BoardEvent.endEditRow(rowId));
},
openCard: (context) => _openCard(
gridId,
fieldCache,
rowPB,
rowCache,
context,
),
),
);
}
void _openCard(String gridId, GridFieldCache fieldCache, RowPB rowPB,
GridRowCache rowCache, BuildContext context) {
final rowInfo = RowInfo(
gridId: gridId,
fields: UnmodifiableListView(fieldCache.fields),
rowPB: rowPB,
);
final dataController = GridRowDataController(
rowInfo: rowInfo,
fieldCache: fieldCache,
rowCache: rowCache,
);
RowDetailPage(
cellBuilder: GridCellBuilder(delegate: dataController),
dataController: dataController,
).show(context);
}
}
extension HexColor on Color {

View File

@ -18,6 +18,7 @@ class BoardCard extends StatefulWidget {
final CardDataController dataController;
final BoardCellBuilder cellBuilder;
final OnEndEditing onEditEditing;
final void Function(BuildContext) openCard;
const BoardCard({
required this.gridId,
@ -25,6 +26,7 @@ class BoardCard extends StatefulWidget {
required this.dataController,
required this.cellBuilder,
required this.onEditEditing,
required this.openCard,
Key? key,
}) : super(key: key);
@ -54,6 +56,9 @@ class _BoardCardState extends State<BoardCard> {
accessoryBuilder: (context) {
return [const _CardMoreOption()];
},
onTap: (context) {
widget.openCard(context);
},
child: Column(
children: _makeCells(context, state.gridCellMap),
),

View File

@ -7,8 +7,10 @@ import 'package:styled_widget/styled_widget.dart';
class BoardCardContainer extends StatelessWidget {
final Widget child;
final CardAccessoryBuilder? accessoryBuilder;
final void Function(BuildContext) onTap;
const BoardCardContainer({
required this.child,
required this.onTap,
this.accessoryBuilder,
Key? key,
}) : super(key: key);
@ -30,11 +32,14 @@ class BoardCardContainer extends StatelessWidget {
}
}
return Padding(
padding: const EdgeInsets.all(8),
child: ConstrainedBox(
constraints: const BoxConstraints(minHeight: 30),
child: container,
return GestureDetector(
onTap: () => onTap(context),
child: Padding(
padding: const EdgeInsets.all(8),
child: ConstrainedBox(
constraints: const BoxConstraints(minHeight: 30),
child: container,
),
),
);
},

View File

@ -17,19 +17,19 @@ class RowActionSheetBloc
RowActionSheetBloc({required RowInfo rowInfo})
: _rowService = RowFFIService(
gridId: rowInfo.gridId,
blockId: rowInfo.blockId,
rowId: rowInfo.rowPB.id,
blockId: rowInfo.rowPB.blockId,
),
super(RowActionSheetState.initial(rowInfo)) {
on<RowActionSheetEvent>(
(event, emit) async {
await event.map(
deleteRow: (_DeleteRow value) async {
final result = await _rowService.deleteRow();
final result = await _rowService.deleteRow(state.rowData.rowPB.id);
logResult(result);
},
duplicateRow: (_DuplicateRow value) async {
final result = await _rowService.duplicateRow();
final result =
await _rowService.duplicateRow(state.rowData.rowPB.id);
logResult(result);
},
);

View File

@ -20,8 +20,7 @@ class RowBloc extends Bloc<RowEvent, RowState> {
required GridRowDataController dataController,
}) : _rowService = RowFFIService(
gridId: rowInfo.gridId,
blockId: rowInfo.blockId,
rowId: rowInfo.rowPB.id,
blockId: rowInfo.rowPB.blockId,
),
_dataController = dataController,
super(RowState.initial(rowInfo, dataController.loadData())) {
@ -32,7 +31,7 @@ class RowBloc extends Bloc<RowEvent, RowState> {
await _startListening();
},
createRow: (_CreateRow value) {
_rowService.createRow();
_rowService.createRow(rowInfo.rowPB.id);
},
didReceiveCells: (_DidReceiveCells value) async {
final cells = value.gridCellMap.values

View File

@ -255,7 +255,6 @@ class GridRowCache {
RowInfo buildGridRow(RowPB rowPB) {
return RowInfo(
gridId: gridId,
blockId: block.id,
fields: _fieldNotifier.fields,
rowPB: rowPB,
);
@ -283,7 +282,6 @@ class _RowChangesetNotifier extends ChangeNotifier {
class RowInfo with _$RowInfo {
const factory RowInfo({
required String gridId,
required String blockId,
required UnmodifiableListView<FieldPB> fields,
required RowPB rowPB,
}) = _RowInfo;

View File

@ -9,12 +9,13 @@ import 'package:flowy_sdk/protobuf/flowy-grid/setting_entities.pb.dart';
class RowFFIService {
final String gridId;
final String blockId;
final String rowId;
RowFFIService(
{required this.gridId, required this.blockId, required this.rowId});
RowFFIService({
required this.gridId,
required this.blockId,
});
Future<Either<RowPB, FlowyError>> createRow() {
Future<Either<RowPB, FlowyError>> createRow(String rowId) {
final payload = CreateTableRowPayloadPB.create()
..gridId = gridId
..startRowId = rowId;
@ -43,7 +44,7 @@ class RowFFIService {
return GridEventMoveRow(payload).send();
}
Future<Either<OptionalRowPB, FlowyError>> getRow() {
Future<Either<OptionalRowPB, FlowyError>> getRow(String rowId) {
final payload = RowIdPB.create()
..gridId = gridId
..blockId = blockId
@ -52,7 +53,7 @@ class RowFFIService {
return GridEventGetRow(payload).send();
}
Future<Either<Unit, FlowyError>> deleteRow() {
Future<Either<Unit, FlowyError>> deleteRow(String rowId) {
final payload = RowIdPB.create()
..gridId = gridId
..blockId = blockId
@ -61,7 +62,7 @@ class RowFFIService {
return GridEventDeleteRow(payload).send();
}
Future<Either<Unit, FlowyError>> duplicateRow() {
Future<Either<Unit, FlowyError>> duplicateRow(String rowId) {
final payload = RowIdPB.create()
..gridId = gridId
..blockId = blockId

View File

@ -239,8 +239,10 @@ class _GridRowsState extends State<_GridRows> {
RowInfo rowInfo,
Animation<double> animation,
) {
final rowCache =
context.read<GridBloc>().getRowCache(rowInfo.blockId, rowInfo.rowPB.id);
final rowCache = context.read<GridBloc>().getRowCache(
rowInfo.rowPB.blockId,
rowInfo.rowPB.id,
);
/// Return placeholder widget if the rowCache is null.
if (rowCache == null) return const SizedBox();