Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] GraphPresenter should react to global provider state changes #166

Open
shweaver-MSFT opened this issue Sep 28, 2021 · 0 comments

Comments

@shweaver-MSFT
Copy link
Member

shweaver-MSFT commented Sep 28, 2021

Describe the problem this feature would solve

The GraphPresenter requires an IBaseRequestBuilder implementation to determine what data to fetch from Graph. We don't currently have a good way to define the RequestBuilder property in XAML, so this must be done from code. The problem is that if the provider state changes after the RequestBuilder property is set, the GraphPresenter will fail. The way to fix this is to nullify the RequestBuilder, and then re-set it.

Describe the solution

Update the GraphPresenter to listen for changes in the global provider state, and do whatever is required to keep the control functional after a login change.

The GraphPresenter should not display any content if the global provider is not signed in.

Describe alternatives you've considered

None

Additional context & Screenshots

All of this code is required to support a single instance of the GraphPresenter control:

namespace SampleTest.Samples.GraphPresenter
{
    public sealed partial class MailMessagesSample : Page
    {
        public IBaseRequestBuilder MessagesRequestBuilder { get; set; }

        public MailMessagesSample()
        {
            this.InitializeComponent();
            ProviderManager.Instance.ProviderUpdated += OnProviderUpdated;
            ProviderManager.Instance.ProviderStateChanged += OnProviderStateChanged;
        }

        private void OnProviderUpdated(object sender, IProvider provider)
        {
            if (provider == null)
            {
                ClearRequestBuilders();
            }
        }

        private void OnProviderStateChanged(object sender, ProviderStateChangedEventArgs e)
        {
            if (e.NewState == ProviderState.SignedIn)
            {
                var graphClient = ProviderManager.Instance.GlobalProvider.GetClient();

                MessagesRequestBuilder = graphClient.Me.Messages;
            }
            else
            {
                ClearRequestBuilders();
            }
        }

        private void ClearRequestBuilders()
        {
            MessagesRequestBuilder = null;
        }
    }
}
<controls:GraphPresenter
    IsCollection="True"
    RequestBuilder="{x:Bind MessagesRequestBuilder, Mode=OneWay}"
    ResponseType="graph:Message">
    <controls:GraphPresenter.ContentTemplate>
        <DataTemplate>
            ...
        </DataTemplate>
    </controls:GraphPresenter.ContentTemplate>
</controls:GraphPresenter>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant