Skip to content

Commit

Permalink
fix: correct remaining quota count on API side
Browse files Browse the repository at this point in the history
  • Loading branch information
TheCatLady committed Jun 30, 2021
1 parent c4d8d22 commit 8b94eca
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 29 deletions.
6 changes: 4 additions & 2 deletions server/entity/User.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
},
Expand Down
12 changes: 4 additions & 8 deletions src/components/RequestModal/QuotaDisplay/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
: ''
}`}
Expand All @@ -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
),
Expand Down
29 changes: 10 additions & 19 deletions src/components/UserProfile/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -150,10 +147,7 @@ const UserProfile: React.FC = () => {
limit: (
<span className="text-3xl font-semibold">
{intl.formatMessage(messages.limit, {
remaining: Math.max(
0,
quota.movie.remaining ?? 0
),
remaining: quota.movie.remaining,
limit: quota.movie.limit,
})}
</span>
Expand Down Expand Up @@ -196,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"
Expand All @@ -212,7 +203,7 @@ const UserProfile: React.FC = () => {
limit: (
<span className="text-3xl font-semibold">
{intl.formatMessage(messages.limit, {
remaining: Math.max(0, quota.tv.remaining ?? 0),
remaining: quota.tv.remaining,
limit: quota.tv.limit,
})}
</span>
Expand Down

0 comments on commit 8b94eca

Please sign in to comment.