AuthorBuddy/Components/Pages/Editor.razor
2026-05-16 16:13:35 +02:00

123 lines
3.4 KiB
Text

@page "/editor"
@page "/editor/{action}"
@page "/editor/{action}/{projectId:int}"
@inject IOllamaService OllamaService
@inject IProjectService ProjectService
@inject NavigationManager Navigation
<PageTitle>Editor - Author Buddy</PageTitle>
<div class="editor-container">
<textarea @bind="editorContent" placeholder="Schreibe hier deinen Text..."></textarea>
<div class="editor-toolbar">
<span style="flex: 1; font-size: 12px; color: var(--border-color);">
@statusText
</span>
@if (isChecking)
{
<progress value="@checkProgress" max="100"></progress>
}
<button @onclick="CheckStyle" disabled="@isChecking">
Stil prüfen
</button>
<button @onclick="SpellCheck" disabled="@isChecking">
Rechtschreibung prüfen
</button>
<button @onclick="RagSearch">
Fakten suchen (RAG)
</button>
</div>
</div>
@if (!string.IsNullOrEmpty(analysisResult))
{
<div style="border-top: 2px solid var(--border-color); padding: 12px; max-height: 300px; overflow-y: auto;">
<h4 style="margin-bottom: 8px;">Ergebnis:</h4>
<div style="white-space: pre-wrap; font-size: 13px; line-height: 1.5;">@analysisResult</div>
</div>
}
@code {
[Parameter]
public string? Action { get; set; }
[Parameter]
public int? ProjectId { get; set; }
private string editorContent = string.Empty;
private string statusText = "Bereit";
private bool isChecking;
private double checkProgress;
private string analysisResult = string.Empty;
protected override async Task OnInitializedAsync()
{
if (Action == "newproject")
{
// The native folder dialog isn't available in Blazor.
// In a real app, you'd provide a form to enter project name and path.
statusText = "Bitte nutze die Einstellungen zum Erstellen eines neuen Projekts.";
}
}
private async Task CheckStyle()
{
if (string.IsNullOrWhiteSpace(editorContent)) return;
isChecking = true;
statusText = "Ollama analysiert Stil...";
checkProgress = 50;
try
{
//analysisResult = await OllamaService.StreamStyleCheckAsync(editorContent);
}
catch (Exception ex)
{
analysisResult = $"Fehler: {ex.Message}";
}
finally
{
statusText = "Bereit";
isChecking = false;
checkProgress = 0;
}
}
private async Task SpellCheck()
{
if (string.IsNullOrWhiteSpace(editorContent)) return;
isChecking = true;
statusText = "Ollama prüft Rechtschreibung...";
checkProgress = 50;
try
{
//analysisResult = await OllamaService.QuickSpellCheckAsync(editorContent);
}
catch (Exception ex)
{
analysisResult = $"Fehler: {ex.Message}";
}
finally
{
statusText = "Bereit";
isChecking = false;
checkProgress = 0;
}
}
private async Task RagSearch()
{
if (string.IsNullOrWhiteSpace(editorContent)) return;
isChecking = true;
statusText = "Suche verwandte Fakten...";
await Task.Delay(500);
analysisResult = "RAG-Suche: Stelle sicher, dass ein Projekt geladen und indexiert wurde.";
statusText = "Bereit";
isChecking = false;
}
}