mirror of
https://github.com/YouXam/claude-code-usage-dashboard.git
synced 2026-03-22 12:33:47 +08:00
feat: select the most recent historical period by default
This commit is contained in:
@@ -66,7 +66,10 @@ export function HistoricalPeriods({ periods, apiKey, userId }: HistoricalPeriods
|
|||||||
setPeriodOptions(initialOptions);
|
setPeriodOptions(initialOptions);
|
||||||
|
|
||||||
if (!selectedPeriod && initialOptions.length > 0) {
|
if (!selectedPeriod && initialOptions.length > 0) {
|
||||||
setSelectedPeriod(initialOptions[0].period);
|
const lastOption = initialOptions[initialOptions.length - 1];
|
||||||
|
if (lastOption) {
|
||||||
|
setSelectedPeriod(lastOption.period);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fetch costs individually to update progressively
|
// Fetch costs individually to update progressively
|
||||||
@@ -74,6 +77,8 @@ export function HistoricalPeriods({ periods, apiKey, userId }: HistoricalPeriods
|
|||||||
|
|
||||||
for (let i = 0; i < periods.length; i++) {
|
for (let i = 0; i < periods.length; i++) {
|
||||||
const period = periods[i];
|
const period = periods[i];
|
||||||
|
if (!period) continue;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await fetch(`/api/periods/${period.index}/summary`, {
|
const response = await fetch(`/api/periods/${period.index}/summary`, {
|
||||||
headers: { 'X-API-Key': apiKey },
|
headers: { 'X-API-Key': apiKey },
|
||||||
@@ -102,7 +107,10 @@ export function HistoricalPeriods({ periods, apiKey, userId }: HistoricalPeriods
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (periods.length > 0 && !selectedPeriod) {
|
if (periods.length > 0 && !selectedPeriod) {
|
||||||
setSelectedPeriod(periods[0] || null); // Select the most recent historical period
|
const lastPeriod = periods[periods.length - 1];
|
||||||
|
if (lastPeriod) {
|
||||||
|
setSelectedPeriod(lastPeriod); // Select the most recent historical period
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}, [periods]);
|
}, [periods]);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user