From e49771e5271c9e0afeb7389abf4c43f7c32eadd0 Mon Sep 17 00:00:00 2001 From: TheCatLady <52870424+TheCatLady@users.noreply.github.com> Date: Wed, 30 Jun 2021 11:01:36 -0400 Subject: [PATCH] fix: correct remaining quota count on API side --- server/entity/User.ts | 6 ++-- .../RequestModal/QuotaDisplay/index.tsx | 12 +++----- src/components/UserProfile/index.tsx | 29 +++++++------------ 3 files changed, 18 insertions(+), 29 deletions(-) diff --git a/server/entity/User.ts b/server/entity/User.ts index ed6fc4a6b8..766ef76f08 100644 --- a/server/entity/User.ts +++ b/server/entity/User.ts @@ -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, }, diff --git a/src/components/RequestModal/QuotaDisplay/index.tsx b/src/components/RequestModal/QuotaDisplay/index.tsx index 223540d5d6..c6e40b8c37 100644 --- a/src/components/RequestModal/QuotaDisplay/index.tsx +++ b/src/components/RequestModal/QuotaDisplay/index.tsx @@ -59,18 +59,14 @@ const QuotaDisplay: React.FC = ({
= ({ {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 ), diff --git a/src/components/UserProfile/index.tsx b/src/components/UserProfile/index.tsx index 6343c5fae2..6745877a86 100644 --- a/src/components/UserProfile/index.tsx +++ b/src/components/UserProfile/index.tsx @@ -134,13 +134,10 @@ const UserProfile: React.FC = () => { {quota.movie.limit ? ( <> { limit: ( {intl.formatMessage(messages.limit, { - remaining: Math.max( - 0, - quota.movie.remaining ?? 0 - ), + remaining: quota.movie.remaining ?? 0, limit: quota.movie.limit, })} @@ -196,13 +190,10 @@ const UserProfile: React.FC = () => { {quota.tv.limit ? ( <> { limit: ( {intl.formatMessage(messages.limit, { - remaining: Math.max(0, quota.tv.remaining ?? 0), + remaining: quota.tv.remaining, limit: quota.tv.limit, })}