mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-05 16:23:36 +00:00
add copy edit with shakespeare URL
This commit is contained in:
1 parent
efbd659ccd
commit
a1c9b70b2e
2 files changed
+58
-19
No files matched your search
@@ -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<Payment[]> => {
|
||||
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<Payment> => {
|
||||
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<Payment> => {
|
||||
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<Payment[]>(
|
||||
['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 (
|
||||
<Dialog open={open} onOpenChange={onOpenChange}>
|
||||
<DialogContent className="max-w-lg">
|
||||
<DialogHeader>
|
||||
<DialogTitle>Credits</DialogTitle>
|
||||
</DialogHeader>
|
||||
<div className="text-center py-8">
|
||||
<p className="text-muted-foreground">
|
||||
No AI provider selected. Please configure an AI provider first.
|
||||
</p>
|
||||
</div>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={onOpenChange}>
|
||||
<DialogContent onOpenAutoFocus={(e) => 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">
|
||||
|
||||
@@ -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
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
{/* Copy Shakespeare URL Button */}
|
||||
{/* Edit with Shakespeare URL */}
|
||||
{originUrl.trim() && (
|
||||
<Button
|
||||
onClick={handleCopyShakespeareURL}
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
className="w-full h-8 text-xs gap-2"
|
||||
>
|
||||
<Copy className="h-3 w-3" />
|
||||
Copy "Edit with Shakespeare" URL
|
||||
</Button>
|
||||
<div className="space-y-2">
|
||||
<Label className="text-xs text-muted-foreground">
|
||||
Edit with Shakespeare URL
|
||||
</Label>
|
||||
<div className="flex gap-2">
|
||||
<Input
|
||||
value={`https://shakespeare.diy/clone?url=${encodeURIComponent(originUrl.trim())}`}
|
||||
readOnly
|
||||
className="flex-1 text-xs text-muted-foreground bg-muted cursor-default h-8 truncate"
|
||||
tabIndex={-1}
|
||||
/>
|
||||
<Button
|
||||
onClick={handleCopyShakespeareURL}
|
||||
variant="outline"
|
||||
size="sm"
|
||||
className="h-8 px-3"
|
||||
>
|
||||
<Copy className="h-3 w-3" />
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Credentials Warning */}
|
||||
|
||||
Reference in new issue
Block a user