<commit_before>﻿using Microsoft.AspNetCore.Blazor.Services;
using Microsoft.JSInterop;
using Money.Models;
using Neptuo;
using Neptuo.Models.Keys;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Money.Services
{
    internal class Navigator : NavigatorUrl, System.IDisposable
    {
        private readonly IUriHelper uri;

        public event Action<string> LocationChanged;

        public Navigator(IUriHelper uri)
        {
            Ensure.NotNull(uri, "uri");
            this.uri = uri;

            uri.OnLocationChanged += OnLocationChanged;
        }

        public void Dispose()
        {
            uri.OnLocationChanged -= OnLocationChanged;
        }

        private void OnLocationChanged(object sender, string e)
            => LocationChanged?.Invoke(e);

        private void OpenExternal(string url)
            => Interop.NavigateTo(url);

        public void Open(string url)
            => uri.NavigateTo(url);

        public void OpenSummary()
            => uri.NavigateTo(UrlSummary());

        public void OpenSummary(MonthModel month)
            => uri.NavigateTo(UrlSummary(month));

        public void OpenOverview(MonthModel month)
            => uri.NavigateTo(UrlOverview(month));

        public void OpenOverview(MonthModel month, IKey categoryKey)
            => uri.NavigateTo(UrlOverview(month, categoryKey));

        public void OpenSearch()
            => uri.NavigateTo(UrlSearch());

        public void OpenCategories()
            => uri.NavigateTo(UrlCategories());

        public void OpenCurrencies()
            => uri.NavigateTo(UrlCurrencies());

        public void OpenAbout()
            => uri.NavigateTo(UrlAbout());

        public void OpenUserManage()
            => uri.NavigateTo(UrlUserManage());

        public void OpenUserPassword()
            => uri.NavigateTo(UrlUserPassword());

        public void OpenLogin()
        {
            string loginUrl = UrlAccountLogin();
            string currentUrl = "/" + uri.ToBaseRelativePath(uri.GetBaseUri(), uri.GetAbsoluteUri());
            int indexOfReturnUrl = currentUrl.IndexOf("?returnUrl");
            if (indexOfReturnUrl >= 0)
                currentUrl = currentUrl.Substring(0, indexOfReturnUrl);

            if (loginUrl != currentUrl)
            {
                uri.NavigateTo($"{loginUrl}?returnUrl={currentUrl}");
            }
        }

        public void OpenRegister()
            => uri.NavigateTo(UrlAccountRegister());
    }
}<commit_msg>#218 - Skip redirect to login from register.<commit_after>﻿using Microsoft.AspNetCore.Blazor.Services;
using Microsoft.JSInterop;
using Money.Models;
using Neptuo;
using Neptuo.Models.Keys;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Money.Services
{
    internal class Navigator : NavigatorUrl, System.IDisposable
    {
        private readonly IUriHelper uri;

        public event Action<string> LocationChanged;

        public Navigator(IUriHelper uri)
        {
            Ensure.NotNull(uri, "uri");
            this.uri = uri;

            uri.OnLocationChanged += OnLocationChanged;
        }

        public void Dispose()
        {
            uri.OnLocationChanged -= OnLocationChanged;
        }

        private void OnLocationChanged(object sender, string e)
            => LocationChanged?.Invoke(e);

        private void OpenExternal(string url)
            => Interop.NavigateTo(url);

        public void Open(string url)
            => uri.NavigateTo(url);

        public void OpenSummary()
            => uri.NavigateTo(UrlSummary());

        public void OpenSummary(MonthModel month)
            => uri.NavigateTo(UrlSummary(month));

        public void OpenOverview(MonthModel month)
            => uri.NavigateTo(UrlOverview(month));

        public void OpenOverview(MonthModel month, IKey categoryKey)
            => uri.NavigateTo(UrlOverview(month, categoryKey));

        public void OpenSearch()
            => uri.NavigateTo(UrlSearch());

        public void OpenCategories()
            => uri.NavigateTo(UrlCategories());

        public void OpenCurrencies()
            => uri.NavigateTo(UrlCurrencies());

        public void OpenAbout()
            => uri.NavigateTo(UrlAbout());

        public void OpenUserManage()
            => uri.NavigateTo(UrlUserManage());

        public void OpenUserPassword()
            => uri.NavigateTo(UrlUserPassword());

        public void OpenLogin()
        {
            string loginUrl = UrlAccountLogin();
            string currentUrl = GetCurrentUrl();

            if (loginUrl != currentUrl && currentUrl != UrlAccountRegister())
                uri.NavigateTo($"{loginUrl}?returnUrl={currentUrl}");
        }

        private string GetCurrentUrl()
        {
            string currentUrl = "/" + uri.ToBaseRelativePath(uri.GetBaseUri(), uri.GetAbsoluteUri());
            int indexOfReturnUrl = currentUrl.IndexOf("?returnUrl");
            if (indexOfReturnUrl >= 0)
                currentUrl = currentUrl.Substring(0, indexOfReturnUrl);

            return currentUrl;
        }

        public void OpenRegister()
            => uri.NavigateTo(UrlAccountRegister());
    }
}
{'fraction_non_alphanumeric': 0.10221721157459601, 'fraction_numerical': 0.0013152950018789928, 'mean_word_length': 2.300061996280223, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7046988', 'n_tokens_mistral': 1411, 'n_tokens_neox': 1353, 'n_words': 294}