refactor: address gemini-code-assist feedback on quota display

- Simplifies conditional rendering logic in QuotaStatsInfo.
- Improves chronological sorting of reset times in Config using Date objects.
- Documents the Unix timestamp parsing heuristic in formatResetTime.
- Streamlines intermediate string assignments in the formatter.
This commit is contained in:
Spencer
2026-02-20 05:16:11 +00:00
parent 211a6fb50a
commit 9d195f0f31
3 changed files with 7 additions and 13 deletions
@@ -57,18 +57,9 @@ export const QuotaStatsInfo: React.FC<QuotaStatsInfoProps> = ({
? `Limit reached`
: percentage !== undefined
? `${percentage.toFixed(0)}%`
: remaining !== undefined && remaining !== null
? `${remaining.toLocaleString()}`
: 'Limit reached'}
: 'Limit reached'}
</Text>
{remaining !== 0 && (
<Text>
{percentage !== undefined ||
(remaining !== undefined && remaining !== null)
? ' usage remaining'
: ''}
</Text>
)}
{remaining !== 0 && <Text> usage remaining</Text>}
{resetTime &&
`, ${(function (t) {
const formatted = formatResetTime(t);
+2 -1
View File
@@ -105,7 +105,8 @@ export const formatResetTime = (resetTime: string): string => {
if (isNaN(date.getTime())) {
const timestamp = parseInt(resetTime, 10);
if (!isNaN(timestamp)) {
// Could be seconds or milliseconds. If < 10^12, likely seconds.
// Heuristic: If the timestamp is less than 10^12, it is likely in seconds
// (as 10^12 ms is year 2001, while 10^12 s is far in the future).
date = new Date(timestamp < 10000000000 ? timestamp * 1000 : timestamp);
}
}
+3 -1
View File
@@ -1338,7 +1338,9 @@ export class Config {
// For reset time, take the one that is nearest in the future (soonest reset)
const resetTime = [proQuota?.resetTime, flashQuota?.resetTime]
.filter((t): t is string => !!t)
.sort()[0];
.map((t) => new Date(t))
.sort((a, b) => a.getTime() - b.getTime())[0]
?.toISOString();
return {
remaining: (proQuota?.remaining ?? 0) + (flashQuota?.remaining ?? 0),