From cab7d62b2ec471241317d5e7f64fbc7c4ca15514 Mon Sep 17 00:00:00 2001 From: "shakespeare.diy" Date: Tue, 21 Oct 2025 13:06:33 -0500 Subject: [PATCH 1/5] Add "Copy Edit with Shakespeare URL" button to repository section - Added Copy icon import from lucide-react - Created handleCopyShakespeareURL function that: - Validates that a repository URL exists - Encodes the URL and formats it as a Shakespeare clone URL - Copies the formatted URL to clipboard - Shows success/error toast notifications - Added button below Git URL input that appears when URL is present - Button copies the properly formatted Shakespeare clone URL (https://shakespeare.diy/clone?url=...) - Works with GitHub, GitLab, NostrGit, and any other git repository URL --- src/components/GitDialog.tsx | 42 ++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/src/components/GitDialog.tsx b/src/components/GitDialog.tsx index 8de746bf..63191ed5 100644 --- a/src/components/GitDialog.tsx +++ b/src/components/GitDialog.tsx @@ -46,6 +46,7 @@ import { Settings2, GitPullRequest, ExternalLink, + Copy, } from 'lucide-react'; import { useGitStatus } from '@/hooks/useGitStatus'; import { useGitSettings } from '@/hooks/useGitSettings'; @@ -683,6 +684,34 @@ export function GitDialog({ projectId, children, open, onOpenChange }: GitDialog const [isGitManagementOpen, setIsGitManagementOpen] = useState(false); const [gitManagementDefaultTab, setGitManagementDefaultTab] = useState('branches'); + const handleCopyShakespeareURL = () => { + if (!originUrl.trim()) { + toast({ + title: "No repository URL", + description: "Please enter a Git URL first", + variant: "destructive", + }); + return; + } + + // Create the Shakespeare clone URL by encoding the origin URL + const shakespeareURL = `https://shakespeare.diy/clone?url=${encodeURIComponent(originUrl.trim())}`; + + // Copy to clipboard + navigator.clipboard.writeText(shakespeareURL).then(() => { + toast({ + title: "Copied to clipboard", + description: "Edit with Shakespeare URL copied", + }); + }).catch(() => { + toast({ + title: "Failed to copy", + description: "Could not copy to clipboard", + variant: "destructive", + }); + }); + }; + return ( <> @@ -752,6 +781,19 @@ export function GitDialog({ projectId, children, open, onOpenChange }: GitDialog + {/* Copy Shakespeare URL Button */} + {originUrl.trim() && ( + + )} + {/* Credentials Warning */} {gitStatus.remotes.length > 0 && ( (() => { From efbd659ccdb2b9e946f3407b822a76f65573f852 Mon Sep 17 00:00:00 2001 From: "shakespeare.diy" Date: Tue, 21 Oct 2025 13:08:22 -0500 Subject: [PATCH 2/5] Fix clipboard copy with fallback method for browser compatibility - Made handleCopyShakespeareURL async - Added try-catch for modern clipboard API - Implemented fallback using document.execCommand for older browsers or insecure contexts - Fallback creates hidden textarea, selects text, and uses execCommand('copy') - Improved error handling with better user feedback - Ensures copy functionality works across different browser environments --- src/components/GitDialog.tsx | 46 ++++++++++++++++++++++++++++-------- 1 file changed, 36 insertions(+), 10 deletions(-) diff --git a/src/components/GitDialog.tsx b/src/components/GitDialog.tsx index 63191ed5..bf3ee75f 100644 --- a/src/components/GitDialog.tsx +++ b/src/components/GitDialog.tsx @@ -684,7 +684,7 @@ export function GitDialog({ projectId, children, open, onOpenChange }: GitDialog const [isGitManagementOpen, setIsGitManagementOpen] = useState(false); const [gitManagementDefaultTab, setGitManagementDefaultTab] = useState('branches'); - const handleCopyShakespeareURL = () => { + const handleCopyShakespeareURL = async () => { if (!originUrl.trim()) { toast({ title: "No repository URL", @@ -697,19 +697,45 @@ export function GitDialog({ projectId, children, open, onOpenChange }: GitDialog // Create the Shakespeare clone URL by encoding the origin URL const shakespeareURL = `https://shakespeare.diy/clone?url=${encodeURIComponent(originUrl.trim())}`; - // Copy to clipboard - navigator.clipboard.writeText(shakespeareURL).then(() => { + // Try modern clipboard API first + try { + await navigator.clipboard.writeText(shakespeareURL); toast({ title: "Copied to clipboard", description: "Edit with Shakespeare URL copied", }); - }).catch(() => { - toast({ - title: "Failed to copy", - description: "Could not copy to clipboard", - variant: "destructive", - }); - }); + return; + } catch (clipboardError) { + // Fallback to older method + try { + const textArea = document.createElement('textarea'); + textArea.value = shakespeareURL; + textArea.style.position = 'fixed'; + textArea.style.left = '-999999px'; + textArea.style.top = '-999999px'; + document.body.appendChild(textArea); + textArea.focus(); + textArea.select(); + + const successful = document.execCommand('copy'); + document.body.removeChild(textArea); + + if (successful) { + toast({ + title: "Copied to clipboard", + description: "Edit with Shakespeare URL copied", + }); + } else { + throw new Error('execCommand failed'); + } + } catch (fallbackError) { + toast({ + title: "Failed to copy", + description: "Could not copy to clipboard. Please copy manually.", + variant: "destructive", + }); + } + } }; return ( From a1c9b70b2e73e00047621ef1dc247eccf5a34418 Mon Sep 17 00:00:00 2001 From: Mary Kate Fain Date: Tue, 21 Oct 2025 13:20:35 -0500 Subject: [PATCH 3/5] add copy edit with shakespeare URL --- src/components/CreditsDialog.tsx | 41 ++++++++++++++++++++++++++------ src/components/GitDialog.tsx | 36 ++++++++++++++++++---------- 2 files changed, 58 insertions(+), 19 deletions(-) diff --git a/src/components/CreditsDialog.tsx b/src/components/CreditsDialog.tsx index 226651d2..b9a2e339 100644 --- a/src/components/CreditsDialog.tsx +++ b/src/components/CreditsDialog.tsx @@ -19,7 +19,7 @@ import { AIProvider } from '@/contexts/AISettingsContext'; interface CreditsDialogProps { open: boolean; onOpenChange: (open: boolean) => void; - provider: AIProvider; + provider: AIProvider | undefined; } interface Payment { @@ -195,13 +195,16 @@ export function CreditsDialog({ open, onOpenChange, provider }: CreditsDialogPro // Query for payment history const { data: payments, isLoading: isLoadingPayments } = useQuery({ - queryKey: ['ai-payments', provider.nostr ? user?.pubkey ?? '' : '', provider.id], + queryKey: ['ai-payments', provider?.nostr ? user?.pubkey ?? '' : '', provider?.id ?? ''], queryFn: async (): Promise => { + if (!provider) { + throw new Error('Provider is required'); + } const ai = createAIClient(provider, user, config.corsProxy); const data = await ai.get('/credits/payments?limit=50') as PaymentsResponse; return data.data; }, - enabled: open, + enabled: open && !!provider, retry: false, refetchOnWindowFocus: false, }); @@ -209,6 +212,9 @@ export function CreditsDialog({ open, onOpenChange, provider }: CreditsDialogPro // Mutation for adding credits const addCreditsMutation = useMutation({ mutationFn: async (request: AddCreditsRequest): Promise => { + if (!provider) { + throw new Error('Provider is required'); + } const ai = createAIClient(provider, user, config.corsProxy); return await ai.post('/credits/add', { body: request, @@ -229,12 +235,12 @@ export function CreditsDialog({ open, onOpenChange, provider }: CreditsDialogPro // Refresh payments list queryClient.invalidateQueries({ - queryKey: ['ai-payments', provider.nostr ? user?.pubkey ?? '' : '', provider.id], + queryKey: ['ai-payments', provider?.nostr ? user?.pubkey ?? '' : '', provider?.id ?? ''], }); // Refresh credits balance queryClient.invalidateQueries({ - queryKey: ['ai-credits', provider.nostr ? user?.pubkey ?? '' : '', provider.id], + queryKey: ['ai-credits', provider?.nostr ? user?.pubkey ?? '' : '', provider?.id ?? ''], }); }, onError: (error: Error) => { @@ -250,6 +256,9 @@ export function CreditsDialog({ open, onOpenChange, provider }: CreditsDialogPro // Mutation for checking payment status const checkPaymentMutation = useMutation({ mutationFn: async (paymentId: string): Promise => { + if (!provider) { + throw new Error('Provider is required'); + } const ai = createAIClient(provider, user, config.corsProxy); return await ai.get(`/credits/payments/${paymentId}`) as Payment; }, @@ -267,7 +276,7 @@ export function CreditsDialog({ open, onOpenChange, provider }: CreditsDialogPro // Update the specific payment in the cache instead of refetching queryClient.setQueryData( - ['ai-payments', provider.nostr ? user?.pubkey ?? '' : '', provider.id], + ['ai-payments', provider?.nostr ? user?.pubkey ?? '' : '', provider?.id ?? ''], (oldPayments) => { if (!oldPayments) return oldPayments; return oldPayments.map(payment => @@ -279,7 +288,7 @@ export function CreditsDialog({ open, onOpenChange, provider }: CreditsDialogPro // If payment completed, refresh credits balance if (updatedPayment.status === 'completed') { queryClient.invalidateQueries({ - queryKey: ['ai-credits', provider.nostr ? user?.pubkey ?? '' : '', provider.id], + queryKey: ['ai-credits', provider?.nostr ? user?.pubkey ?? '' : '', provider?.id ?? ''], }); toast({ title: 'Payment completed!', @@ -399,6 +408,24 @@ export function CreditsDialog({ open, onOpenChange, provider }: CreditsDialogPro } }; + // Guard against undefined provider + if (!provider) { + return ( + + + + Credits + +
+

+ No AI provider selected. Please configure an AI provider first. +

+
+
+
+ ); + } + return ( e.preventDefault()} className="max-w-lg w-full max-h-[75vh] overflow-hidden flex flex-col sm:max-w-lg sm:max-h-[75vh] max-sm:w-full max-sm:h-dvh-safe max-sm:max-w-none max-sm:max-h-none max-sm:m-0 max-sm:rounded-none"> diff --git a/src/components/GitDialog.tsx b/src/components/GitDialog.tsx index bf3ee75f..30033ecc 100644 --- a/src/components/GitDialog.tsx +++ b/src/components/GitDialog.tsx @@ -705,7 +705,7 @@ export function GitDialog({ projectId, children, open, onOpenChange }: GitDialog description: "Edit with Shakespeare URL copied", }); return; - } catch (clipboardError) { + } catch { // Fallback to older method try { const textArea = document.createElement('textarea'); @@ -728,7 +728,7 @@ export function GitDialog({ projectId, children, open, onOpenChange }: GitDialog } else { throw new Error('execCommand failed'); } - } catch (fallbackError) { + } catch { toast({ title: "Failed to copy", description: "Could not copy to clipboard. Please copy manually.", @@ -807,17 +807,29 @@ export function GitDialog({ projectId, children, open, onOpenChange }: GitDialog - {/* Copy Shakespeare URL Button */} + {/* Edit with Shakespeare URL */} {originUrl.trim() && ( - +
+ +
+ + +
+
)} {/* Credentials Warning */} From 4b47dc19ce661ac67b3f93d6522aff75ae2d376d Mon Sep 17 00:00:00 2001 From: Mary Kate Fain Date: Tue, 21 Oct 2025 13:26:59 -0500 Subject: [PATCH 4/5] placeholder when no repo configured --- src/components/GitDialog.tsx | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/components/GitDialog.tsx b/src/components/GitDialog.tsx index 30033ecc..0b8346be 100644 --- a/src/components/GitDialog.tsx +++ b/src/components/GitDialog.tsx @@ -808,7 +808,7 @@ export function GitDialog({ projectId, children, open, onOpenChange }: GitDialog {/* Edit with Shakespeare URL */} - {originUrl.trim() && ( + {originUrl.trim() ? (
+ ) : ( +
+ +
+
+ + + Push your repository to get a shareable Shakespeare link + +
+
+
)} {/* Credentials Warning */} From 7879182446f681ee1939f16bd1a629b66f11fbd3 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Tue, 21 Oct 2025 19:41:50 -0500 Subject: [PATCH 5/5] Reset CreditsDialog --- src/components/CreditsDialog.tsx | 41 ++++++-------------------------- 1 file changed, 7 insertions(+), 34 deletions(-) diff --git a/src/components/CreditsDialog.tsx b/src/components/CreditsDialog.tsx index b9a2e339..226651d2 100644 --- a/src/components/CreditsDialog.tsx +++ b/src/components/CreditsDialog.tsx @@ -19,7 +19,7 @@ import { AIProvider } from '@/contexts/AISettingsContext'; interface CreditsDialogProps { open: boolean; onOpenChange: (open: boolean) => void; - provider: AIProvider | undefined; + provider: AIProvider; } interface Payment { @@ -195,16 +195,13 @@ export function CreditsDialog({ open, onOpenChange, provider }: CreditsDialogPro // Query for payment history const { data: payments, isLoading: isLoadingPayments } = useQuery({ - queryKey: ['ai-payments', provider?.nostr ? user?.pubkey ?? '' : '', provider?.id ?? ''], + queryKey: ['ai-payments', provider.nostr ? user?.pubkey ?? '' : '', provider.id], queryFn: async (): Promise => { - if (!provider) { - throw new Error('Provider is required'); - } const ai = createAIClient(provider, user, config.corsProxy); const data = await ai.get('/credits/payments?limit=50') as PaymentsResponse; return data.data; }, - enabled: open && !!provider, + enabled: open, retry: false, refetchOnWindowFocus: false, }); @@ -212,9 +209,6 @@ export function CreditsDialog({ open, onOpenChange, provider }: CreditsDialogPro // Mutation for adding credits const addCreditsMutation = useMutation({ mutationFn: async (request: AddCreditsRequest): Promise => { - if (!provider) { - throw new Error('Provider is required'); - } const ai = createAIClient(provider, user, config.corsProxy); return await ai.post('/credits/add', { body: request, @@ -235,12 +229,12 @@ export function CreditsDialog({ open, onOpenChange, provider }: CreditsDialogPro // Refresh payments list queryClient.invalidateQueries({ - queryKey: ['ai-payments', provider?.nostr ? user?.pubkey ?? '' : '', provider?.id ?? ''], + queryKey: ['ai-payments', provider.nostr ? user?.pubkey ?? '' : '', provider.id], }); // Refresh credits balance queryClient.invalidateQueries({ - queryKey: ['ai-credits', provider?.nostr ? user?.pubkey ?? '' : '', provider?.id ?? ''], + queryKey: ['ai-credits', provider.nostr ? user?.pubkey ?? '' : '', provider.id], }); }, onError: (error: Error) => { @@ -256,9 +250,6 @@ export function CreditsDialog({ open, onOpenChange, provider }: CreditsDialogPro // Mutation for checking payment status const checkPaymentMutation = useMutation({ mutationFn: async (paymentId: string): Promise => { - if (!provider) { - throw new Error('Provider is required'); - } const ai = createAIClient(provider, user, config.corsProxy); return await ai.get(`/credits/payments/${paymentId}`) as Payment; }, @@ -276,7 +267,7 @@ export function CreditsDialog({ open, onOpenChange, provider }: CreditsDialogPro // Update the specific payment in the cache instead of refetching queryClient.setQueryData( - ['ai-payments', provider?.nostr ? user?.pubkey ?? '' : '', provider?.id ?? ''], + ['ai-payments', provider.nostr ? user?.pubkey ?? '' : '', provider.id], (oldPayments) => { if (!oldPayments) return oldPayments; return oldPayments.map(payment => @@ -288,7 +279,7 @@ export function CreditsDialog({ open, onOpenChange, provider }: CreditsDialogPro // If payment completed, refresh credits balance if (updatedPayment.status === 'completed') { queryClient.invalidateQueries({ - queryKey: ['ai-credits', provider?.nostr ? user?.pubkey ?? '' : '', provider?.id ?? ''], + queryKey: ['ai-credits', provider.nostr ? user?.pubkey ?? '' : '', provider.id], }); toast({ title: 'Payment completed!', @@ -408,24 +399,6 @@ export function CreditsDialog({ open, onOpenChange, provider }: CreditsDialogPro } }; - // Guard against undefined provider - if (!provider) { - return ( - - - - Credits - -
-

- No AI provider selected. Please configure an AI provider first. -

-
-
-
- ); - } - return ( e.preventDefault()} className="max-w-lg w-full max-h-[75vh] overflow-hidden flex flex-col sm:max-w-lg sm:max-h-[75vh] max-sm:w-full max-sm:h-dvh-safe max-sm:max-w-none max-sm:max-h-none max-sm:m-0 max-sm:rounded-none">