Exemplo n.º 1
0
        protected override async Task OnInitializedAsync()
        {
            var response = await AwsJsInterop.GraphQlAsync <CompetitionList>(Queries.LIST_COMPETITIONS);

            CompetitionList = response.ListCompetitions.Items;
        }
Exemplo n.º 2
0
        protected override async Task OnAfterRenderAsync(bool firstRender)
        {
            if (firstRender)
            {
                var config = new AwsConfig
                {
                    Aws_cognito_identity_pool_id = "eu-west-2:5ad8c79a-2cdc-4da4-a94c-1c42becdf301",
                    Aws_cognito_region           = "eu-west-2",
                    Aws_user_pools_id            = "eu-west-2_MUFO3Qdac",
                    Aws_user_pools_web_client_id = "1ou6jkhe2u8j7sj14rek4a6mcq",
                    Oauth = new AwsOAuth
                    {
                        Domain = "football-championship-dev.auth.eu-west-2.amazoncognito.com",
                        Scope  = new string[]
                        {
                            "phone",
                            "email",
                            "openid",
                            "profile",
                            "aws.cognito.signin.user.admin"
                        },
                        RedirectSignIn  = NavigationManager.BaseUri,
                        RedirectSignOut = NavigationManager.BaseUri,
                        ResponseType    = "code"
                    },
                    FederationTarget               = "COGNITO_USER_POOLS",
                    Aws_appsync_graphqlEndpoint    = "https://pod5c66d6ze73b62evt7xqpn4q.appsync-api.eu-west-2.amazonaws.com/graphql",
                    Aws_appsync_region             = "eu-west-2",
                    Aws_appsync_authenticationType = "AMAZON_COGNITO_USER_POOLS"
                };
                await AwsJsInterop.ConfigureAsync(config);

                await AwsJsInterop.ListenAsync();

                if (AwsHelper.IsConnected)
                {
                    await BrowserJsInterop.NotificationOptIn();

                    var matches = new List <Match>();
                    GraphQlSubscriber.MatchUpdated += async(e, match) =>
                    {
                        if (match.MatchTeams?.Items == null ||
                            match.Scores == null)
                        {
                            return;
                        }

                        var homeTeam  = match.MatchTeams.Items.First(t => t.IsHome).Team;
                        var awayTeam  = match.MatchTeams.Items.First(t => !t.IsHome).Team;
                        var homeScore = match.Scores.First(s => s.IsHome).Value;
                        var awayScore = match.Scores.First(s => !s.IsHome).Value;

                        if (!matches.Any(m => m.Id == match.Id))
                        {
                            matches.Add(match);
                            return;
                        }

                        var started = matches.First(m => m.Id == match.Id);

                        var message = $"{homeTeam.LocalizedNames.GetLocalizedValue()} - {awayTeam.LocalizedNames.GetLocalizedValue()}\n{homeScore} - {awayScore}";

                        if (match.IsFinished != started.IsFinished)
                        {
                            started.IsFinished = match.IsFinished;
                            await BrowserJsInterop.Notify(Resources["Finished"], message);

                            return;
                        }

                        foreach (var score in match.Scores)
                        {
                            if (started.Scores.Any(s => s.IsHome == score.IsHome && s.Value != score.Value))
                            {
                                started.Scores = match.Scores;
                                await BrowserJsInterop.Notify("Gooooal!", message);

                                return;
                            }
                        }
                    };
                    await AwsJsInterop.GraphSubscribeAsync(Subscriptions.ON_UPDATE_MATCH, GraphQlSubscriber, nameof(GraphQlSubscriber.OnMatchUpdated));
                }
            }
            await base.OnAfterRenderAsync(firstRender);
        }