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

feat(desktopui): re-triggers search when account is switched & popula… #128

Merged
merged 1 commit into from Dec 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
46 changes: 44 additions & 2 deletions DesktopUI/DesktopUI/Streams/StreamCreateDialogViewModel.cs
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Threading.Tasks;
using MaterialDesignThemes.Wpf;
using Speckle.Core.Api;
using Speckle.Core.Credentials;
Expand Down Expand Up @@ -32,8 +33,22 @@ public StreamCreateDialogViewModel(IEventAggregator events, StreamsRepository st
}

private readonly StreamsRepository _streamsRepo;

private readonly AccountsRepository _acctRepo;

public override Account AccountToSendFrom
{
get => _accountToSendFrom;
set
{
SetAndNotify(ref _accountToSendFrom, value);

_latestStreams = null;
StreamSearchResults?.Clear();
SearchForStreams();
}
}

public ISnackbarMessageQueue Notifications
{
get => _notifications;
Expand Down Expand Up @@ -113,6 +128,8 @@ public string StreamQuery
}
}



private BindableCollection<Stream> _streamSearchResults;

public BindableCollection<Stream> StreamSearchResults
Expand All @@ -129,13 +146,38 @@ public bool HasSearchResults
get => StreamSearchResults != null && StreamSearchResults.Count > 0 ? true : false;
}

private List<Stream> _latestStreams;

private async Task<List<Stream>> GetLatestStreams()
{
if (_latestStreams == null)
{
var client = new Client(AccountToSendFrom);
_latestStreams = await client.StreamsGet(3);
}
return _latestStreams;
}

private async void SearchForStreams()
{
if (StreamQuery == null || StreamQuery.Length <= 2)
//Show latest 3 streams if query field is empty
if (string.IsNullOrEmpty(StreamQuery))
{
try
{
StreamSearchResults = new BindableCollection<Stream>(await GetLatestStreams());
}
catch
{
StreamSearchResults?.Clear();
}
return;
}


if (StreamQuery.Length <= 2)
return;

try
{
var client = new Client(AccountToSendFrom);
Expand Down Expand Up @@ -176,7 +218,7 @@ public async void AddNewStream()
}

StreamToCreate = await _streamsRepo.GetStream(streamId, AccountToSendFrom);

StreamState = new StreamState(client, StreamToCreate);
Bindings.AddNewStream(StreamState);

Expand Down
18 changes: 9 additions & 9 deletions DesktopUI/DesktopUI/Utils/StreamDialogBase.cs
Expand Up @@ -21,9 +21,9 @@ public int SelectedSlide
set => SetAndNotify(ref _selectedSlide, value);
}

private Account _accountToSendFrom = AccountManager.GetDefaultAccount();
internal Account _accountToSendFrom = AccountManager.GetDefaultAccount();

public Account AccountToSendFrom
public virtual Account AccountToSendFrom
{
get => _accountToSendFrom;
set => SetAndNotify(ref _accountToSendFrom, value);
Expand Down Expand Up @@ -95,13 +95,13 @@ public string UserQuery
{
SetAndNotify(ref _userQuery, value);

if ( value == "" )
if (value == "")
{
SelectedUser = null;
UserSearchResults?.Clear();
}

if ( SelectedUser != null ) return;
if (SelectedUser != null) return;
SearchForUsers();
}
}
Expand All @@ -122,7 +122,7 @@ public User SelectedUser
set
{
SetAndNotify(ref _selectedUser, value);
if ( SelectedUser == null )
if (SelectedUser == null)
return;
UserQuery = SelectedUser.name;
AddCollabToCollection(SelectedUser);
Expand All @@ -131,7 +131,7 @@ public User SelectedUser

public async void SearchForUsers()
{
if ( UserQuery == null || UserQuery.Length <= 2 )
if (UserQuery == null || UserQuery.Length <= 2)
return;

try
Expand All @@ -140,7 +140,7 @@ public async void SearchForUsers()
var users = await client.UserSearch(UserQuery);
UserSearchResults = new BindableCollection<User>(users);
}
catch ( Exception e )
catch (Exception e)
{
// search prob returned no results
UserSearchResults?.Clear();
Expand All @@ -167,7 +167,7 @@ public BindableCollection<User> Collaborators

private void AddCollabToCollection(User user)
{
if ( Collaborators.All(c => c.id != user.id) )
if (Collaborators.All(c => c.id != user.id))
Collaborators.Add(user);
}

Expand All @@ -186,7 +186,7 @@ public void CloseDialog()

public class StreamRole
{
public StreamRole(string name, string description)
public StreamRole(string name, string description)
{
Name = name;
Role = $"stream:{name}";
Expand Down