11use crate :: instagram:: Msg :: { InstagramAccountIdSuccess , InstagramAccountDetailsSuccess } ;
2- use facebook_api_rs:: prelude:: account:: { InstaAccount , InstagramAccount } ;
2+ use facebook_api_rs:: prelude:: account:: { InstaAccount , InstagramAccount , InstaAccountId } ;
33use facebook_api_rs:: prelude:: publish:: { InstaMediaContainerId , InstaPostParams } ;
44use facebook_api_rs:: prelude:: search:: { PageSearch , PagesAPI } ;
55use facebook_api_rs:: prelude:: * ;
@@ -101,11 +101,16 @@ pub enum Msg {
101101 InstaPostSuccessful ( InstaMediaContainerId ) ,
102102 HandleInstaPostingOption ( web_sys:: Event ) ,
103103 PagesSearch ( String ) ,
104- GetInstagramAccountDetails ,
104+ GetInstagramAccountDetails ( InstaAccount ) ,
105105 InstagramAccountDetailsSuccess ( InstagramAccount ) ,
106106 PageSearchResponse ( PageSearch ) ,
107+
107108 MediaContainerStatus ,
108109 MediaContainerStatusResponse ( MediaContainerStatus ) ,
110+
111+ FetchInstagramAccountId ,
112+ FetchInstagramAccountIdSuccess ( InstaAccount ) ,
113+
109114 // every error should user this
110115 ResponseFailed ( FetchError ) ,
111116}
@@ -137,8 +142,7 @@ pub fn update(msg: Msg, model: &mut Model, orders: &mut impl Orders<Msg>) {
137142 Msg :: InstagramAccountIdSuccess ( resp) => {
138143 model. insta_account = Some ( resp) ;
139144 }
140-
141- Msg :: GetInstagramAccountDetails => {
145+ Msg :: FetchInstagramAccountId => {
142146 if model. selected_account . is_some ( ) {
143147 if let Some ( selected_page) = & model. selected_account {
144148 let page_access_token = selected_page. access_token . to_owned ( ) ;
@@ -147,6 +151,26 @@ pub fn update(msg: Msg, model: &mut Model, orders: &mut impl Orders<Msg>) {
147151 orders. perform_cmd ( async move {
148152 Client :: new ( Token :: default ( ) , page_access_token. clone ( ) )
149153 . instagram_account ( facebook_page_id)
154+ . account_id ( )
155+ . await
156+ . map_or_else ( Msg :: ResponseFailed , Msg :: FetchInstagramAccountIdSuccess )
157+ } ) ;
158+ }
159+ } ;
160+
161+ }
162+ Msg :: FetchInstagramAccountIdSuccess ( insta_id) => {
163+ orders. send_msg ( Msg :: GetInstagramAccountDetails ( insta_id) ) ;
164+ }
165+ Msg :: GetInstagramAccountDetails ( insta_id) => {
166+ let instagram_id = insta_id. instagram_business_account . id . clone ( ) ;
167+ if model. selected_account . is_some ( ) {
168+ if let Some ( selected_page) = & model. selected_account {
169+ let page_access_token = selected_page. access_token . to_owned ( ) ;
170+
171+ orders. perform_cmd ( async move {
172+ Client :: new ( Token :: default ( ) , page_access_token. clone ( ) )
173+ . instagram_account ( instagram_id)
150174 . account_details ( )
151175 . await
152176 . map_or_else ( Msg :: ResponseFailed , InstagramAccountDetailsSuccess )
@@ -398,7 +422,7 @@ pub fn view(model: &Model) -> Node<Msg> {
398422 ] ,
399423 button![
400424 "Get Instagram Account details " ,
401- ev( Ev :: Click , |_| { Msg :: GetInstagramAccountDetails } ) ,
425+ ev( Ev :: Click , |_| { Msg :: FetchInstagramAccountId } ) ,
402426 attrs! {
403427 At :: Disabled => model. selected_account. is_none( ) . as_at_value( )
404428 }
0 commit comments