From a1c9b70b2e73e00047621ef1dc247eccf5a34418 Mon Sep 17 00:00:00 2001 From: Mary Kate Fain Date: Tue, 21 Oct 2025 13:20:35 -0500 Subject: [PATCH] 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 */}