Refactor API hooks to remove infinite query support and update API client base URL
- Removed infinite query options and related functions from Trading212, User Registration, and User API files. - Updated API client base URLs in privateClient.ts and publicClient.ts to use environment variable for backend URL. - Refactored Downloader component to directly call API functions for video info retrieval instead of using a hook.
This commit is contained in:
@@ -1,25 +1,36 @@
|
||||
import { useState } from 'react';
|
||||
import { useApiDownloaderDownloadRetrieve } from '@/api/generated/public/downloader';
|
||||
import { apiDownloaderDownloadRetrieve, apiDownloaderDownloadCreate } from '@/api/generated/public/downloader';
|
||||
import { type VideoInfoResponse } from '@/api/generated/public/models';
|
||||
|
||||
|
||||
export default function Downloader() {
|
||||
const [videoUrl, setVideoUrl] = useState('');
|
||||
const [videoInfo, setVideoInfo] = useState<null | VideoInfoResponse>(null);
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
const [error, setError] = useState<null | { error: string }>(null);
|
||||
|
||||
// The hook needs: (params, options)
|
||||
// params = { url: string }
|
||||
// options = { query: { enabled: boolean } }
|
||||
const { data: videoInfo, isLoading, error } = useApiDownloaderDownloadRetrieve(
|
||||
{ url: videoUrl }, // 1st arg: parameters
|
||||
{
|
||||
query: {
|
||||
enabled: videoUrl.length > 10, // 2nd arg: query options (only fetch when URL is valid)
|
||||
}
|
||||
async function retriveVideoInfo() {
|
||||
setIsLoading(true);
|
||||
setError(null);
|
||||
try {
|
||||
const info = await apiDownloaderDownloadRetrieve({ url: videoUrl });
|
||||
setVideoInfo(info);
|
||||
} catch (err: any) {
|
||||
setError({ error: err.message || 'Failed to retrieve video info' });
|
||||
} finally {
|
||||
setIsLoading(false);
|
||||
}
|
||||
);
|
||||
|
||||
console.log('Retrieving video info for URL:', videoUrl);
|
||||
console.log('Retrieved video info:', videoInfo);
|
||||
|
||||
}
|
||||
|
||||
|
||||
return (
|
||||
<div className="p-6">
|
||||
<h1 className="text-2xl font-bold mb-4">Video Downloader</h1>
|
||||
|
||||
|
||||
<input
|
||||
type="text"
|
||||
value={videoUrl}
|
||||
@@ -28,6 +39,8 @@ export default function Downloader() {
|
||||
className="w-full p-2 border rounded mb-4"
|
||||
/>
|
||||
|
||||
<button onClick={retriveVideoInfo}>Retrieve options</button>
|
||||
|
||||
{isLoading && <p>Loading video info...</p>}
|
||||
|
||||
{error && <p className="text-red-500">Error: {error?.error}</p>}
|
||||
|
||||
Reference in New Issue
Block a user