mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
feat: folder web (#4580)
* chore: folder wasm * chore: folder wasm * chore: resolve deps * chore: fix trait * chore: try localset * chore: fix * chore: fix * chore: fix * chore: async init sdk * chore: fix test * chore: fix test
This commit is contained in:
@ -22,7 +22,7 @@ flowy-error = { path = "../flowy-error", features = ["impl_from_dispatch_error"]
|
||||
lib-dispatch = { workspace = true }
|
||||
bytes.workspace = true
|
||||
lib-infra = { workspace = true }
|
||||
tokio = { workspace = true, features = ["full"] }
|
||||
tokio = { workspace = true, features = ["sync"] }
|
||||
nanoid = "0.4.0"
|
||||
lazy_static = "1.4.0"
|
||||
chrono = { workspace = true, default-features = false, features = ["clock"] }
|
||||
@ -32,11 +32,13 @@ uuid.workspace = true
|
||||
tokio-stream = { workspace = true, features = ["sync"] }
|
||||
serde_json.workspace = true
|
||||
validator = "0.16.0"
|
||||
async-trait.workspace = true
|
||||
|
||||
[build-dependencies]
|
||||
flowy-codegen.workspace = true
|
||||
|
||||
[features]
|
||||
dart = ["flowy-codegen/dart", "flowy-notification/dart"]
|
||||
ts = ["flowy-codegen/ts", "flowy-notification/tauri_ts"]
|
||||
tauri_ts = ["flowy-codegen/ts", "flowy-notification/tauri_ts"]
|
||||
web_ts = ["flowy-codegen/ts", "flowy-notification/web_ts"]
|
||||
test_helper = []
|
||||
|
@ -5,9 +5,30 @@ fn main() {
|
||||
flowy_codegen::dart_event::gen(env!("CARGO_PKG_NAME"));
|
||||
}
|
||||
|
||||
#[cfg(feature = "ts")]
|
||||
#[cfg(feature = "tauri_ts")]
|
||||
{
|
||||
flowy_codegen::ts_event::gen(env!("CARGO_PKG_NAME"), flowy_codegen::Project::Tauri);
|
||||
flowy_codegen::protobuf_file::ts_gen(env!("CARGO_PKG_NAME"), flowy_codegen::Project::Tauri);
|
||||
flowy_codegen::protobuf_file::ts_gen(
|
||||
env!("CARGO_PKG_NAME"),
|
||||
env!("CARGO_PKG_NAME"),
|
||||
flowy_codegen::Project::Tauri,
|
||||
);
|
||||
}
|
||||
|
||||
#[cfg(feature = "web_ts")]
|
||||
{
|
||||
flowy_codegen::ts_event::gen(
|
||||
"folder",
|
||||
flowy_codegen::Project::Web {
|
||||
relative_path: "../../".to_string(),
|
||||
},
|
||||
);
|
||||
flowy_codegen::protobuf_file::ts_gen(
|
||||
env!("CARGO_PKG_NAME"),
|
||||
"folder",
|
||||
flowy_codegen::Project::Web {
|
||||
relative_path: "../../".to_string(),
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ use collab_integrate::{CollabKVDB, CollabPersistenceConfig};
|
||||
use flowy_error::{ErrorCode, FlowyError, FlowyResult};
|
||||
use flowy_folder_pub::cloud::{gen_view_id, FolderCloudService};
|
||||
use flowy_folder_pub::folder_builder::ParentChildViews;
|
||||
use lib_infra::async_trait::async_trait;
|
||||
use lib_infra::conditional_send_sync_trait;
|
||||
|
||||
use crate::entities::icon::UpdateViewIconParams;
|
||||
use crate::entities::{
|
||||
@ -35,11 +35,12 @@ use crate::util::{
|
||||
};
|
||||
use crate::view_operation::{create_view, FolderOperationHandler, FolderOperationHandlers};
|
||||
|
||||
/// [FolderUser] represents the user for folder.
|
||||
#[async_trait]
|
||||
pub trait FolderUser: Send + Sync {
|
||||
fn user_id(&self) -> Result<i64, FlowyError>;
|
||||
fn collab_db(&self, uid: i64) -> Result<Weak<CollabKVDB>, FlowyError>;
|
||||
conditional_send_sync_trait! {
|
||||
"[crate::manager::FolderUser] represents the user for folder.";
|
||||
FolderUser {
|
||||
fn user_id(&self) -> Result<i64, FlowyError>;
|
||||
fn collab_db(&self, uid: i64) -> Result<Weak<CollabKVDB>, FlowyError>;
|
||||
}
|
||||
}
|
||||
|
||||
pub struct FolderManager {
|
||||
|
@ -12,7 +12,6 @@ use crate::manager_observer::{
|
||||
subscribe_folder_trash_changed, subscribe_folder_view_changed,
|
||||
};
|
||||
use crate::user_default::DefaultFolderBuilder;
|
||||
use crate::util::is_exist_in_local_disk;
|
||||
|
||||
impl FolderManager {
|
||||
/// Called immediately after the application launched if the user already sign in/sign up.
|
||||
@ -47,7 +46,7 @@ impl FolderManager {
|
||||
FolderInitDataSource::LocalDisk {
|
||||
create_if_not_exist,
|
||||
} => {
|
||||
let is_exist = is_exist_in_local_disk(&self.user, &workspace_id).unwrap_or(false);
|
||||
let is_exist = self.is_workspace_exist_in_local(uid, &workspace_id).await;
|
||||
if is_exist {
|
||||
self
|
||||
.open_local_folder(uid, &workspace_id, collab_db, folder_notifier)
|
||||
@ -104,6 +103,15 @@ impl FolderManager {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn is_workspace_exist_in_local(&self, uid: i64, workspace_id: &str) -> bool {
|
||||
if let Ok(weak_collab) = self.user.collab_db(uid) {
|
||||
if let Some(collab_db) = weak_collab.upgrade() {
|
||||
return collab_db.is_exist(uid, workspace_id).await.unwrap_or(false);
|
||||
}
|
||||
}
|
||||
false
|
||||
}
|
||||
|
||||
async fn create_default_folder(
|
||||
&self,
|
||||
uid: i64,
|
||||
|
@ -1,31 +1,13 @@
|
||||
use collab_folder::Folder;
|
||||
use collab_integrate::CollabKVAction;
|
||||
use collab_plugins::local_storage::kv::KVTransactionDB;
|
||||
use flowy_error::{ErrorCode, FlowyError, FlowyResult};
|
||||
use flowy_folder_pub::folder_builder::ParentChildViews;
|
||||
use std::sync::Arc;
|
||||
use tracing::{event, instrument};
|
||||
|
||||
use crate::entities::UserFolderPB;
|
||||
use crate::manager::FolderUser;
|
||||
use collab_folder::Folder;
|
||||
use flowy_error::{ErrorCode, FlowyError};
|
||||
use flowy_folder_pub::folder_builder::ParentChildViews;
|
||||
use tracing::{event, instrument};
|
||||
|
||||
pub(crate) fn folder_not_init_error() -> FlowyError {
|
||||
FlowyError::internal().with_context("Folder not initialized")
|
||||
}
|
||||
|
||||
pub(crate) fn is_exist_in_local_disk(
|
||||
user: &Arc<dyn FolderUser>,
|
||||
doc_id: &str,
|
||||
) -> FlowyResult<bool> {
|
||||
let uid = user.user_id()?;
|
||||
if let Some(collab_db) = user.collab_db(uid)?.upgrade() {
|
||||
let read_txn = collab_db.read_txn();
|
||||
Ok(read_txn.is_exist(uid, doc_id))
|
||||
} else {
|
||||
Ok(false)
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn workspace_data_not_sync_error(uid: i64, workspace_id: &str) -> FlowyError {
|
||||
FlowyError::from(ErrorCode::WorkspaceDataNotSync).with_payload(UserFolderPB {
|
||||
uid,
|
||||
|
Reference in New Issue
Block a user