Skip to content

Commit

Permalink
feat: add new database on mobile platform (AppFlowy-IO#3788)
Browse files Browse the repository at this point in the history
* chore: downgrade clipboard package

* fix: update i18n in the favorite page

* fix: update the favorite icon

* feat: support add new database

* chore: disable cache in unit test

* chore: bump version 0.3.7
  • Loading branch information
LucasXu0 authored Oct 26, 2023
1 parent 8c3984d commit 9416ba1
Show file tree
Hide file tree
Showing 19 changed files with 324 additions and 70 deletions.
9 changes: 2 additions & 7 deletions .github/workflows/flutter_ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -181,17 +181,12 @@ jobs:
fi
shell: bash

- uses: actions/download-artifact@v3
with:
name: ${{ github.run_id }}-${{ matrix.os }}

- name: Uncompress appflowy_flutter
run: tar -xf appflowy_flutter.tar.gz

- name: Run Flutter unit tests
working-directory: frontend
run: |
if [ "$RUNNER_OS" == "macOS" ]; then
flutter config --enable-macos-desktop
cargo make --profile ${{ matrix.flutter_profile }} appflowy-dev
cargo make dart_unit_test
else
cargo make dart_unit_test_no_build
Expand Down
2 changes: 1 addition & 1 deletion frontend/Makefile.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ CARGO_MAKE_EXTEND_WORKSPACE_MAKEFILE = true
CARGO_MAKE_CRATE_FS_NAME = "dart_ffi"
CARGO_MAKE_CRATE_NAME = "dart-ffi"
LIB_NAME = "dart_ffi"
CURRENT_APP_VERSION = "0.3.6"
CURRENT_APP_VERSION = "0.3.7"
FLUTTER_DESKTOP_FEATURES = "dart,rev-sqlite"
PRODUCT_NAME = "AppFlowy"
# CRATE_TYPE: https://doc.rust-lang.org/reference/linkage.html
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:appflowy/mobile/presentation/bottom_sheet/mobile_bottom_sheet_body.dart';
import 'package:appflowy/mobile/presentation/bottom_sheet/mobile_bottom_sheet_rename_widget.dart';
import 'package:appflowy/mobile/presentation/bottom_sheet/mobile_bottom_sheet_view_item_header.dart';
import 'package:appflowy/mobile/presentation/bottom_sheet/bottom_sheet_drag_handler.dart';
import 'package:appflowy/mobile/presentation/bottom_sheet/bottom_sheet_rename_widget.dart';
import 'package:appflowy/mobile/presentation/bottom_sheet/bottom_sheet_view_item_body.dart';
import 'package:appflowy/mobile/presentation/bottom_sheet/bottom_sheet_view_item_header.dart';
import 'package:appflowy/workspace/application/favorite/favorite_bloc.dart';
import 'package:appflowy/workspace/application/view/view_bloc.dart';
import 'package:appflowy_backend/protobuf/flowy-folder2/protobuf.dart';
Expand Down Expand Up @@ -36,11 +37,11 @@ enum MobileBottomSheetType {
class MobileViewItemBottomSheet extends StatefulWidget {
const MobileViewItemBottomSheet({
super.key,
this.view,
required this.view,
this.defaultType = MobileBottomSheetType.view,
});

final ViewPB? view;
final ViewPB view;
final MobileBottomSheetType defaultType;

@override
Expand All @@ -56,11 +57,6 @@ class _MobileViewItemBottomSheetState extends State<MobileViewItemBottomSheet> {
super.initState();

type = widget.defaultType;

if ([MobileBottomSheetType.view, MobileBottomSheetType.rename]
.contains(type)) {
assert(widget.view != null);
}
}

@override
Expand All @@ -69,17 +65,7 @@ class _MobileViewItemBottomSheetState extends State<MobileViewItemBottomSheet> {
mainAxisSize: MainAxisSize.min,
children: [
// drag handler
Padding(
padding: const EdgeInsets.only(top: 12, bottom: 12.0),
child: Container(
width: 64,
height: 4,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(2.0),
color: Colors.grey,
),
),
),
const MobileBottomSheetDragHandler(),

// header
_buildHeader(),
Expand All @@ -100,7 +86,7 @@ class _MobileViewItemBottomSheetState extends State<MobileViewItemBottomSheet> {
// header
return MobileViewItemBottomSheetHeader(
showBackButton: type != MobileBottomSheetType.view,
view: widget.view!,
view: widget.view,
onBack: () {
setState(() {
type = MobileBottomSheetType.view;
Expand All @@ -114,7 +100,7 @@ class _MobileViewItemBottomSheetState extends State<MobileViewItemBottomSheet> {
switch (type) {
case MobileBottomSheetType.view:
return MobileViewItemBottomSheetBody(
isFavorite: widget.view!.isFavorite,
isFavorite: widget.view.isFavorite,
onAction: (action) {
switch (action) {
case MobileViewItemBottomSheetBodyAction.rename:
Expand All @@ -138,17 +124,17 @@ class _MobileViewItemBottomSheetState extends State<MobileViewItemBottomSheet> {
case MobileViewItemBottomSheetBodyAction.removeFromFavorites:
context
.read<FavoriteBloc>()
.add(FavoriteEvent.toggle(widget.view!));
.add(FavoriteEvent.toggle(widget.view));
context.pop();
break;
}
},
);
case MobileBottomSheetType.rename:
return MobileBottomSheetRenameWidget(
name: widget.view!.name,
name: widget.view.name,
onRename: (name) {
if (name != widget.view!.name) {
if (name != widget.view.name) {
context.read<ViewBloc>().add(ViewEvent.rename(name));
}
context.pop();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
import 'package:appflowy/generated/flowy_svgs.g.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/mobile/presentation/bottom_sheet/bottom_sheet_action_widget.dart';
import 'package:appflowy/mobile/presentation/bottom_sheet/bottom_sheet_drag_handler.dart';
import 'package:appflowy/mobile/presentation/bottom_sheet/bottom_sheet_view_item_header.dart';
import 'package:appflowy_backend/protobuf/flowy-folder2/protobuf.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flowy_infra_ui/flowy_infra_ui.dart';
import 'package:flutter/material.dart';

class AddNewPageWidgetBottomSheet extends StatelessWidget {
const AddNewPageWidgetBottomSheet({
super.key,
required this.view,
required this.onAction,
});

final ViewPB view;
final void Function(ViewLayoutPB layout) onAction;

@override
Widget build(BuildContext context) {
return Column(
mainAxisSize: MainAxisSize.min,
children: [
// drag handler
const MobileBottomSheetDragHandler(),

// header
MobileViewItemBottomSheetHeader(
showBackButton: false,
view: view,
onBack: () {},
),
const VSpace(8.0),
const Divider(),

// body
_AddNewPageBody(
onAction: onAction,
),
const VSpace(24.0),
],
);
}
}

class _AddNewPageBody extends StatelessWidget {
const _AddNewPageBody({
required this.onAction,
});

final void Function(ViewLayoutPB layout) onAction;

@override
Widget build(BuildContext context) {
return Column(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
// rename, duplicate
Row(
mainAxisSize: MainAxisSize.min,
children: [
Expanded(
child: BottomSheetActionWidget(
svg: FlowySvgs.documents_s,
text: LocaleKeys.newDocumentText.tr(),
onTap: () => onAction(ViewLayoutPB.Document),
),
),
Expanded(
child: BottomSheetActionWidget(
svg: FlowySvgs.grid_s,
text: LocaleKeys.newGridText.tr(),
onTap: () => onAction(ViewLayoutPB.Grid),
),
),
],
),

// share, delete
Row(
mainAxisSize: MainAxisSize.min,
children: [
Expanded(
child: BottomSheetActionWidget(
svg: FlowySvgs.board_s,
text: LocaleKeys.newBoardText.tr(),
onTap: () => onAction(ViewLayoutPB.Board),
),
),
Expanded(
child: BottomSheetActionWidget(
svg: FlowySvgs.date_s,
text: LocaleKeys.newCalendarText.tr(),
onTap: () => onAction(ViewLayoutPB.Calendar),
),
),
],
),
],
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import 'package:flutter/material.dart';

class MobileBottomSheetDragHandler extends StatelessWidget {
const MobileBottomSheetDragHandler({super.key});

@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.only(top: 12, bottom: 12.0),
child: Container(
width: 64,
height: 4,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(2.0),
color: Colors.grey,
),
),
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
import 'package:appflowy/mobile/presentation/bottom_sheet/bottom_sheet_drag_handler.dart';
import 'package:appflowy/mobile/presentation/bottom_sheet/bottom_sheet_rename_widget.dart';
import 'package:appflowy/mobile/presentation/bottom_sheet/bottom_sheet_view_item_body.dart';
import 'package:appflowy/mobile/presentation/bottom_sheet/bottom_sheet_view_item_header.dart';
import 'package:appflowy/workspace/application/favorite/favorite_bloc.dart';
import 'package:appflowy/workspace/application/view/view_bloc.dart';
import 'package:appflowy_backend/protobuf/flowy-folder2/protobuf.dart';
import 'package:flowy_infra_ui/flowy_infra_ui.dart' hide WidgetBuilder;
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:go_router/go_router.dart';

enum MobileBottomSheetType {
view,
rename,
}

class MobileViewItemBottomSheet extends StatefulWidget {
const MobileViewItemBottomSheet({
super.key,
required this.view,
this.defaultType = MobileBottomSheetType.view,
});

final ViewPB view;
final MobileBottomSheetType defaultType;

@override
State<MobileViewItemBottomSheet> createState() =>
_MobileViewItemBottomSheetState();
}

class _MobileViewItemBottomSheetState extends State<MobileViewItemBottomSheet> {
MobileBottomSheetType type = MobileBottomSheetType.view;

@override
initState() {
super.initState();

type = widget.defaultType;
}

@override
Widget build(BuildContext context) {
return Column(
mainAxisSize: MainAxisSize.min,
children: [
// drag handler
const MobileBottomSheetDragHandler(),

// header
_buildHeader(),
const VSpace(8.0),
const Divider(),

// body
_buildBody(),
const VSpace(24.0),
],
);
}

Widget _buildHeader() {
switch (type) {
case MobileBottomSheetType.view:
case MobileBottomSheetType.rename:
// header
return MobileViewItemBottomSheetHeader(
showBackButton: type != MobileBottomSheetType.view,
view: widget.view,
onBack: () {
setState(() {
type = MobileBottomSheetType.view;
});
},
);
}
}

Widget _buildBody() {
switch (type) {
case MobileBottomSheetType.view:
return MobileViewItemBottomSheetBody(
isFavorite: widget.view.isFavorite,
onAction: (action) {
switch (action) {
case MobileViewItemBottomSheetBodyAction.rename:
setState(() {
type = MobileBottomSheetType.rename;
});
break;
case MobileViewItemBottomSheetBodyAction.duplicate:
context.read<ViewBloc>().add(const ViewEvent.duplicate());
context.pop();
break;
case MobileViewItemBottomSheetBodyAction.share:
// unimplemented
context.pop();
break;
case MobileViewItemBottomSheetBodyAction.delete:
context.read<ViewBloc>().add(const ViewEvent.delete());
context.pop();
break;
case MobileViewItemBottomSheetBodyAction.addToFavorites:
case MobileViewItemBottomSheetBodyAction.removeFromFavorites:
context
.read<FavoriteBloc>()
.add(FavoriteEvent.toggle(widget.view));
context.pop();
break;
}
},
);
case MobileBottomSheetType.rename:
return MobileBottomSheetRenameWidget(
name: widget.view.name,
onRename: (name) {
if (name != widget.view.name) {
context.read<ViewBloc>().add(ViewEvent.rename(name));
}
context.pop();
},
);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:appflowy/generated/flowy_svgs.g.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/mobile/presentation/bottom_sheet/mobile_bottom_sheet_action_widget.dart';
import 'package:appflowy/mobile/presentation/bottom_sheet/bottom_sheet_action_widget.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'package:appflowy/generated/flowy_svgs.g.dart';
import 'package:appflowy/mobile/presentation/bottom_sheet/mobile_bottom_sheet.dart';
import 'package:appflowy/mobile/presentation/bottom_sheet/bottom_sheet.dart';
import 'package:appflowy/mobile/presentation/page_item/mobile_slide_action_button.dart';
import 'package:appflowy/workspace/application/favorite/favorite_bloc.dart';
import 'package:appflowy/workspace/application/view/view_bloc.dart';
Expand Down
Loading

0 comments on commit 9416ba1

Please sign in to comment.