feat(ui): add ListSettingsModalViewModel
This commit is contained in:
@@ -79,6 +79,7 @@ sealed class Program
|
|||||||
sc.AddTransient<WorktreeModalViewModel>();
|
sc.AddTransient<WorktreeModalViewModel>();
|
||||||
sc.AddTransient<SettingsModalViewModel>();
|
sc.AddTransient<SettingsModalViewModel>();
|
||||||
sc.AddTransient<MergeModalViewModel>();
|
sc.AddTransient<MergeModalViewModel>();
|
||||||
|
sc.AddTransient<ListSettingsModalViewModel>();
|
||||||
|
|
||||||
// Islands shell VMs
|
// Islands shell VMs
|
||||||
sc.AddSingleton<ListsIslandViewModel>(sp =>
|
sc.AddSingleton<ListsIslandViewModel>(sp =>
|
||||||
|
|||||||
@@ -0,0 +1,96 @@
|
|||||||
|
using System.Collections.ObjectModel;
|
||||||
|
using ClaudeDo.Data.Models;
|
||||||
|
using ClaudeDo.Ui.Services;
|
||||||
|
using CommunityToolkit.Mvvm.ComponentModel;
|
||||||
|
using CommunityToolkit.Mvvm.Input;
|
||||||
|
|
||||||
|
namespace ClaudeDo.Ui.ViewModels.Modals;
|
||||||
|
|
||||||
|
public sealed partial class ListSettingsModalViewModel : ViewModelBase
|
||||||
|
{
|
||||||
|
private readonly WorkerClient _worker;
|
||||||
|
|
||||||
|
public string ListId { get; set; } = "";
|
||||||
|
|
||||||
|
[ObservableProperty] private string _name = "";
|
||||||
|
[ObservableProperty] private string _workingDir = "";
|
||||||
|
[ObservableProperty] private string _defaultCommitType = "chore";
|
||||||
|
|
||||||
|
[ObservableProperty] private string _selectedModel = "(default)";
|
||||||
|
[ObservableProperty] private string _systemPrompt = "";
|
||||||
|
[ObservableProperty] private AgentInfo? _selectedAgent;
|
||||||
|
|
||||||
|
public ObservableCollection<string> ModelOptions { get; } = new()
|
||||||
|
{
|
||||||
|
"(default)", "sonnet", "opus", "haiku",
|
||||||
|
};
|
||||||
|
|
||||||
|
public ObservableCollection<string> CommitTypeOptions { get; } = new()
|
||||||
|
{
|
||||||
|
"chore", "feat", "fix", "refactor", "docs", "test", "ci", "perf", "style", "build",
|
||||||
|
};
|
||||||
|
|
||||||
|
public ObservableCollection<AgentInfo> Agents { get; } = new();
|
||||||
|
|
||||||
|
public Action? CloseAction { get; set; }
|
||||||
|
|
||||||
|
public ListSettingsModalViewModel(WorkerClient worker)
|
||||||
|
{
|
||||||
|
_worker = worker;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task LoadAsync(
|
||||||
|
string listId,
|
||||||
|
string name,
|
||||||
|
string? workingDir,
|
||||||
|
string defaultCommitType,
|
||||||
|
CancellationToken ct = default)
|
||||||
|
{
|
||||||
|
ListId = listId;
|
||||||
|
Name = name;
|
||||||
|
WorkingDir = workingDir ?? "";
|
||||||
|
DefaultCommitType = string.IsNullOrWhiteSpace(defaultCommitType) ? "chore" : defaultCommitType;
|
||||||
|
|
||||||
|
Agents.Clear();
|
||||||
|
Agents.Add(new AgentInfo("(none)", "", ""));
|
||||||
|
var agents = await _worker.GetAgentsAsync();
|
||||||
|
foreach (var a in agents) Agents.Add(a);
|
||||||
|
|
||||||
|
var config = await _worker.GetListConfigAsync(listId);
|
||||||
|
SelectedModel = string.IsNullOrWhiteSpace(config?.Model) ? "(default)" : config!.Model!;
|
||||||
|
SystemPrompt = config?.SystemPrompt ?? "";
|
||||||
|
SelectedAgent = string.IsNullOrWhiteSpace(config?.AgentPath)
|
||||||
|
? Agents[0]
|
||||||
|
: (Agents.FirstOrDefault(a => a.Path == config!.AgentPath) ?? Agents[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
[RelayCommand]
|
||||||
|
private async Task SaveAsync()
|
||||||
|
{
|
||||||
|
var model = SelectedModel == "(default)" ? null : SelectedModel;
|
||||||
|
var sp = string.IsNullOrWhiteSpace(SystemPrompt) ? null : SystemPrompt;
|
||||||
|
var ap = SelectedAgent is null || string.IsNullOrWhiteSpace(SelectedAgent.Path) ? null : SelectedAgent.Path;
|
||||||
|
|
||||||
|
await _worker.UpdateListAsync(new UpdateListDto(
|
||||||
|
ListId,
|
||||||
|
string.IsNullOrWhiteSpace(Name) ? "Untitled" : Name,
|
||||||
|
string.IsNullOrWhiteSpace(WorkingDir) ? null : WorkingDir,
|
||||||
|
DefaultCommitType));
|
||||||
|
|
||||||
|
await _worker.UpdateListConfigAsync(new UpdateListConfigDto(
|
||||||
|
ListId, model, sp, ap));
|
||||||
|
|
||||||
|
CloseAction?.Invoke();
|
||||||
|
}
|
||||||
|
|
||||||
|
[RelayCommand]
|
||||||
|
private void Cancel() => CloseAction?.Invoke();
|
||||||
|
|
||||||
|
[RelayCommand]
|
||||||
|
private void ResetAgentSettings()
|
||||||
|
{
|
||||||
|
SelectedModel = "(default)";
|
||||||
|
SystemPrompt = "";
|
||||||
|
SelectedAgent = Agents.Count > 0 ? Agents[0] : null;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user