forked from AcaMate/AcaMate_Web
88 lines
3.3 KiB
C#
88 lines
3.3 KiB
C#
using Front.Program.Models;
|
|
using Front.Program.Services;
|
|
using Front.Program.ViewModels;
|
|
using Microsoft.AspNetCore.Components;
|
|
using Microsoft.AspNetCore.Components.Routing;
|
|
|
|
namespace Front.Program.Views.Academy;
|
|
|
|
public partial class AcademyIntro : ComponentBase, IDisposable
|
|
{
|
|
[Inject] NavigationManager Navigation { get; set; } = default!;
|
|
[Inject] StorageService StorageService { get; set; } = default!;
|
|
[Inject] QueryParamService QueryParamService { get; set; } = default!;
|
|
[Inject] UserStateService UserStateService { get; set; } = default!;
|
|
|
|
private bool _isProcessing = false;
|
|
|
|
|
|
protected Models.SimpleAcademy[] academyItems = Array.Empty<Models.SimpleAcademy>();
|
|
|
|
protected override async void OnInitialized()
|
|
{
|
|
Navigation.LocationChanged += HandleLocationChanged;
|
|
HandleLocationChanged(this, new LocationChangedEventArgs(Navigation.Uri, false));
|
|
if (!UserStateService.isFirstCheck) await UserStateService.GetUserDataAsync();
|
|
|
|
academyItems = new[]
|
|
{
|
|
new SimpleAcademy{ bid = "AA0000", business_name = "테스트 학원1"},
|
|
new SimpleAcademy{ bid = "AA0001", business_name = "테스트 학원2"},
|
|
new SimpleAcademy{ bid = "AA0002", business_name = "테스트 학원3"},
|
|
new SimpleAcademy{ bid = "AA0003", business_name = "테스트 학원4"},
|
|
new SimpleAcademy{ bid = "AA0004", business_name = "테스트 학원5"},
|
|
new SimpleAcademy{ bid = "AA0005", business_name = "테스트 학원6"},
|
|
new SimpleAcademy{ bid = "AA0006", business_name = "테스트 학원7"},
|
|
|
|
};
|
|
|
|
await InvokeAsync(StateHasChanged);
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
Navigation.LocationChanged -= HandleLocationChanged;
|
|
}
|
|
|
|
private async void HandleLocationChanged(object? sender, LocationChangedEventArgs e)
|
|
{
|
|
try
|
|
{
|
|
// 다중 실행 방지
|
|
if (_isProcessing) return;
|
|
_isProcessing = true;
|
|
|
|
var uri = Navigation.ToAbsoluteUri(Navigation.Uri);
|
|
Console.WriteLine($"리다이렉트된 URI: {uri}");
|
|
|
|
// 쿼리 파라미터가 있는 경우에만 처리
|
|
if (!string.IsNullOrEmpty(uri.Query))
|
|
{
|
|
var queryParam = QueryParamService.ParseQueryParam(uri);
|
|
await QueryParamService.AuthCheck(queryParam, StorageService);
|
|
|
|
// 유저 정보 확인하는거 (로그인 했으니 값 가져와야지)
|
|
await UserStateService.GetUserDataAsync();
|
|
|
|
// 쿼리 파라미터를 제거한 기본 URI로 리다이렉트
|
|
var baseUri = uri.GetLeftPart(UriPartial.Path);
|
|
Console.WriteLine($"리다이렉트할 URI: {baseUri}");
|
|
await InvokeAsync(StateHasChanged); // StateHasChanged를 호출하여 UI 업데이트
|
|
Navigation.NavigateTo(baseUri, forceLoad: false);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Console.WriteLine($"Error in HandleLocationChanged: {ex.Message}");
|
|
}
|
|
finally
|
|
{
|
|
_isProcessing = false;
|
|
}
|
|
}
|
|
|
|
protected void OnClickLogin()
|
|
{
|
|
Navigation.NavigateTo("/am/auth");
|
|
}
|
|
} |