Skip to content

Commit b035bc8

Browse files
committed
fix: Prevent gallery index shift when new outputs are generated
- Fix issue where viewing image changes when new outputs are added to the gallery - Add currentGalleryAssetId ref to track the opened asset ID - Update index to maintain same image when displayAssets changes - Clear stored ID when gallery closes
1 parent 466f39c commit b035bc8

File tree

1 file changed

+29
-18
lines changed

1 file changed

+29
-18
lines changed

src/components/sidebar/tabs/AssetsSidebarTab.vue

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,35 @@ const error = computed(() => currentAssets.value.error.value)
144144
const mediaAssets = computed(() => currentAssets.value.media.value)
145145
146146
const galleryActiveIndex = ref(-1)
147+
const currentGalleryAssetId = ref<string | null>(null)
148+
149+
const folderAssets = ref<AssetItem[]>([])
150+
151+
const displayAssets = computed(() => {
152+
if (isInFolderView.value) {
153+
return folderAssets.value
154+
}
155+
return mediaAssets.value
156+
})
157+
158+
watch(displayAssets, (newAssets) => {
159+
if (currentGalleryAssetId.value && galleryActiveIndex.value !== -1) {
160+
const newIndex = newAssets.findIndex(
161+
(asset) => asset.id === currentGalleryAssetId.value
162+
)
163+
if (newIndex !== -1) {
164+
galleryActiveIndex.value = newIndex
165+
}
166+
}
167+
})
168+
169+
watch(galleryActiveIndex, (index) => {
170+
if (index === -1) {
171+
currentGalleryAssetId.value = null
172+
}
173+
})
174+
147175
const galleryItems = computed(() => {
148-
// Convert AssetItems to ResultItemImpl format for gallery
149-
// Use displayAssets instead of mediaAssets to show correct items based on view mode
150176
return displayAssets.value.map((asset) => {
151177
const mediaType = getMediaTypeFromFilename(asset.name)
152178
const resultItem = new ResultItemImpl({
@@ -168,20 +194,6 @@ const galleryItems = computed(() => {
168194
})
169195
})
170196
171-
// Store folder view assets separately
172-
const folderAssets = ref<AssetItem[]>([])
173-
174-
// Get display assets based on view mode
175-
const displayAssets = computed(() => {
176-
if (isInFolderView.value) {
177-
// Show all assets from the folder view
178-
return folderAssets.value
179-
}
180-
181-
// Normal view: show grouped assets (already have outputCount from API)
182-
return mediaAssets.value
183-
})
184-
185197
// Add key property for VirtualGrid
186198
const mediaAssetsWithKey = computed(() => {
187199
return displayAssets.value.map((asset) => ({
@@ -206,7 +218,6 @@ watch(
206218
)
207219
208220
const handleAssetSelect = (asset: AssetItem) => {
209-
// Toggle selection
210221
if (selectedAsset.value?.id === asset.id) {
211222
selectedAsset.value = null
212223
} else {
@@ -215,7 +226,7 @@ const handleAssetSelect = (asset: AssetItem) => {
215226
}
216227
217228
const handleZoomClick = (asset: AssetItem) => {
218-
// Find the index of the clicked asset
229+
currentGalleryAssetId.value = asset.id
219230
const index = displayAssets.value.findIndex((a) => a.id === asset.id)
220231
if (index !== -1) {
221232
galleryActiveIndex.value = index

0 commit comments

Comments
 (0)