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

[Sample] Show using OneDrive Recent Files in GraphPresenter #55

Closed
michael-hawker opened this issue Aug 8, 2020 · 1 comment · Fixed by #148
Closed

[Sample] Show using OneDrive Recent Files in GraphPresenter #55

michael-hawker opened this issue Aug 8, 2020 · 1 comment · Fixed by #148
Assignees
Labels
Milestone

Comments

@michael-hawker
Copy link
Member

michael-hawker commented Aug 8, 2020

Describe the problem this feature would solve

Want to have a OneDrive sample for the GraphPresenter.

Currently blocked on Graph SDK bug microsoftgraph/MSGraph-SDK-Code-Generator#266

Describe the solution

Current solution used old NotifyTaskCompletion pattern now replaced by Toolkit MVVM package. We should have a new solution built on that somehow or alternate method.

Original Sample:

<wgt:GraphPresenter RequestBuilder="{x:Bind providers:ProviderManager.Instance.GlobalProvider.Graph.Me.Drive.Recent(), Mode=OneWay}"
                                    ResponseType="graph:DriveItem"
                                    IsCollection="True">
  <wgt:GraphPresenter.ContentTemplate>
                        <DataTemplate>
                            <!-- Return result is a collection of DriveItem's as we used 'IsCollection', so bind that first. -->
                            <ScrollViewer HorizontalScrollMode="Disabled" VerticalScrollBarVisibility="Auto">
                                <ItemsControl ItemsSource="{Binding}">
                                    <ItemsControl.ItemTemplate>
                                        <DataTemplate x:DataType="graph:DriveItem">
                                            <StackPanel>
                                                <controls:ImageEx DataContext="{x:Bind RemoteItem, Converter={StaticResource OneDriveThumbnailConverter}}"
                                                                  PlaceholderSource="/Assets/FileIcon.png"
                                                                  Source="{Binding Result.Medium.Url}" Width="176" Height="176"/>
                                                <TextBlock Text="{Binding Name}"/>
                                                <TextBlock Text="{Binding Size, Converter={StaticResource FileSizeConverter}}"/>
                                            </StackPanel>
                                        </DataTemplate>
                                    </ItemsControl.ItemTemplate>
                                    <ItemsControl.ItemsPanel>
                                        <ItemsPanelTemplate>
                                            <controls:UniformGrid Columns="2" ColumnSpacing="8"/>
                                        </ItemsPanelTemplate>
                                    </ItemsControl.ItemsPanel>
                                </ItemsControl>
                            </ScrollViewer>
                        </DataTemplate>
  </wgt:GraphPresenter.ContentTemplate.
</wgt:GraphPresenter>

Original Converter:

if (value is RemoteItem ri)
            {
                // drives/${file.remoteItem.parentReference.driveId}/items/${file.remoteItem.id}/thumbnails/0/medium
                var provider = ProviderManager.Instance.GlobalProvider;
                if (provider != null && provider.Graph != null)
                {
                    return new NotifyTaskCompletion<ThumbnailSet>(provider.Graph.Drives[ri.ParentReference.DriveId].Items[ri.Id].Thumbnails["0"].Request().GetAsync());
                }
            }

New idea for converter (thanks @Sergio0694):

var command = new AsyncRelayCommand(async () =>
{
    var data = await provider...GetAsync();
    return data.Medium.Url;
});
command.Execute(); // Start loading immediately
return command;
<controls:ImageEx
    DataContext="{x:Bind RemoteItem, Converter={StaticResource OneDriveThumbnailConverter}}"
    Source="{Binding ExecutionTask, Converter={StaticResource TaskResultConverter}}"/>

I think we can also just x:Bind directly to the helper function for the ToFileSizeString too.

@michael-hawker michael-hawker added documentation 📃 Improvements or additions to documentation enhancement ✨ New feature or request labels Aug 8, 2020
@michael-hawker michael-hawker added this to the Initial Release milestone Aug 8, 2020
michael-hawker added a commit that referenced this issue Aug 8, 2020
(they need re-work see #55)
Also updated Teams sample messages to remove HTML tags for now.
@Sergio0694
Copy link
Member

Also just for reference, in case you really wanted to keep using the NotifyTaskCompletion<T> syntax for the project (making the type internal, so that'd be fine), this is an example of a simple async box type you can write with the MVVM Toolkit:

internal sealed class AsyncResult<TResult> : ObservableObject
{
    private readonly Task<TResult> task;

    public AsyncResult(Task<TResult> task)
    {
        SetPropertyAndNotifyOnCompletion(ref this.task, () => this.task, task, nameof(ResultOrDefault));
    }

    public TResult ResultOrDefault => this.task.GetResultOrDefault();
}

Then you could do:

// Converter
return new AsyncResult<ThumbnailSet>(provider...GetAsync());
<controls:ImageEx
    DataContext="{x:Bind RemoteItem, Converter={StaticResource OneDriveThumbnailConverter}}"
    Source="{Binding ResultOrDefault.Medium.Url}"/>

Small note: that GetResultOrDefault extension is from the base Microsoft.Toolkit package.

Both approaches should work just fine, so as long as this code is internal you can just pick whatever you prefer! 😊

@shweaver-MSFT shweaver-MSFT removed this from the Initial Release milestone Apr 13, 2021
@ghost ghost added the In-PR 🚀 label Aug 26, 2021
@shweaver-MSFT shweaver-MSFT added this to the 7.1.0 milestone Aug 27, 2021
@shweaver-MSFT shweaver-MSFT self-assigned this Aug 27, 2021
@ghost ghost added Completed 🔥 and removed In-PR 🚀 labels Aug 31, 2021
@ghost ghost locked as resolved and limited conversation to collaborators Nov 3, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants