@page "/sites"
@attribute [Authorize]
@using BLAIzor.Components.Layout
@using BLAIzor.Models
@using BLAIzor.Services
@using Microsoft.AspNetCore.Components.Authorization
@layout AdminLayout
@inject ScopedContentService SiteInfoService
@inject ContentEditorService _contentEditorService
@inject NavigationManager NavigationManager
@inject AuthenticationStateProvider AuthenticationStateProvider
@inject CustomAuthenticationStateProvider CustomAuthProvider
@inject IJSRuntime JSRuntime
Your Sites
@code {
private IEnumerable siteInfoList = new List();
private SiteInfo newSite = new();
private string? userId;
private string? userName;
private AuthenticationState? authState;
int position = 1;
//TEMPORARY
private string collectionName = "seemgen-collection";
void Change(string text)
{
Console.Write($"{text}");
}
private void visit(SiteInfo site)
{
SiteInfoService.SelectedBrandName = site.SiteName;
SiteInfoService.SelectedSiteId = site.Id;
NavigationManager.NavigateTo(site.DefaultUrl, true);
}
private async Task Migrate(int siteId, string collectionName)
{
var result = await _contentEditorService.MigrateQdrantToContentItemsAsync(siteId, collectionName);
Console.WriteLine($"Migration result: {result}");
}
private async Task Preview(SiteInfo site)
{
string myUrl = $"/preview/{site.Id}";
try
{
await JSRuntime.InvokeVoidAsync("open", myUrl, "_blank");
}
catch (Exception ex)
{
Console.WriteLine($"Error opening new tab: {ex.Message}");
}
}
protected override async Task OnInitializedAsync()
{
authState = await AuthenticationStateProvider.GetAuthenticationStateAsync();
if (authState.User.Identity?.IsAuthenticated == true)
{
userId = CustomAuthProvider.GetUserId();
userName = CustomAuthProvider.GetUserName();
}
siteInfoList = await _contentEditorService.GetUserSitesAsync(userId!);
}
private async Task HandleValidSubmit()
{
newSite.UserId = userId;
newSite.TemplateId = 1;
newSite.DefaultUrl = await GenerateSubdomainAsync(newSite.SiteName);
newSite.VectorCollectionName = _contentEditorService.GetGeneratedVectorCollectionName(newSite);
var result = await _contentEditorService.AddSiteInfoAsync(newSite);
siteInfoList = await _contentEditorService.GetUserSitesAsync(userId!);
newSite = new(); // Reset the form
}
public async Task GenerateSubdomainAsync(string siteName)
{
var normalizedSiteName = siteName.ToLower()
.Replace(" ", "-")
.Replace("_", "-")
.Replace(".", "-");
var subdomain = $"{normalizedSiteName}.seemgen.com";
// var site = await SiteInfoService.GetSiteInfoByIdAsync(siteId);
// if (site != null)
// {
// site.DefaultUrl = subdomain;
// await SiteInfoService.UpdateSiteInfoAsync(site);
// }
return subdomain;
}
}