fix(ui): do not display negative remaining quota (#1859)

* fix(ui): do not display negative remaining quota

* fix: correct remaining quota count on API side
pull/1860/head
TheCatLady 4 years ago committed by GitHub
parent 11378549c6
commit 3841fb06eb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -307,7 +307,7 @@ export class User {
limit: movieQuotaLimit, limit: movieQuotaLimit,
used: movieQuotaUsed, used: movieQuotaUsed,
remaining: movieQuotaLimit remaining: movieQuotaLimit
? movieQuotaLimit - movieQuotaUsed ? Math.max(0, movieQuotaLimit - movieQuotaUsed)
: undefined, : undefined,
restricted: restricted:
movieQuotaLimit && movieQuotaLimit - movieQuotaUsed <= 0 movieQuotaLimit && movieQuotaLimit - movieQuotaUsed <= 0
@ -318,7 +318,9 @@ export class User {
days: tvQuotaDays, days: tvQuotaDays,
limit: tvQuotaLimit, limit: tvQuotaLimit,
used: tvQuotaUsed, used: tvQuotaUsed,
remaining: tvQuotaLimit ? tvQuotaLimit - tvQuotaUsed : undefined, remaining: tvQuotaLimit
? Math.max(0, tvQuotaLimit - tvQuotaUsed)
: undefined,
restricted: restricted:
tvQuotaLimit && tvQuotaLimit - tvQuotaUsed <= 0 ? true : false, tvQuotaLimit && tvQuotaLimit - tvQuotaUsed <= 0 ? true : false,
}, },

@ -59,18 +59,14 @@ const QuotaDisplay: React.FC<QuotaDisplayProps> = ({
<div className="flex items-center"> <div className="flex items-center">
<ProgressCircle <ProgressCircle
className="w-8 h-8" className="w-8 h-8"
progress={Math.max( progress={Math.round(
0, ((remaining ?? quota?.remaining ?? 0) / (quota?.limit ?? 1)) * 100
Math.round(
((remaining ?? quota?.remaining ?? 0) / (quota?.limit ?? 1)) * 100
)
)} )}
useHeatLevel useHeatLevel
/> />
<div <div
className={`flex items-end ${ className={`flex items-end ${
Math.max(0, remaining ?? quota?.remaining ?? 0) === 0 || (remaining ?? quota?.remaining ?? 0) <= 0 || quota?.restricted
quota?.restricted
? 'text-red-500' ? 'text-red-500'
: '' : ''
}`} }`}
@ -79,7 +75,7 @@ const QuotaDisplay: React.FC<QuotaDisplayProps> = ({
{overLimit !== undefined {overLimit !== undefined
? intl.formatMessage(messages.notenoughseasonrequests) ? intl.formatMessage(messages.notenoughseasonrequests)
: intl.formatMessage(messages.requestsremaining, { : intl.formatMessage(messages.requestsremaining, {
remaining: Math.max(0, remaining ?? quota?.remaining ?? 0), remaining: remaining ?? quota?.remaining ?? 0,
type: intl.formatMessage( type: intl.formatMessage(
mediaType === 'movie' ? messages.movie : messages.season mediaType === 'movie' ? messages.movie : messages.season
), ),

@ -134,13 +134,10 @@ const UserProfile: React.FC = () => {
{quota.movie.limit ? ( {quota.movie.limit ? (
<> <>
<ProgressCircle <ProgressCircle
progress={Math.max( progress={Math.round(
0, ((quota?.movie.remaining ?? 0) /
Math.round( (quota?.movie.limit ?? 1)) *
((quota?.movie.remaining ?? 0) / 100
(quota?.movie.limit ?? 1)) *
100
)
)} )}
useHeatLevel useHeatLevel
className="w-8 h-8 mr-2" className="w-8 h-8 mr-2"
@ -193,13 +190,10 @@ const UserProfile: React.FC = () => {
{quota.tv.limit ? ( {quota.tv.limit ? (
<> <>
<ProgressCircle <ProgressCircle
progress={Math.max( progress={Math.round(
0, ((quota?.tv.remaining ?? 0) /
Math.round( (quota?.tv.limit ?? 1)) *
((quota?.tv.remaining ?? 0) / 100
(quota?.tv.limit ?? 1)) *
100
)
)} )}
useHeatLevel useHeatLevel
className="w-8 h-8 mr-2" className="w-8 h-8 mr-2"

Loading…
Cancel
Save