< Summary

Class:UsersSearchPromptController
Assembly:BuilderProjectsPanel
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/BuilderInWorld/HUD/ProjectsPanelHUD/Scripts/UsersSearchPrompt/UsersSearchPromptController.cs
Covered lines:33
Uncovered lines:8
Coverable lines:41
Total lines:87
Line coverage:80.4% (33 of 41)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
UsersSearchPromptController(...)0%110100%
Dispose()0%220100%
Show()0%110100%
Hide()0%6200%
SetUsersInRolList(...)0%110100%
OnSearchText(...)0%220100%
OnShouldHidePrompt()0%2100%
OnAddUserPressed(...)0%6200%
OnRemoveUserPressed(...)0%6200%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/BuilderInWorld/HUD/ProjectsPanelHUD/Scripts/UsersSearchPrompt/UsersSearchPromptController.cs

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3using DCL.Helpers;
 4using UnityEngine;
 5
 6internal class UsersSearchPromptController : IDisposable
 7{
 8    private const int MAX_USERS_RESULT = 10;
 9
 10    public event Action<string> OnRemoveUser;
 11    public event Action<string> OnAddUser;
 12
 13    private readonly UsersSearchPromptView view;
 14    internal readonly UsersSearchUserViewsHandler userViewsHandler;
 15    private readonly UsersSearcher usersSearcher;
 16
 17    internal Promise<UserProfileModel[]> usersSearchPromise = null;
 18
 919    public UsersSearchPromptController(UsersSearchPromptView promptView)
 20    {
 921        view = promptView;
 922        view.SetIdleSearchTime(1.5f);
 23
 924        userViewsHandler = new UsersSearchUserViewsHandler(view.GetUsersBaseElement(), view.GetUserElementsParent());
 925        usersSearcher = new UsersSearcher();
 26
 927        view.OnSearchText += OnSearchText;
 928        view.OnShouldHide += OnShouldHidePrompt;
 929        userViewsHandler.OnAddUser += OnAddUserPressed;
 930        userViewsHandler.OnRemoveUser += OnRemoveUserPressed;
 931    }
 32
 33    public void Dispose()
 34    {
 935        view.OnSearchText -= OnSearchText;
 936        view.OnShouldHide -= OnShouldHidePrompt;
 937        userViewsHandler.OnAddUser -= OnAddUserPressed;
 938        userViewsHandler.OnRemoveUser -= OnRemoveUserPressed;
 39
 940        usersSearchPromise?.Dispose();
 941        userViewsHandler.Dispose();
 942        view.Dispose();
 943    }
 44
 45    public void Show()
 46    {
 147        view.ClearSearch();
 148        view.SetFriendListEmpty(true);
 149        view.Show();
 150    }
 51
 52    public void Hide()
 53    {
 054        view.Hide();
 055        usersSearchPromise?.Dispose();
 056    }
 57
 1058    public void SetUsersInRolList(List<string> usersId) { userViewsHandler.SetUsersInRolList(usersId); }
 59
 60    private void OnSearchText(string searchText)
 61    {
 262        usersSearchPromise?.Dispose();
 63
 264        view.ShowSearchSpinner();
 265        usersSearchPromise = usersSearcher.SearchUser(searchText, MAX_USERS_RESULT);
 266        usersSearchPromise.Then(
 67            result =>
 68            {
 169                view.ShowClearButton();
 170                if (result == null || result.Length == 0)
 71                {
 072                    view.SetFriendListEmpty(true);
 073                }
 74                else
 75                {
 176                    view.SetFriendListEmpty(false);
 177                    userViewsHandler.SetUserViewsList(result);
 78                }
 179            });
 280    }
 81
 082    private void OnShouldHidePrompt() { Hide(); }
 83
 084    private void OnAddUserPressed(string userId) { OnAddUser?.Invoke(userId); }
 85
 086    private void OnRemoveUserPressed(string userId) { OnRemoveUser?.Invoke(userId); }
 87}