mirror of
https://github.com/xavidop/cardex.git
synced 2026-09-04 17:23:30 +00:00
feat: refactor
This commit is contained in:
@@ -14,7 +14,7 @@ import { compressBase64Image, getBase64Size, formatBytes } from '@/utils/imageUt
|
||||
import { parsePhotoGenerationParams } from '@/utils/generationParamsUtils';
|
||||
import { getGameConfig } from '@/config/tcg-games';
|
||||
import type { GenerateFromPhotoInput } from '@/components/cards/PhotoCardGeneratorFormOnly';
|
||||
import type { TCGGame } from '@/types';
|
||||
import type { TCGGame, PhotoCardGenerationParams, GeneratedCard } from '@/types';
|
||||
import Image from 'next/image';
|
||||
|
||||
export default function EditGenerateFromPhotoPage() {
|
||||
@@ -22,7 +22,7 @@ export default function EditGenerateFromPhotoPage() {
|
||||
const { toast } = useToast();
|
||||
const router = useRouter();
|
||||
const searchParams = useSearchParams();
|
||||
const [generatedCard, setGeneratedCard] = useState<{ imageBase64: string; prompt: string; params?: any } | null>(null);
|
||||
const [generatedCard, setGeneratedCard] = useState<(GeneratedCard & { params?: GenerateFromPhotoInput }) | null>(null);
|
||||
const [originalCard, setOriginalCard] = useState<{ id: string; name: string; imageUrl: string } | null>(null);
|
||||
const [isSaving, setIsSaving] = useState(false);
|
||||
const [initialValues, setInitialValues] = useState<Partial<GenerateFromPhotoInput> | undefined>(undefined);
|
||||
@@ -95,7 +95,7 @@ export default function EditGenerateFromPhotoPage() {
|
||||
const gameName = getGameConfig(game as TCGGame).name;
|
||||
|
||||
// Exclude photoDataUri from params when saving to Firestore (too large for document storage)
|
||||
const { photoDataUri, ...paramsWithoutPhoto } = generatedCard.params;
|
||||
const { photoDataUri, ...paramsWithoutPhoto } = generatedCard.params || {};
|
||||
|
||||
await addCardToCollection(user.uid, {
|
||||
name: `Photo-Generated ${gameName} Card`,
|
||||
@@ -106,7 +106,7 @@ export default function EditGenerateFromPhotoPage() {
|
||||
isGenerated: true,
|
||||
isPhotoGenerated: true,
|
||||
prompt: generatedCard.prompt,
|
||||
photoGenerationParams: paramsWithoutPhoto,
|
||||
photoGenerationParams: paramsWithoutPhoto as PhotoCardGenerationParams,
|
||||
});
|
||||
|
||||
toast({
|
||||
|
||||
@@ -12,7 +12,7 @@ import { useRouter } from 'next/navigation';
|
||||
import { compressBase64Image, getBase64Size, formatBytes } from '@/utils/imageUtils';
|
||||
import ApiKeysWarning from '@/components/cards/ApiKeysWarning';
|
||||
import { getGameConfig } from '@/config/tcg-games';
|
||||
import type { TCGGame } from '@/types';
|
||||
import type { TCGGame, GeneratedCard, PhotoCardGenerationParams } from '@/types';
|
||||
|
||||
export default function GenerateFromPhotoPage() {
|
||||
const { user } = useAuth();
|
||||
|
||||
@@ -11,14 +11,14 @@ import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/com
|
||||
import { compressBase64Image, getBase64Size, formatBytes } from '@/utils/imageUtils';
|
||||
import { parseGenerationParams } from '@/utils/generationParamsUtils';
|
||||
import { getGameConfig } from '@/config/tcg-games';
|
||||
import type { TCGGame, CardGenerationParams } from '@/types';
|
||||
import type { TCGGame, CardGenerationParams, GeneratedCard } from '@/types';
|
||||
import Image from 'next/image';
|
||||
|
||||
export default function EditGenerateCardPage() {
|
||||
const { user } = useAuth();
|
||||
const { toast } = useToast();
|
||||
const searchParams = useSearchParams();
|
||||
const [generatedCard, setGeneratedCard] = useState<{ imageBase64: string; prompt: string; params?: any } | null>(null);
|
||||
const [generatedCard, setGeneratedCard] = useState<(GeneratedCard & { params?: CardGenerationParams }) | null>(null);
|
||||
const [originalCard, setOriginalCard] = useState<{ id: string; name: string; imageUrl: string } | null>(null);
|
||||
const [isSaving, setIsSaving] = useState(false);
|
||||
const [initialValues, setInitialValues] = useState<Partial<CardGenerationParams> | undefined>(undefined);
|
||||
|
||||
@@ -10,12 +10,12 @@ import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
|
||||
import { compressBase64Image, getBase64Size, formatBytes } from '@/utils/imageUtils';
|
||||
import ApiKeysWarning from '@/components/cards/ApiKeysWarning';
|
||||
import { getGameConfig } from '@/config/tcg-games';
|
||||
import type { TCGGame } from '@/types';
|
||||
import type { TCGGame, GeneratedCard, CardGenerationParams } from '@/types';
|
||||
|
||||
export default function GenerateCardPage() {
|
||||
const { user } = useAuth();
|
||||
const { toast } = useToast();
|
||||
const [generatedCard, setGeneratedCard] = useState<{ imageBase64: string; prompt: string; params?: any } | null>(null);
|
||||
const [generatedCard, setGeneratedCard] = useState<(GeneratedCard & { params?: CardGenerationParams }) | null>(null);
|
||||
const [isSaving, setIsSaving] = useState(false);
|
||||
|
||||
const handleCardGenerated = (imageBase64: string, prompt: string, params: any) => {
|
||||
|
||||
Reference in New Issue
Block a user