collection fix
This commit is contained in:
@@ -110,6 +110,7 @@ export default function EditCollectionPage() {
|
||||
description: collection.description,
|
||||
tags: collection.tags?.map(tag => tag.name) || [],
|
||||
storyIds: collection.collectionStories?.map(cs => cs.story.id) || [],
|
||||
stories: collection.collectionStories?.map(cs => cs.story) || [],
|
||||
coverImagePath: collection.coverImagePath,
|
||||
};
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ interface CollectionFormProps {
|
||||
description?: string;
|
||||
tags?: string[];
|
||||
storyIds?: string[];
|
||||
stories?: Story[];
|
||||
coverImagePath?: string;
|
||||
};
|
||||
onSubmit: (data: {
|
||||
@@ -42,11 +43,12 @@ export default function CollectionForm({
|
||||
const [selectedStoryIds, setSelectedStoryIds] = useState<string[]>(initialData?.storyIds || []);
|
||||
const [coverImage, setCoverImage] = useState<File | null>(null);
|
||||
const [coverImagePreview, setCoverImagePreview] = useState<string | null>(null);
|
||||
// Pre-populate from initialData.stories to avoid a redundant search fetch
|
||||
const [selectedStories, setSelectedStories] = useState<Story[]>(initialData?.stories || []);
|
||||
|
||||
// Story selection state
|
||||
const [storySearchQuery, setStorySearchQuery] = useState('');
|
||||
const [availableStories, setAvailableStories] = useState<Story[]>([]);
|
||||
const [selectedStories, setSelectedStories] = useState<Story[]>([]);
|
||||
const [loadingStories, setLoadingStories] = useState(false);
|
||||
const [showStorySelection, setShowStorySelection] = useState(false);
|
||||
|
||||
@@ -93,26 +95,6 @@ export default function CollectionForm({
|
||||
}
|
||||
}, [storySearchQuery, showStorySelection]);
|
||||
|
||||
// Load selected stories data on mount
|
||||
useEffect(() => {
|
||||
if (selectedStoryIds.length > 0) {
|
||||
const loadSelectedStories = async () => {
|
||||
try {
|
||||
const result = await searchApi.search({
|
||||
query: '*',
|
||||
page: 0,
|
||||
size: 100,
|
||||
});
|
||||
const stories = result.results.filter(story => selectedStoryIds.includes(story.id));
|
||||
setSelectedStories(stories);
|
||||
} catch (error) {
|
||||
console.error('Failed to load selected stories:', error);
|
||||
}
|
||||
};
|
||||
loadSelectedStories();
|
||||
}
|
||||
}, [selectedStoryIds]);
|
||||
|
||||
const handleTagInputKeyDown = (e: React.KeyboardEvent) => {
|
||||
if (e.key === 'Enter' && tagInput.trim()) {
|
||||
e.preventDefault();
|
||||
|
||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user