mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
feat: integrate publish api
This commit is contained in:
parent
9c3f083684
commit
4a8536d403
@ -1,11 +1,13 @@
|
|||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
|
|
||||||
import 'package:appflowy/workspace/application/export/document_exporter.dart';
|
import 'package:appflowy/workspace/application/export/document_exporter.dart';
|
||||||
|
import 'package:appflowy/workspace/application/view/view_service.dart';
|
||||||
import 'package:appflowy_backend/log.dart';
|
import 'package:appflowy_backend/log.dart';
|
||||||
import 'package:appflowy_backend/protobuf/flowy-document/entities.pb.dart';
|
import 'package:appflowy_backend/protobuf/flowy-document/entities.pb.dart';
|
||||||
import 'package:appflowy_backend/protobuf/flowy-error/errors.pb.dart';
|
import 'package:appflowy_backend/protobuf/flowy-error/errors.pb.dart';
|
||||||
import 'package:appflowy_backend/protobuf/flowy-folder/view.pb.dart';
|
import 'package:appflowy_backend/protobuf/flowy-folder/view.pb.dart';
|
||||||
import 'package:appflowy_result/appflowy_result.dart';
|
import 'package:appflowy_result/appflowy_result.dart';
|
||||||
|
import 'package:flowy_infra/uuid.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||||
|
|
||||||
@ -35,16 +37,41 @@ class DocumentShareBloc extends Bloc<DocumentShareEvent, DocumentShareState> {
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
publish: (url) async {
|
publish: (url) async {
|
||||||
emit(state.copyWith(isPublished: true));
|
// todo: optimize the logic
|
||||||
|
const spaceName = 'appflowy';
|
||||||
|
final name = '${view.name}-${uuid()}';
|
||||||
|
|
||||||
|
// set space name
|
||||||
|
try {
|
||||||
|
await ViewBackendService.setPublishNameSpace(spaceName)
|
||||||
|
.getOrThrow();
|
||||||
|
await ViewBackendService.publish(view, name: name).getOrThrow();
|
||||||
|
} catch (e) {
|
||||||
|
Log.error('publish error: $e');
|
||||||
|
}
|
||||||
|
|
||||||
|
emit(
|
||||||
|
state.copyWith(
|
||||||
|
isPublished: true,
|
||||||
|
url: 'https://test.appflowy.io/$spaceName/$name',
|
||||||
|
),
|
||||||
|
);
|
||||||
},
|
},
|
||||||
unPublish: () async {
|
unPublish: () async {
|
||||||
emit(state.copyWith(isPublished: false));
|
await ViewBackendService.unpublish(view);
|
||||||
|
emit(
|
||||||
|
state.copyWith(
|
||||||
|
isPublished: false,
|
||||||
|
url: '',
|
||||||
|
),
|
||||||
|
);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
final ViewPB view;
|
final ViewPB view;
|
||||||
|
|
||||||
late final exporter = DocumentExporter(view);
|
late final exporter = DocumentExporter(view);
|
||||||
|
|
||||||
Future<FlowyResult<ExportDataPB, FlowyError>> _export(
|
Future<FlowyResult<ExportDataPB, FlowyError>> _export(
|
||||||
@ -124,10 +151,12 @@ class DocumentShareState with _$DocumentShareState {
|
|||||||
FlowyResult<ExportDataPB, FlowyError>? exportResult,
|
FlowyResult<ExportDataPB, FlowyError>? exportResult,
|
||||||
required bool isPublished,
|
required bool isPublished,
|
||||||
FlowyResult<void, FlowyError>? publishResult,
|
FlowyResult<void, FlowyError>? publishResult,
|
||||||
|
required String url,
|
||||||
}) = _DocumentShareState;
|
}) = _DocumentShareState;
|
||||||
|
|
||||||
factory DocumentShareState.initial() => const DocumentShareState(
|
factory DocumentShareState.initial() => const DocumentShareState(
|
||||||
isLoading: false,
|
isLoading: false,
|
||||||
isPublished: false,
|
isPublished: false,
|
||||||
|
url: '',
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import 'package:appflowy/generated/flowy_svgs.g.dart';
|
import 'package:appflowy/generated/flowy_svgs.g.dart';
|
||||||
import 'package:appflowy/generated/locale_keys.g.dart';
|
import 'package:appflowy/generated/locale_keys.g.dart';
|
||||||
import 'package:appflowy/plugins/document/application/document_share_bloc.dart';
|
import 'package:appflowy/plugins/document/application/document_share_bloc.dart';
|
||||||
|
import 'package:appflowy_editor/appflowy_editor.dart';
|
||||||
import 'package:easy_localization/easy_localization.dart';
|
import 'package:easy_localization/easy_localization.dart';
|
||||||
import 'package:flowy_infra_ui/flowy_infra_ui.dart';
|
import 'package:flowy_infra_ui/flowy_infra_ui.dart';
|
||||||
import 'package:flowy_infra_ui/widget/rounded_button.dart';
|
import 'package:flowy_infra_ui/widget/rounded_button.dart';
|
||||||
@ -81,7 +82,9 @@ class _PublishedWidgetState extends State<_PublishedWidget> {
|
|||||||
name: LocaleKeys.shareAction_visitSite.tr(),
|
name: LocaleKeys.shareAction_visitSite.tr(),
|
||||||
backgroundColor: Theme.of(context).colorScheme.primary,
|
backgroundColor: Theme.of(context).colorScheme.primary,
|
||||||
textColor: Colors.white,
|
textColor: Colors.white,
|
||||||
onTap: () {},
|
onTap: () {
|
||||||
|
safeLaunchUrl(controller.text);
|
||||||
|
},
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
@ -271,4 +271,31 @@ class ViewBackendService {
|
|||||||
);
|
);
|
||||||
return FolderEventUpdateViewVisibilityStatus(payload).send();
|
return FolderEventUpdateViewVisibilityStatus(payload).send();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Future<FlowyResult<void, FlowyError>> publish(
|
||||||
|
ViewPB view, {
|
||||||
|
String? name,
|
||||||
|
}) async {
|
||||||
|
final payload = PublishViewParamsPB()..viewId = view.id;
|
||||||
|
|
||||||
|
if (name != null) {
|
||||||
|
payload.publishName = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
return FolderEventPublishView(payload).send();
|
||||||
|
}
|
||||||
|
|
||||||
|
static Future<FlowyResult<void, FlowyError>> unpublish(
|
||||||
|
ViewPB view,
|
||||||
|
) async {
|
||||||
|
final payload = UnpublishViewsPayloadPB(viewIds: [view.id]);
|
||||||
|
return FolderEventUnpublishViews(payload).send();
|
||||||
|
}
|
||||||
|
|
||||||
|
static Future<FlowyResult<void, FlowyError>> setPublishNameSpace(
|
||||||
|
String name,
|
||||||
|
) async {
|
||||||
|
final payload = SetPublishNamespacePayloadPB()..newNamespace = name;
|
||||||
|
return FolderEventSetPublishNamespace(payload).send();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user