public PullRequestsViewModel(ISessionService sessionService)
		{
            _sessionService = sessionService;
            Title = "Pull Requests";

            PullRequests = _pullRequests.CreateDerivedCollection(x => {
                    var vm = new PullRequestItemViewModel(x);
                    vm.GoToCommand.Subscribe(_ => {
                        var prViewModel = this.CreateViewModel<PullRequestViewModel>();
                        prViewModel.Init(RepositoryOwner, RepositoryName, x.Number, x);
                        NavigateTo(prViewModel);

                        prViewModel.WhenAnyValue(y => y.Issue.State)
                            .DistinctUntilChanged()
                            .Skip(1)
                            .Subscribe(y => LoadCommand.ExecuteIfCan());
                    });
                    return vm;
                },
                filter: x => x.Title.ContainsKeyword(SearchKeyword),
                signalReset: this.WhenAnyValue(x => x.SearchKeyword));

            LoadCommand = ReactiveCommand.CreateAsyncTask(async t => {
                _pullRequests.Reset(await RetrievePullRequests());
            });

            this.WhenAnyValue(x => x.SelectedFilter).Skip(1).Subscribe(_ => {
                _pullRequests.Clear();
                LoadCommand.ExecuteIfCan();
            });
		}
Beispiel #2
0
        public PullRequestsViewModel(ISessionService sessionService)
        {
            _sessionService = sessionService;
            Title           = "Pull Requests";

            PullRequests = _pullRequests.CreateDerivedCollection(x => {
                var vm = new PullRequestItemViewModel(x);
                vm.GoToCommand.Subscribe(_ => {
                    var prViewModel = this.CreateViewModel <PullRequestViewModel>();
                    prViewModel.Init(RepositoryOwner, RepositoryName, x.Number, x);
                    NavigateTo(prViewModel);

                    prViewModel.WhenAnyValue(y => y.Issue.State)
                    .DistinctUntilChanged()
                    .Skip(1)
                    .Subscribe(y => LoadCommand.ExecuteIfCan());
                });
                return(vm);
            },
                                                                 filter: x => x.Title.ContainsKeyword(SearchKeyword),
                                                                 signalReset: this.WhenAnyValue(x => x.SearchKeyword));

            LoadCommand = ReactiveCommand.CreateAsyncTask(async t => {
                _pullRequests.Reset(await RetrievePullRequests());
            });

            this.WhenAnyValue(x => x.SelectedFilter).Skip(1).Subscribe(_ => {
                _pullRequests.Clear();
                LoadCommand.ExecuteIfCan();
            });
        }
        public PullRequestsViewModel(ISessionService applicationService)
		{
            Title = "Pull Requests";

            var pullRequests = new ReactiveList<PullRequestModel>();
            PullRequests = pullRequests.CreateDerivedCollection(x => {
                    var vm = new PullRequestItemViewModel(x);
                    vm.GoToCommand.Subscribe(_ => {
                        var prViewModel = this.CreateViewModel<PullRequestViewModel>();
                        prViewModel.Init(RepositoryOwner, RepositoryName, (int)x.Number);
                        NavigateTo(prViewModel);

                        prViewModel.WhenAnyValue(y => y.Issue.State)
                            .DistinctUntilChanged()
                            .Skip(1)
                            .Subscribe(y => LoadCommand.ExecuteIfCan());
                    });
                    return vm;
                },
                filter: x => x.Title.ContainsKeyword(SearchKeyword),
                signalReset: this.WhenAnyValue(x => x.SearchKeyword));

            LoadCommand = ReactiveCommand.CreateAsyncTask(t =>
            {
                var state = SelectedFilter == 0 ? "open" : "closed";
			    var request = applicationService.Client.Users[RepositoryOwner].Repositories[RepositoryName].PullRequests.GetAll(state: state);
                return pullRequests.SimpleCollectionLoad(request, 
                    x => LoadMoreCommand = x == null ? null : ReactiveCommand.CreateAsyncTask(_ => x()));
            });

            this.WhenAnyValue(x => x.SelectedFilter).Skip(1).Subscribe(_ => 
            {
                pullRequests.Clear();
                LoadCommand.ExecuteIfCan();
            });
		}