Nathan.fooo f9e7b5ffa4
feat: reload UI (#2999)
* chore: reload folder

* chore: reload folder

* chore: init sync

* chore: update tables

* chore: update database

* chore: load row

* chore: update

* chore: reload row

* test: fit test

* chore: retry

* chore: support batch fetch

* chore: enable sync

* chore: sync switch

* chore: sync switch

* chore: migration user data

* chore: migrate data

* chore: migrate folder

* chore: save user email

* chore: refresh user profile

* chore: fix test

* chore: delete translation files

* test: clippy format
2023-07-14 13:37:13 +08:00

83 lines
2.0 KiB
Rust

use std::sync::Arc;
use nanoid::nanoid;
use flowy_user::entities::{AuthTypePB, SignUpPayloadPB, UserProfilePB};
use flowy_user::errors::FlowyError;
use flowy_user::event_map::UserEvent::*;
use lib_dispatch::prelude::{AFPluginDispatcher, AFPluginRequest, ToBytes};
pub fn random_email() -> String {
format!("{}@appflowy.io", nanoid!(20))
}
pub fn login_email() -> String {
"annie2@appflowy.io".to_string()
}
pub fn login_password() -> String {
"HelloWorld!123".to_string()
}
pub struct SignUpContext {
pub user_profile: UserProfilePB,
pub password: String,
}
pub fn sign_up(dispatch: Arc<AFPluginDispatcher>) -> SignUpContext {
let password = login_password();
let payload = SignUpPayloadPB {
email: random_email(),
name: "app flowy".to_string(),
password: password.clone(),
auth_type: AuthTypePB::Local,
}
.into_bytes()
.unwrap();
let request = AFPluginRequest::new(SignUp).payload(payload);
let user_profile = AFPluginDispatcher::sync_send(dispatch, request)
.parse::<UserProfilePB, FlowyError>()
.unwrap()
.unwrap();
SignUpContext {
user_profile,
password,
}
}
pub async fn async_sign_up(
dispatch: Arc<AFPluginDispatcher>,
auth_type: AuthTypePB,
) -> SignUpContext {
let password = login_password();
let email = random_email();
let payload = SignUpPayloadPB {
email,
name: "app flowy".to_string(),
password: password.clone(),
auth_type,
}
.into_bytes()
.unwrap();
let request = AFPluginRequest::new(SignUp).payload(payload);
let user_profile = AFPluginDispatcher::async_send(dispatch.clone(), request)
.await
.parse::<UserProfilePB, FlowyError>()
.unwrap()
.unwrap();
// let _ = create_default_workspace_if_need(dispatch.clone(), &user_profile.id);
SignUpContext {
user_profile,
password,
}
}
pub async fn init_user_setting(dispatch: Arc<AFPluginDispatcher>) {
let request = AFPluginRequest::new(InitUser);
let _ = AFPluginDispatcher::async_send(dispatch.clone(), request).await;
}