mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-06 08:37:22 +00:00
Fix deps lint warning in Clone.tsx
This commit is contained in:
1 file changed
+21
-21
+21
-21
@@ -1,4 +1,4 @@
|
|||||||
import { useState, useEffect } from 'react';
|
import { useState, useEffect, useCallback } from 'react';
|
||||||
import { useNavigate, useSearchParams } from 'react-router-dom';
|
import { useNavigate, useSearchParams } from 'react-router-dom';
|
||||||
import { AppLayout } from '@/components/AppLayout';
|
import { AppLayout } from '@/components/AppLayout';
|
||||||
import { Button } from '@/components/ui/button';
|
import { Button } from '@/components/ui/button';
|
||||||
@@ -36,18 +36,6 @@ export default function Clone() {
|
|||||||
description: 'Import a Git repository into your Shakespeare workspace',
|
description: 'Import a Git repository into your Shakespeare workspace',
|
||||||
});
|
});
|
||||||
|
|
||||||
// Initialize repoUrl from URL parameters and auto-import if URL is provided
|
|
||||||
useEffect(() => {
|
|
||||||
const urlParam = searchParams.get('url');
|
|
||||||
if (urlParam) {
|
|
||||||
const decodedUrl = decodeURIComponent(urlParam);
|
|
||||||
setRepoUrl(decodedUrl);
|
|
||||||
|
|
||||||
// Automatically start the clone process with the URL directly
|
|
||||||
handleClone(decodedUrl);
|
|
||||||
}
|
|
||||||
}, [searchParams]);
|
|
||||||
|
|
||||||
const extractRepoName = (url: string): string => {
|
const extractRepoName = (url: string): string => {
|
||||||
try {
|
try {
|
||||||
// Handle different URL formats
|
// Handle different URL formats
|
||||||
@@ -126,7 +114,7 @@ export default function Clone() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const validateGitUrl = (url: string): boolean => {
|
const validateGitUrl = useCallback((url: string): boolean => {
|
||||||
if (!url.trim()) return false;
|
if (!url.trim()) return false;
|
||||||
|
|
||||||
// Check if it's a Nostr clone URI
|
// Check if it's a Nostr clone URI
|
||||||
@@ -144,9 +132,9 @@ export default function Clone() {
|
|||||||
// Check if it looks like a git repository URL
|
// Check if it looks like a git repository URL
|
||||||
const gitUrlPattern = /^https?:\/\/.*\.git$|^https?:\/\/github\.com\/.*\/.*$|^https?:\/\/gitlab\.com\/.*\/.*$/i;
|
const gitUrlPattern = /^https?:\/\/.*\.git$|^https?:\/\/github\.com\/.*\/.*$|^https?:\/\/gitlab\.com\/.*\/.*$/i;
|
||||||
return gitUrlPattern.test(url) || url.includes('github.com') || url.includes('gitlab.com');
|
return gitUrlPattern.test(url) || url.includes('github.com') || url.includes('gitlab.com');
|
||||||
};
|
}, []);
|
||||||
|
|
||||||
const fetchNostrRepository = async (nostrUri: NostrCloneUri): Promise<string[]> => {
|
const fetchNostrRepository = useCallback(async (nostrUri: NostrCloneUri): Promise<string[]> => {
|
||||||
const signal = AbortSignal.timeout(10000); // 10 second timeout
|
const signal = AbortSignal.timeout(10000); // 10 second timeout
|
||||||
|
|
||||||
// Build the filter for the NIP-34 repository announcement
|
// Build the filter for the NIP-34 repository announcement
|
||||||
@@ -184,9 +172,9 @@ export default function Clone() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return cloneUrls;
|
return cloneUrls;
|
||||||
};
|
}, [nostr]);
|
||||||
|
|
||||||
const tryCloneUrls = async (cloneUrls: string[], repoName: string): Promise<Project> => {
|
const tryCloneUrls = useCallback(async (cloneUrls: string[], repoName: string): Promise<Project> => {
|
||||||
let lastError: Error | null = null;
|
let lastError: Error | null = null;
|
||||||
|
|
||||||
for (const cloneUrl of cloneUrls) {
|
for (const cloneUrl of cloneUrls) {
|
||||||
@@ -211,9 +199,9 @@ export default function Clone() {
|
|||||||
|
|
||||||
// If we get here, all clone attempts failed
|
// If we get here, all clone attempts failed
|
||||||
throw lastError || new Error('All clone attempts failed');
|
throw lastError || new Error('All clone attempts failed');
|
||||||
};
|
}, [projectsManager]);
|
||||||
|
|
||||||
const handleClone = async (url?: string) => {
|
const handleClone = useCallback(async (url?: string) => {
|
||||||
const targetUrl = url || repoUrl;
|
const targetUrl = url || repoUrl;
|
||||||
|
|
||||||
if (!targetUrl.trim()) {
|
if (!targetUrl.trim()) {
|
||||||
@@ -301,7 +289,7 @@ export default function Clone() {
|
|||||||
} finally {
|
} finally {
|
||||||
setIsCloning(false);
|
setIsCloning(false);
|
||||||
}
|
}
|
||||||
};
|
}, [fetchNostrRepository, navigate, projectsManager, repoUrl, toast, tryCloneUrls, validateGitUrl]);
|
||||||
|
|
||||||
const handleKeyDown = (e: React.KeyboardEvent) => {
|
const handleKeyDown = (e: React.KeyboardEvent) => {
|
||||||
if (e.key === 'Enter' && !isCloning) {
|
if (e.key === 'Enter' && !isCloning) {
|
||||||
@@ -309,6 +297,18 @@ export default function Clone() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Initialize repoUrl from URL parameters and auto-import if URL is provided
|
||||||
|
useEffect(() => {
|
||||||
|
const urlParam = searchParams.get('url');
|
||||||
|
if (urlParam) {
|
||||||
|
const decodedUrl = decodeURIComponent(urlParam);
|
||||||
|
setRepoUrl(decodedUrl);
|
||||||
|
|
||||||
|
// Automatically start the clone process with the URL directly
|
||||||
|
handleClone(decodedUrl);
|
||||||
|
}
|
||||||
|
}, [handleClone, searchParams]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<AppLayout title="Import Repository">
|
<AppLayout title="Import Repository">
|
||||||
<div className="max-w-2xl mx-auto">
|
<div className="max-w-2xl mx-auto">
|
||||||
|
|||||||
Reference in new issue
Block a user