Jump Bar Testing (#1302)

* Implemented a basic jump bar for the library view. This currently just interacts with existing pagination controls and is not inlined with infinite scroll yet. This is a first pass implementation.

* Refactored time estimates into the reading service.

* Cleaned up when the jump bar is shown to mimic pagination controls

* Cleanup up code in reader service.

* Scroll to card when selecting a jump key that is shown on the current page.

* Ensure estimated times always has the smaller number on left hand side.

* Fixed a bug with a missing vertical rule

* Fixed an off by 1 pixel for search overlay
This commit is contained in:
Joseph Milazzo 2022-05-30 16:50:12 -05:00 committed by GitHub
parent 64c0b5a71e
commit 742cfd3293
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
20 changed files with 319 additions and 120 deletions

View file

@ -6,6 +6,7 @@ using System.Threading.Tasks;
using API.Data;
using API.Data.Repositories;
using API.DTOs;
using API.DTOs.JumpBar;
using API.DTOs.Search;
using API.Entities;
using API.Entities.Enums;
@ -106,6 +107,16 @@ namespace API.Controllers
return Ok(await _unitOfWork.LibraryRepository.GetLibraryDtosAsync());
}
[HttpGet("jump-bar")]
public async Task<ActionResult<IEnumerable<JumpKeyDto>>> GetJumpBar(int libraryId)
{
var userId = await _unitOfWork.UserRepository.GetUserIdByUsernameAsync(User.GetUsername());
if (!await _unitOfWork.UserRepository.HasAccessToLibrary(libraryId, userId)) return BadRequest("User does not have access to library");
return Ok(_unitOfWork.LibraryRepository.GetJumpBarAsync(libraryId));
}
[Authorize(Policy = "RequireAdminRole")]
[HttpPost("grant-access")]
public async Task<ActionResult<MemberDto>> UpdateUserLibraries(UpdateLibraryForUserDto updateLibraryForUserDto)

View file

@ -639,25 +639,7 @@ namespace API.Controllers
[HttpGet("manual-read-time")]
public ActionResult<HourEstimateRangeDto> GetManualReadTime(int wordCount, int pageCount, bool isEpub)
{
if (isEpub)
{
return Ok(new HourEstimateRangeDto()
{
MinHours = (int) Math.Round((wordCount / ReaderService.MinWordsPerHour)),
MaxHours = (int) Math.Round((wordCount / ReaderService.MaxWordsPerHour)),
AvgHours = (int) Math.Round((wordCount / ReaderService.AvgWordsPerHour)),
HasProgress = false
});
}
return Ok(new HourEstimateRangeDto()
{
MinHours = (int) Math.Round((pageCount / ReaderService.MinPagesPerMinute / 60F)),
MaxHours = (int) Math.Round((pageCount / ReaderService.MaxPagesPerMinute / 60F)),
AvgHours = (int) Math.Round((pageCount / ReaderService.AvgPagesPerMinute / 60F)),
HasProgress = false
});
return Ok(_readerService.GetTimeEstimate(wordCount, pageCount, isEpub));
}
[HttpGet("read-time")]
@ -667,24 +649,8 @@ namespace API.Controllers
var series = await _unitOfWork.SeriesRepository.GetSeriesDtoByIdAsync(seriesId, userId);
var progress = (await _unitOfWork.AppUserProgressRepository.GetUserProgressForSeriesAsync(seriesId, userId)).ToList();
if (series.Format == MangaFormat.Epub)
{
return Ok(new HourEstimateRangeDto()
{
MinHours = (int) Math.Round((series.WordCount / ReaderService.MinWordsPerHour)),
MaxHours = (int) Math.Round((series.WordCount / ReaderService.MaxWordsPerHour)),
AvgHours = (int) Math.Round((series.WordCount / ReaderService.AvgWordsPerHour)),
HasProgress = progress.Any()
});
}
return Ok(new HourEstimateRangeDto()
{
MinHours = (int) Math.Round((series.Pages / ReaderService.MinPagesPerMinute / 60F)),
MaxHours = (int) Math.Round((series.Pages / ReaderService.MaxPagesPerMinute / 60F)),
AvgHours = (int) Math.Round((series.Pages / ReaderService.AvgPagesPerMinute / 60F)),
HasProgress = progress.Any()
});
return Ok(_readerService.GetTimeEstimate(series.WordCount, series.Pages, series.Format == MangaFormat.Epub,
progress.Any()));
}
@ -709,24 +675,12 @@ namespace API.Controllers
// Word count
var progressCount = chapters.Sum(c => c.WordCount);
var wordsLeft = series.WordCount - progressCount;
return Ok(new HourEstimateRangeDto()
{
MinHours = (int) Math.Round((wordsLeft / ReaderService.MinWordsPerHour)),
MaxHours = (int) Math.Round((wordsLeft / ReaderService.MaxWordsPerHour)),
AvgHours = (int) Math.Round((wordsLeft / ReaderService.AvgWordsPerHour)),
HasProgress = progressCount > 0
});
return _readerService.GetTimeEstimate(wordsLeft, 0, true, progressCount > 0);
}
var progressPageCount = progress.Sum(p => p.PagesRead);
var pagesLeft = series.Pages - progressPageCount;
return Ok(new HourEstimateRangeDto()
{
MinHours = (int) Math.Round((pagesLeft / ReaderService.MinPagesPerMinute / 60F)),
MaxHours = (int) Math.Round((pagesLeft / ReaderService.MaxPagesPerMinute / 60F)),
AvgHours = (int) Math.Round((pagesLeft / ReaderService.AvgPagesPerMinute / 60F)),
HasProgress = progressPageCount > 0
});
return _readerService.GetTimeEstimate(0, pagesLeft, false, progressPageCount > 0);
}
}