@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
Change("Panel expanded")) Collapse=@(() => Change("Panel collapsed"))>
New site
@*
*@
@if (siteInfoList.Any())
{
Change("Panel expanded")) Collapse=@(() => Change("Panel collapsed"))>
Sites created
@{
if(siteInfoList.Count() > 0)
{
@(site.SiteName)
@(site.SiteName)
@site.DefaultUrl
Fefault color: @(site.DefaultColor)
Theme: @(site.TemplateId)
Edit
Migrate(site.Id, collectionName)" class="btn btn-secondary">Migrate
Manage content
Preview(site)" class="btn btn-secondary"> Preview
}
else
{
Let1s create your first website!
}
}
@siteInfoList.Count() Sites
@* foreach (var item in siteInfoList)
{
} *@
}
else
{
No sites created yet.
}
@code {
private IEnumerable siteInfoList = new List();
private SiteInfo newSite = new();
private string? userId;
private string? userName;
private AuthenticationState? authState;
int position = 1;
public string SessionId;
//TEMPORARY
private string collectionName = "seemgen-collection";
private string FinalSiteDescription;
private async Task HandleDescriptionGenerated(string[] desc)
{
newSite.UserId = userId;
FinalSiteDescription = desc[1];
newSite.SiteDescription = desc[1];
newSite.SiteName = desc[0];
newSite.Entity = desc[2];
newSite.Persona = desc[3];
newSite.DefaultLanguage = desc[4];
newSite.BrandLogoUrl = desc[5];
newSite.FacebookUrl = desc[6];
await HandleValidSubmit();
// You can now store it in SiteInfo.SiteDescription
// or prefill the full form with the rest of the properties
}
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!);
SessionId = SiteInfoService.SessionId;
// SiteInfoService.SessionId = SessionId;
}
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
if(result != null)
{
NavigationManager.NavigateTo($"/generate-content/{result.Id}");
}
}
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;
}
}