Skip to content

Commit

Permalink
Change DevicesForPage to field.
Browse files Browse the repository at this point in the history
  • Loading branch information
bitbound committed May 15, 2021
1 parent abcf486 commit 7d36b57
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 18 deletions.
3 changes: 1 addition & 2 deletions Server/Components/Devices/DevicesFrame.razor
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@
<option value="50">50</option>
<option value="100">100</option>
<option value="200">200</option>
<option value="500">500</option>
</select>
<span class="ml-1 small">per page</span>
</div>
Expand All @@ -79,7 +78,7 @@
</div>
</div>
<div id="deviceListDiv" class="p-2 mb-5">
@foreach (var device in DevicesForPage)
@foreach (var device in _devicesForPage)
{
<CascadingValue Value="this">
<DeviceCard @key="device.ID" Device="device" RemoteControlTargetLookup="_remoteControlTargetLookup" />
Expand Down
28 changes: 12 additions & 16 deletions Server/Components/Devices/DevicesFrame.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public partial class DevicesFrame : AuthComponentBase, IDisposable
private readonly List<Device> _allDevices = new();
private readonly string _deviceGroupAll = Guid.NewGuid().ToString();
private readonly string _deviceGroupNone = Guid.NewGuid().ToString();
private readonly List<Device> _devicesForPage = new();
private readonly List<DeviceGroup> _deviceGroups = new();
private readonly List<Device> _filteredDevices = new();
private readonly ConcurrentDictionary<string, RemoteControlTarget> _remoteControlTargetLookup = new();
Expand All @@ -54,22 +55,6 @@ public partial class DevicesFrame : AuthComponentBase, IDisposable
[Inject]
private IDataService DataService { get; set; }

private IEnumerable<Device> DevicesForPage
{
get
{
var appendDevices = _filteredDevices.Where(x => AppState.DevicesFrameSelectedDevices.Contains(x.ID));
var skipCount = (_currentPage - 1) * _devicesPerPage;
var devicesForPage = _filteredDevices
.Except(appendDevices)
.Skip(skipCount)
.Take(_devicesPerPage);


return appendDevices.Concat(devicesForPage);
}
}

[Inject]
private IJsInterop JsInterop { get; set; }

Expand Down Expand Up @@ -284,7 +269,18 @@ private void FilterDevices()
x.Platform?.Contains(_filter, StringComparison.OrdinalIgnoreCase) != true &&
x.Tags?.Contains(_filter, StringComparison.OrdinalIgnoreCase) != true);
}

var appendDevices = _filteredDevices.Where(x => AppState.DevicesFrameSelectedDevices.Contains(x.ID));
var skipCount = (_currentPage - 1) * _devicesPerPage;
var devicesForPage = _filteredDevices
.Except(appendDevices)
.Skip(skipCount)
.Take(_devicesPerPage);

_devicesForPage.Clear();
_devicesForPage.AddRange(devicesForPage);
}

}

private void PageDown()
Expand Down

0 comments on commit 7d36b57

Please sign in to comment.