Skip to content

Commit

Permalink
lint issues
Browse files Browse the repository at this point in the history
  • Loading branch information
ravi-sawlani-yral committed Jul 23, 2024
1 parent ce12882 commit 3fd73f6
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 33 deletions.
6 changes: 5 additions & 1 deletion src/component/content_upload.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
use crate::{auth::DelegatedIdentityWire, state::{canisters::Canisters, content_seed_client::{self, ContentSeedClient}}};
use crate::{
auth::DelegatedIdentityWire,
state::{canisters::Canisters, content_seed_client::ContentSeedClient},
};
use leptos::*;

#[component]
pub fn YoutubeUpload(
canisters: Canisters<true>,
Expand Down
53 changes: 27 additions & 26 deletions src/page/menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@ use crate::component::back_btn::BackButton;
use crate::component::canisters_prov::AuthCansProvider;
use crate::component::content_upload::YoutubeUpload;
use crate::component::modal::Modal;
use crate::component::spinner::{FullScreenSpinner, Spinner};
use crate::component::spinner::Spinner;
use crate::component::title::Title;
use crate::component::{connect::ConnectLogin, social::*, toggle::Toggle};
use crate::consts::{social, NSFW_TOGGLE_STORE};
use crate::state::auth::account_connected_reader;
use crate::state::canisters::{authenticated_canisters, Canisters};
use crate::state::content_seed_client::{self, ContentSeedClient};
use crate::state::canisters::authenticated_canisters;
use crate::state::content_seed_client::ContentSeedClient;
use crate::utils::profile::ProfileDetails;
use crate::utils::MockPartialEq;
use candid::Principal;
use leptos::html::Input;
use leptos::*;
Expand All @@ -19,7 +18,6 @@ use leptos_router::use_query_map;
use leptos_use::use_event_listener;
use leptos_use::{storage::use_local_storage, utils::FromToStringCodec};


#[derive(Clone, Default)]
pub struct AuthorizedUserToSeedContent(RwSignal<Option<(Principal, bool)>>);

Expand Down Expand Up @@ -152,33 +150,36 @@ pub fn Menu() -> impl IntoView {
let (is_connected, _) = account_connected_reader();
let query_map = use_query_map();
let show_content_modal = create_rw_signal(false);
let is_authorized_to_seed_content:AuthorizedUserToSeedContent = expect_context();
let content_seed_client: ContentSeedClient = expect_context();
let is_authorized_to_seed_content: AuthorizedUserToSeedContent = expect_context();

let can_res = authenticated_canisters();
let check_authorized_action = create_action( move |user_principal: &Principal | {
let check_authorized_action = create_action(move |user_principal: &Principal| {
let user_principal = *user_principal;
async move {
let content_seed_client:ContentSeedClient = expect_context();
let res = content_seed_client.check_if_authorized(user_principal).await.ok()?;
is_authorized_to_seed_content.0.set(Some((user_principal, res)));
Some(())
}
async move {
let content_seed_client: ContentSeedClient = expect_context();
let res = content_seed_client
.check_if_authorized(user_principal)
.await
.ok()?;
is_authorized_to_seed_content
.0
.set(Some((user_principal, res)));
Some(())
}
);
});

create_effect(
move |_| {
let canisters = can_res.get()?.ok()?;
let authorized_user_to_seed_content = is_authorized_to_seed_content.0.get_untracked();
match authorized_user_to_seed_content {
Some((user_principal, val)) if user_principal != canisters.user_principal() => {check_authorized_action.dispatch(canisters.user_principal())},
None => {check_authorized_action.dispatch(canisters.user_principal())}
_ => {}
create_effect(move |_| {
let canisters = can_res.get()?.ok()?;
let authorized_user_to_seed_content = is_authorized_to_seed_content.0.get_untracked();
match authorized_user_to_seed_content {
Some((user_principal, _)) if user_principal != canisters.user_principal() => {
check_authorized_action.dispatch(canisters.user_principal())
}
Some(())
},
);
None => check_authorized_action.dispatch(canisters.user_principal()),
_ => {}
}
Some(())
});

create_effect(move |_| {
//check whether query param is right if right set the show_modal_content as true.
Expand Down
5 changes: 1 addition & 4 deletions src/state/canisters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use std::{collections::HashSet, sync::Arc};
use candid::Principal;
use ic_agent::{identity::DelegatedIdentity, AgentError, Identity};
use leptos::*;
use std::error::Error;
use yral_metadata_client::MetadataClient;
use yral_metadata_types::UserMetadata;

Expand All @@ -16,12 +15,10 @@ use crate::{
user_index::UserIndex,
AGENT_URL,
},
consts::{DOWNLOAD_UPLOAD_SERVICE, METADATA_API_BASE},
consts::METADATA_API_BASE,
utils::{profile::ProfileDetails, MockPartialEq},
};

use super::content_seed_client::ContentSeedClient;

#[derive(Clone)]
pub struct Canisters<const AUTH: bool> {
agent: ic_agent::Agent,
Expand Down
7 changes: 5 additions & 2 deletions src/state/content_seed_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,12 @@ pub struct ContentSeedClient {
base_url: Url,
}

impl Default for ContentSeedClient {
impl Default for ContentSeedClient {
fn default() -> Self {
Self { client: Default::default(), base_url: DOWNLOAD_UPLOAD_SERVICE.clone() }
Self {
client: Default::default(),
base_url: DOWNLOAD_UPLOAD_SERVICE.clone(),
}
}
}

Expand Down

0 comments on commit 3fd73f6

Please sign in to comment.