collection fix
This commit is contained in:
@@ -126,7 +126,7 @@ public class CollectionService {
|
|||||||
savedCollection = findById(savedCollection.getId());
|
savedCollection = findById(savedCollection.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Collections are not indexed in search engine yet
|
searchServiceAdapter.indexCollection(savedCollection);
|
||||||
|
|
||||||
logger.info("Created collection: {} with {} stories", name, initialStoryIds != null ? initialStoryIds.size() : 0);
|
logger.info("Created collection: {} with {} stories", name, initialStoryIds != null ? initialStoryIds.size() : 0);
|
||||||
return savedCollection;
|
return savedCollection;
|
||||||
@@ -155,8 +155,7 @@ public class CollectionService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Collection savedCollection = collectionRepository.save(collection);
|
Collection savedCollection = collectionRepository.save(collection);
|
||||||
|
searchServiceAdapter.updateCollection(findById(savedCollection.getId()));
|
||||||
// Collections are not indexed in search engine yet
|
|
||||||
|
|
||||||
logger.info("Updated collection: {}", id);
|
logger.info("Updated collection: {}", id);
|
||||||
return savedCollection;
|
return savedCollection;
|
||||||
@@ -167,9 +166,7 @@ public class CollectionService {
|
|||||||
*/
|
*/
|
||||||
public void deleteCollection(UUID id) {
|
public void deleteCollection(UUID id) {
|
||||||
Collection collection = findByIdBasic(id);
|
Collection collection = findByIdBasic(id);
|
||||||
|
searchServiceAdapter.deleteCollection(id);
|
||||||
// Collections are not indexed in search engine yet
|
|
||||||
|
|
||||||
collectionRepository.delete(collection);
|
collectionRepository.delete(collection);
|
||||||
logger.info("Deleted collection: {}", id);
|
logger.info("Deleted collection: {}", id);
|
||||||
}
|
}
|
||||||
@@ -182,8 +179,7 @@ public class CollectionService {
|
|||||||
collection.setIsArchived(archived);
|
collection.setIsArchived(archived);
|
||||||
|
|
||||||
Collection savedCollection = collectionRepository.save(collection);
|
Collection savedCollection = collectionRepository.save(collection);
|
||||||
|
searchServiceAdapter.updateCollection(findById(savedCollection.getId()));
|
||||||
// Collections are not indexed in search engine yet
|
|
||||||
|
|
||||||
logger.info("{} collection: {}", archived ? "Archived" : "Unarchived", id);
|
logger.info("{} collection: {}", archived ? "Archived" : "Unarchived", id);
|
||||||
return savedCollection;
|
return savedCollection;
|
||||||
@@ -227,8 +223,7 @@ public class CollectionService {
|
|||||||
position += 1000; // Gap-based positioning
|
position += 1000; // Gap-based positioning
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update collection in Typesense
|
searchServiceAdapter.updateCollection(findById(collectionId));
|
||||||
// Collections are not indexed in search engine yet
|
|
||||||
|
|
||||||
long totalStories = collectionStoryRepository.countByCollectionId(collectionId);
|
long totalStories = collectionStoryRepository.countByCollectionId(collectionId);
|
||||||
|
|
||||||
@@ -251,9 +246,7 @@ public class CollectionService {
|
|||||||
|
|
||||||
CollectionStory collectionStory = collectionStoryRepository.findByCollectionIdAndStoryId(collectionId, storyId);
|
CollectionStory collectionStory = collectionStoryRepository.findByCollectionIdAndStoryId(collectionId, storyId);
|
||||||
collectionStoryRepository.delete(collectionStory);
|
collectionStoryRepository.delete(collectionStory);
|
||||||
|
searchServiceAdapter.updateCollection(findById(collectionId));
|
||||||
// Update collection in Typesense
|
|
||||||
// Collections are not indexed in search engine yet
|
|
||||||
|
|
||||||
logger.info("Removed story {} from collection {}", storyId, collectionId);
|
logger.info("Removed story {} from collection {}", storyId, collectionId);
|
||||||
}
|
}
|
||||||
@@ -285,8 +278,7 @@ public class CollectionService {
|
|||||||
collectionStoryRepository.updatePosition(collectionId, storyId, position * 1000); // Gap-based positioning
|
collectionStoryRepository.updatePosition(collectionId, storyId, position * 1000); // Gap-based positioning
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update collection in Typesense
|
searchServiceAdapter.updateCollection(findById(collectionId));
|
||||||
// Collections are not indexed in search engine yet
|
|
||||||
|
|
||||||
logger.info("Reordered {} stories in collection {}", storyOrders.size(), collectionId);
|
logger.info("Reordered {} stories in collection {}", storyOrders.size(), collectionId);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -110,6 +110,7 @@ export default function EditCollectionPage() {
|
|||||||
description: collection.description,
|
description: collection.description,
|
||||||
tags: collection.tags?.map(tag => tag.name) || [],
|
tags: collection.tags?.map(tag => tag.name) || [],
|
||||||
storyIds: collection.collectionStories?.map(cs => cs.story.id) || [],
|
storyIds: collection.collectionStories?.map(cs => cs.story.id) || [],
|
||||||
|
stories: collection.collectionStories?.map(cs => cs.story) || [],
|
||||||
coverImagePath: collection.coverImagePath,
|
coverImagePath: collection.coverImagePath,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ interface CollectionFormProps {
|
|||||||
description?: string;
|
description?: string;
|
||||||
tags?: string[];
|
tags?: string[];
|
||||||
storyIds?: string[];
|
storyIds?: string[];
|
||||||
|
stories?: Story[];
|
||||||
coverImagePath?: string;
|
coverImagePath?: string;
|
||||||
};
|
};
|
||||||
onSubmit: (data: {
|
onSubmit: (data: {
|
||||||
@@ -42,11 +43,12 @@ export default function CollectionForm({
|
|||||||
const [selectedStoryIds, setSelectedStoryIds] = useState<string[]>(initialData?.storyIds || []);
|
const [selectedStoryIds, setSelectedStoryIds] = useState<string[]>(initialData?.storyIds || []);
|
||||||
const [coverImage, setCoverImage] = useState<File | null>(null);
|
const [coverImage, setCoverImage] = useState<File | null>(null);
|
||||||
const [coverImagePreview, setCoverImagePreview] = useState<string | 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
|
// Story selection state
|
||||||
const [storySearchQuery, setStorySearchQuery] = useState('');
|
const [storySearchQuery, setStorySearchQuery] = useState('');
|
||||||
const [availableStories, setAvailableStories] = useState<Story[]>([]);
|
const [availableStories, setAvailableStories] = useState<Story[]>([]);
|
||||||
const [selectedStories, setSelectedStories] = useState<Story[]>([]);
|
|
||||||
const [loadingStories, setLoadingStories] = useState(false);
|
const [loadingStories, setLoadingStories] = useState(false);
|
||||||
const [showStorySelection, setShowStorySelection] = useState(false);
|
const [showStorySelection, setShowStorySelection] = useState(false);
|
||||||
|
|
||||||
@@ -93,26 +95,6 @@ export default function CollectionForm({
|
|||||||
}
|
}
|
||||||
}, [storySearchQuery, showStorySelection]);
|
}, [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) => {
|
const handleTagInputKeyDown = (e: React.KeyboardEvent) => {
|
||||||
if (e.key === 'Enter' && tagInput.trim()) {
|
if (e.key === 'Enter' && tagInput.trim()) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user