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

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

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

Loading…
Cancel
Save