mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
[rust]: enable create doc view on offline mode
This commit is contained in:
parent
dd357c18cf
commit
fc05aac9f0
@ -7,11 +7,9 @@ use crate::{
|
||||
sqlx_ext::{map_sqlx_error, DBTransaction},
|
||||
};
|
||||
|
||||
use flowy_document::services::doc::doc_initial_string;
|
||||
use flowy_net::errors::ServerError;
|
||||
use flowy_workspace::{
|
||||
entities::view::DOC_DEFAULT_DATA,
|
||||
protobuf::{App, CreateViewParams, View, ViewType, Workspace},
|
||||
};
|
||||
use flowy_workspace::protobuf::{App, CreateViewParams, View, ViewType, Workspace};
|
||||
|
||||
pub async fn create_default_workspace(
|
||||
transaction: &mut DBTransaction<'_>,
|
||||
@ -63,7 +61,7 @@ async fn create_default_view(transaction: &mut DBTransaction<'_>, app: &App) ->
|
||||
desc: "View created by AppFlowy".to_string(),
|
||||
thumbnail: "123.png".to_string(),
|
||||
view_type: ViewType::Doc,
|
||||
data: DOC_DEFAULT_DATA.to_string(),
|
||||
data: doc_initial_string(),
|
||||
unknown_fields: Default::default(),
|
||||
cached_size: Default::default(),
|
||||
};
|
||||
|
@ -15,9 +15,19 @@ impl CustomDocument for PlainDoc {
|
||||
fn init_delta() -> Delta { Delta::new() }
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
#[inline]
|
||||
pub fn doc_initial_delta() -> Delta { DeltaBuilder::new().insert("\n").build() }
|
||||
#[allow(dead_code)]
|
||||
#[inline]
|
||||
pub fn doc_initial_string() -> String { doc_initial_delta().to_json() }
|
||||
#[allow(dead_code)]
|
||||
#[inline]
|
||||
pub fn doc_initial_bytes() -> Vec<u8> { doc_initial_string().into_bytes() }
|
||||
|
||||
pub struct FlowyDoc();
|
||||
impl CustomDocument for FlowyDoc {
|
||||
fn init_delta() -> Delta { DeltaBuilder::new().insert("\n").build() }
|
||||
fn init_delta() -> Delta { doc_initial_delta() }
|
||||
}
|
||||
|
||||
pub struct Document {
|
||||
|
@ -1,9 +1,10 @@
|
||||
use crate::{
|
||||
entities::doc::{CreateDocParams, Doc, DocIdentifier, UpdateDocParams},
|
||||
errors::DocError,
|
||||
services::server::DocumentServerAPI,
|
||||
services::{doc::doc_initial_string, server::DocumentServerAPI},
|
||||
};
|
||||
use flowy_infra::future::ResultFuture;
|
||||
|
||||
pub struct DocServerMock {}
|
||||
|
||||
impl DocumentServerAPI for DocServerMock {
|
||||
@ -11,8 +12,14 @@ impl DocumentServerAPI for DocServerMock {
|
||||
ResultFuture::new(async { Ok(()) })
|
||||
}
|
||||
|
||||
fn read_doc(&self, _token: &str, _params: DocIdentifier) -> ResultFuture<Option<Doc>, DocError> {
|
||||
ResultFuture::new(async { Ok(None) })
|
||||
fn read_doc(&self, _token: &str, params: DocIdentifier) -> ResultFuture<Option<Doc>, DocError> {
|
||||
let doc = Doc {
|
||||
id: params.doc_id,
|
||||
data: doc_initial_string(),
|
||||
rev_id: 0,
|
||||
base_rev_id: 0,
|
||||
};
|
||||
ResultFuture::new(async { Ok(Some(doc)) })
|
||||
}
|
||||
|
||||
fn update_doc(&self, _token: &str, _params: UpdateDocParams) -> ResultFuture<(), DocError> {
|
||||
|
@ -8,6 +8,7 @@ use crate::{
|
||||
impl_def_and_def_mut,
|
||||
};
|
||||
use flowy_derive::{ProtoBuf, ProtoBuf_Enum};
|
||||
use flowy_document::services::doc::doc_initial_string;
|
||||
use std::convert::TryInto;
|
||||
|
||||
#[derive(PartialEq, Debug, ProtoBuf_Enum, Clone)]
|
||||
@ -72,10 +73,6 @@ pub struct CreateViewParams {
|
||||
pub data: String,
|
||||
}
|
||||
|
||||
pub const DOC_DEFAULT_DATA: &str = "[{\"insert\":\"\\n\"}]";
|
||||
#[allow(dead_code)]
|
||||
pub fn default_delta() -> Vec<u8> { DOC_DEFAULT_DATA.as_bytes().to_vec() }
|
||||
|
||||
impl CreateViewParams {
|
||||
pub fn new(belong_to_id: String, name: String, desc: String, view_type: ViewType, thumbnail: String) -> Self {
|
||||
Self {
|
||||
@ -84,7 +81,7 @@ impl CreateViewParams {
|
||||
desc,
|
||||
thumbnail,
|
||||
view_type,
|
||||
data: DOC_DEFAULT_DATA.to_string(),
|
||||
data: doc_initial_string(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user