fix: upload page
This commit is contained in:
parent
349abc2071
commit
a397de80e9
|
|
@ -1,6 +1,6 @@
|
||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import { useState, useEffect, useRef, DragEvent, ChangeEvent } from 'react';
|
import { useState, useEffect, useRef, useCallback, DragEvent, ChangeEvent } from 'react';
|
||||||
import { useApiKey } from '@/components/shared/ApiKeyWidget/apikey-context';
|
import { useApiKey } from '@/components/shared/ApiKeyWidget/apikey-context';
|
||||||
import { Section } from '@/components/shared/Section';
|
import { Section } from '@/components/shared/Section';
|
||||||
import { CodeExamplesWidget } from '@/components/demo/CodeExamplesWidget';
|
import { CodeExamplesWidget } from '@/components/demo/CodeExamplesWidget';
|
||||||
|
|
@ -235,13 +235,17 @@ export default function DemoUploadPage() {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleDownloadMeasured = (itemId: string, downloadMs: number) => {
|
const handleDownloadMeasured = useCallback((itemId: string, downloadMs: number) => {
|
||||||
setUploadHistory((prev) =>
|
setUploadHistory((prev) =>
|
||||||
prev.map((item) =>
|
prev.map((item) => {
|
||||||
item.id === itemId ? { ...item, downloadMs } : item
|
// Only update if this item doesn't have downloadMs yet (prevent re-measuring)
|
||||||
)
|
if (item.id === itemId && item.downloadMs === undefined) {
|
||||||
|
return { ...item, downloadMs };
|
||||||
|
}
|
||||||
|
return item;
|
||||||
|
})
|
||||||
);
|
);
|
||||||
};
|
}, []);
|
||||||
|
|
||||||
const generateUploadCodeExamples = (item: UploadHistoryItem, key: string, baseUrl: string) => {
|
const generateUploadCodeExamples = (item: UploadHistoryItem, key: string, baseUrl: string) => {
|
||||||
const fileName = item.originalName;
|
const fileName = item.originalName;
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import { useEffect } from 'react';
|
import { useEffect, useRef } from 'react';
|
||||||
import { ImageMetadataBar } from '../ImageMetadataBar';
|
import { ImageMetadataBar } from '../ImageMetadataBar';
|
||||||
import { useImageDownloadTime } from './useImageDownloadTime';
|
import { useImageDownloadTime } from './useImageDownloadTime';
|
||||||
import { usePageContext } from '@/contexts/page-context';
|
import { usePageContext } from '@/contexts/page-context';
|
||||||
|
|
@ -36,9 +36,13 @@ export const ImageCard = ({
|
||||||
measureDownloadTime ? imageUrl : null
|
measureDownloadTime ? imageUrl : null
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Track if we've already called onDownloadMeasured to prevent duplicate calls
|
||||||
|
const hasCalledCallback = useRef(false);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (downloadTime !== null && onDownloadMeasured) {
|
if (downloadTime !== null && onDownloadMeasured && !hasCalledCallback.current) {
|
||||||
onDownloadMeasured(downloadTime);
|
onDownloadMeasured(downloadTime);
|
||||||
|
hasCalledCallback.current = true;
|
||||||
}
|
}
|
||||||
}, [downloadTime, onDownloadMeasured]);
|
}, [downloadTime, onDownloadMeasured]);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue