feat: Enhance tag management in TagSelectedPhotosDialog with improved logic for removable tags

This commit updates the TagSelectedPhotosDialog to allow both single and bulk tags to be managed more effectively. The logic for determining removable tags has been refined, ensuring that users can see which tags are common across selected photos and whether they can be removed. Additionally, the photo date extraction method in PhotoManager has been improved to include a fallback to file modification time, enhancing reliability. The photo service now also utilizes this updated method for date extraction, ensuring consistency across the application. Documentation has been updated to reflect these changes.
This commit is contained in:
tanyar09
2025-11-11 14:35:50 -05:00
parent f7accb925d
commit 52344febad
3 changed files with 116 additions and 55 deletions
+54 -45
View File
@@ -1423,7 +1423,7 @@ function TagSelectedPhotosDialog({
setPhotoTagsData(tagsData)
}
// Get common tags across all selected photos (only single linkage type tags can be removed)
// Get common tags across all selected photos (both single and bulk)
const commonTags = useMemo(() => {
if (photos.length === 0 || selectedPhotoIds.length === 0) return []
@@ -1433,8 +1433,6 @@ function TagSelectedPhotosDialog({
allPhotoTags[photoId] = photoTagsData[photoId] || []
})
// Find tags that exist in all selected photos with single linkage type (linkage_type = 0)
// Only tags that are single in ALL photos can be removed
const tagIdToName = new Map(tags.map(t => [t.id, t.tag_name]))
// Get all unique tag IDs from all photos
@@ -1443,34 +1441,40 @@ function TagSelectedPhotosDialog({
photoTags.forEach(tag => allTagIds.add(tag.tag_id))
})
// Find tags that are:
// 1. Present in all selected photos
// 2. Have linkage_type = 0 (single) in all photos
const removableTags = Array.from(allTagIds).filter(tagId => {
// Find tags that are present in all selected photos
const commonTagIds = Array.from(allTagIds).filter(tagId => {
// Check if tag exists in all photos
const existsInAll = selectedPhotoIds.every(photoId => {
return selectedPhotoIds.every(photoId => {
const photoTags = allPhotoTags[photoId] || []
return photoTags.some(t => t.tag_id === tagId)
})
if (!existsInAll) return false
// Check if tag is single (linkage_type = 0) in all photos
const isSingleInAll = selectedPhotoIds.every(photoId => {
const photoTags = allPhotoTags[photoId] || []
const tag = photoTags.find(t => t.tag_id === tagId)
return tag && tag.linkage_type === 0
})
return isSingleInAll
})
// Convert to tag objects
return removableTags
// Convert to tag objects with linkage type info
// Determine if tag is removable (single in all photos) or not (bulk in any photo)
return commonTagIds
.map(tagId => {
const tagName = tagIdToName.get(tagId)
if (!tagName) return null
return { tag_id: tagId, tag_name: tagName, linkage_type: 0 }
// Check if tag is single (linkage_type = 0) in all photos
const isSingleInAll = selectedPhotoIds.every(photoId => {
const photoTags = allPhotoTags[photoId] || []
const tag = photoTags.find(t => t.tag_id === tagId)
return tag && tag.linkage_type === 0
})
// Get linkage type from first photo (all should be the same for common tags)
const firstPhotoTags = allPhotoTags[selectedPhotoIds[0]] || []
const firstTag = firstPhotoTags.find(t => t.tag_id === tagId)
const linkageType = firstTag?.linkage_type || 0
return {
tag_id: tagId,
tag_name: tagName,
linkage_type: linkageType,
isRemovable: isSingleInAll,
}
})
.filter(Boolean) as any[]
}, [photos, tags, selectedPhotoIds, photoTagsData])
@@ -1528,33 +1532,38 @@ function TagSelectedPhotosDialog({
<div className="space-y-2">
<h3 className="font-semibold text-sm text-gray-700 mb-2">
Removable Tags (single tags present in all selected photos):
{selectedPhotoIds.length === 1 ? 'Tags:' : 'Common Tags:'}
</h3>
<p className="text-xs text-gray-500 mb-2">
Note: Bulk tags cannot be removed from this dialog
</p>
{commonTags.length === 0 ? (
<p className="text-gray-500 text-sm">No common tags found</p>
) : (
commonTags.map(tag => (
<div key={tag.tag_id} className="flex items-center gap-2 py-1">
<input
type="checkbox"
checked={selectedTagIds.has(tag.tag_id)}
onChange={(e) => {
const newSet = new Set(selectedTagIds)
if (e.target.checked) {
newSet.add(tag.tag_id)
} else {
newSet.delete(tag.tag_id)
}
setSelectedTagIds(newSet)
}}
className="w-4 h-4"
/>
<span className="flex-1">{tag.tag_name}</span>
</div>
))
commonTags.map(tag => {
const isRemovable = tag.isRemovable !== false
return (
<div key={tag.tag_id} className="flex items-center gap-2 py-1">
<input
type="checkbox"
checked={selectedTagIds.has(tag.tag_id)}
onChange={(e) => {
if (!isRemovable) return
const newSet = new Set(selectedTagIds)
if (e.target.checked) {
newSet.add(tag.tag_id)
} else {
newSet.delete(tag.tag_id)
}
setSelectedTagIds(newSet)
}}
disabled={!isRemovable}
className="w-4 h-4"
/>
<span className={`flex-1 ${!isRemovable ? 'text-gray-400' : ''}`}>
{tag.tag_name}
{!isRemovable && <span className="text-xs ml-2">(bulk)</span>}
</span>
</div>
)
})
)}
</div>
</div>