Invite & Library Edit - Missing SideNav Code (#2322)
This commit is contained in:
parent
7c8fdd9ea8
commit
a3afa04be4
9 changed files with 139 additions and 66 deletions
|
@ -236,28 +236,13 @@ public class ReadingListService : IReadingListService
|
|||
public async Task<bool> UpdateReadingListItemPosition(UpdateReadingListPosition dto)
|
||||
{
|
||||
var items = (await _unitOfWork.ReadingListRepository.GetReadingListItemsByIdAsync(dto.ReadingListId)).ToList();
|
||||
ReorderItems(items, dto.ReadingListItemId, dto.ToPosition);
|
||||
OrderableHelper.ReorderItems(items, dto.ReadingListItemId, dto.ToPosition);
|
||||
|
||||
if (!_unitOfWork.HasChanges()) return true;
|
||||
|
||||
return await _unitOfWork.CommitAsync();
|
||||
}
|
||||
|
||||
private static void ReorderItems(List<ReadingListItem> items, int readingListItemId, int toPosition)
|
||||
{
|
||||
var item = items.Find(r => r.Id == readingListItemId);
|
||||
if (item != null)
|
||||
{
|
||||
items.Remove(item);
|
||||
items.Insert(toPosition, item);
|
||||
}
|
||||
|
||||
for (var i = 0; i < items.Count; i++)
|
||||
{
|
||||
items[i].Order = i;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes a certain reading list item from a reading list
|
||||
/// </summary>
|
||||
|
@ -477,7 +462,7 @@ public class ReadingListService : IReadingListService
|
|||
}
|
||||
else
|
||||
{
|
||||
ReorderItems(items, readingListItem.Id, order);
|
||||
OrderableHelper.ReorderItems(items, readingListItem.Id, order);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@ using API.DTOs.Dashboard;
|
|||
using API.DTOs.SideNav;
|
||||
using API.Entities;
|
||||
using API.Entities.Enums;
|
||||
using API.Helpers;
|
||||
using API.SignalR;
|
||||
using Kavita.Common;
|
||||
using Kavita.Common.Helpers;
|
||||
|
@ -127,7 +128,7 @@ public class StreamService : IStreamService
|
|||
if (stream.Order == dto.ToPosition) return;
|
||||
|
||||
var list = user!.DashboardStreams.ToList();
|
||||
ReorderItems(list, stream.Id, dto.ToPosition);
|
||||
OrderableHelper.ReorderItems(list, stream.Id, dto.ToPosition);
|
||||
user.DashboardStreams = list;
|
||||
|
||||
_unitOfWork.UserRepository.Update(user);
|
||||
|
@ -263,7 +264,7 @@ public class StreamService : IStreamService
|
|||
if (stream.Order == dto.ToPosition) return;
|
||||
|
||||
var list = user!.SideNavStreams.ToList();
|
||||
ReorderItems(list, stream.Id, dto.ToPosition);
|
||||
OrderableHelper.ReorderItems(list, stream.Id, dto.ToPosition);
|
||||
user.SideNavStreams = list;
|
||||
_unitOfWork.UserRepository.Update(user);
|
||||
|
||||
|
@ -340,33 +341,5 @@ public class StreamService : IStreamService
|
|||
await _unitOfWork.CommitAsync();
|
||||
}
|
||||
|
||||
private static void ReorderItems(List<AppUserDashboardStream> items, int itemId, int toPosition)
|
||||
{
|
||||
var item = items.Find(r => r.Id == itemId);
|
||||
if (item != null)
|
||||
{
|
||||
items.Remove(item);
|
||||
items.Insert(toPosition, item);
|
||||
}
|
||||
|
||||
for (var i = 0; i < items.Count; i++)
|
||||
{
|
||||
items[i].Order = i;
|
||||
}
|
||||
}
|
||||
|
||||
private static void ReorderItems(List<AppUserSideNavStream> items, int itemId, int toPosition)
|
||||
{
|
||||
var item = items.Find(r => r.Id == itemId);
|
||||
if (item != null)
|
||||
{
|
||||
items.Remove(item);
|
||||
items.Insert(toPosition, item);
|
||||
}
|
||||
|
||||
for (var i = 0; i < items.Count; i++)
|
||||
{
|
||||
items[i].Order = i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue