Skip to content

Commit

Permalink
Toggle off button
Browse files Browse the repository at this point in the history
  • Loading branch information
erri120 committed Feb 24, 2025
1 parent 7058a4e commit 67044fc
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/NexusMods.App.UI/Pages/CollectionDataProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,8 @@ private CompositeItemModel<EntityId> ToItemModel(
key: CollectionColumns.Actions.ManualDownloadComponentKey,
shouldAddObservable: baseShouldAddDownloadObservable.CombineLatest(isManualOnlyObservable, static (shouldAddDownload, isManualOnly) => shouldAddDownload && isManualOnly),
componentFactory: () => new CollectionComponents.ManualDownloadAction(
downloadEntity: download
downloadEntity: download,
isDownloadedObservable: statusObservable.Select(status => status.IsDownloaded())
)
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,21 +133,38 @@ public sealed class ManualDownloadAction : ReactiveR3Object, IItemModelComponent
{
public int CompareTo(ManualDownloadAction? other) => other is null ? 1 : 0;

public ManualDownloadAction(CollectionDownloadExternal.ReadOnly downloadEntity)
private readonly IDisposable _activationDisposable;
public ManualDownloadAction(CollectionDownloadExternal.ReadOnly downloadEntity, Observable<bool> isDownloadedObservable)
{
CommandOpenModal = new ReactiveCommand<Unit, CollectionDownloadExternal.ReadOnly>(_ => downloadEntity);
CommandOpenModal = isDownloadedObservable.Select(static isDownloaded => !isDownloaded).ToReactiveCommand<Unit, CollectionDownloadExternal.ReadOnly>(_ => downloadEntity);

_activationDisposable = this.WhenActivated((downloadEntity, isDownloadedObservable), static (self, state, disposables) =>
{
var (_, isDownloadedObservable) = state;

isDownloadedObservable.Subscribe(self, static (isDownloaded, self) =>
{
self._buttonText.Value = GetButtonText(isDownloaded);
}).AddTo(disposables);
});
}

private readonly BindableReactiveProperty<string> _buttonText = new(value: "");
public IReadOnlyBindableReactiveProperty<string> ButtonText => _buttonText;

public ReactiveCommand<Unit, CollectionDownloadExternal.ReadOnly> CommandOpenModal { get; }

private static string GetButtonText(bool isDownloaded) => isDownloaded ? "Downloaded" : "Manual download";

private bool _isDisposed;

protected override void Dispose(bool disposing)
{
if (!_isDisposed)
{
if (disposing)
{
CommandOpenModal.Dispose();
Disposable.Dispose(CommandOpenModal, ButtonText, _activationDisposable);
}

_isDisposed = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
Type="Secondary"
Fill="Strong"
LeftIcon="{x:Static icons:IconValues.Save}"
Text="Manual download"/>
Text="{CompiledBinding ButtonText.Value}"/>
</StackPanel>
</DataTemplate>
</controls:ComponentTemplate.DataTemplate>
Expand Down

0 comments on commit 67044fc

Please sign in to comment.