コード例 #1
0
        public override async Task OnNavigatedToAsync(object parameter, NavigationMode mode, IDictionary <string, object> suspensionState)
        {
            id = (suspensionState.ContainsKey(nameof(id))) ? (long)suspensionState[nameof(id)] : (long)parameter;
            //TODO: Should be a way to optimize this so it isn't so slow to get tournament matches. Might need to do on manager level
            //1) Make this function, GetMatchesForTournament, asyncrhonous and give it a delegate as a parameter. The delegate will refer to
            //a function in this class that will update the value of Tournament.Matches so that it can be done after page load
            //2) Implement the cache so getting individual team profiles is much less taxing and doesn't require you to call the API twice for every match
            var pastMatches     = tournamentManager.GetMatchesForTournament(id);
            var liveJsonMatches = tournamentManager.GetLiveTournamentGames().Where(t => t.Tournament.ID == id);
            ObservableCollection <MatchModel> matches     = new ObservableCollection <MatchModel>();
            ObservableCollection <MatchModel> liveMatches = new ObservableCollection <MatchModel>();

            foreach (var match in liveJsonMatches)
            {
                liveMatches.Add(convertMatchToMatchModel(match, true));
            }
            foreach (var match in pastMatches)
            {
                matches.Add(convertMatchToMatchModel(match, false));
            }
            LiveMatches = liveMatches;
            Tournament  = new TournamentModel()
            {
                ID      = id,
                Name    = liveJsonMatches.First().Tournament.Name,
                Matches = matches,
            };
            //TODO: Disable whatever the loading gif you create
            await Task.CompletedTask;
        }