-
Notifications
You must be signed in to change notification settings - Fork 388
Media Assets Management Sidebar Tab Implementation #6112
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
viva-jinyi
wants to merge
4
commits into
main
Choose a base branch
from
feature/media-asset-sidebar-tab
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
4fcfc62
feat: Add Media Assets sidebar tab for file management
viva-jinyi dcc56cc
refactor: Apply PR #6112 review feedback for Media Assets feature
viva-jinyi 308f864
chore: unexpected export
viva-jinyi bee62d3
feat: Improve media asset display with file format tags and filename …
viva-jinyi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
<template> | ||
<SidebarTabTemplate :title="$t('sideToolbar.mediaAssets')"> | ||
<template #header> | ||
<Tabs v-model:value="activeTab" class="w-full"> | ||
<TabList class="border-b border-neutral-300"> | ||
<Tab value="input">{{ $t('sideToolbar.labels.imported') }}</Tab> | ||
<Tab value="output">{{ $t('sideToolbar.labels.generated') }}</Tab> | ||
</TabList> | ||
</Tabs> | ||
</template> | ||
<template #body> | ||
<VirtualGrid | ||
v-if="mediaAssets.length" | ||
:items="mediaAssetsWithKey" | ||
:grid-style="{ | ||
display: 'grid', | ||
gridTemplateColumns: 'repeat(auto-fill, minmax(200px, 1fr))', | ||
padding: '0.5rem', | ||
gap: '0.5rem' | ||
}" | ||
> | ||
<template #item="{ item }"> | ||
<MediaAssetCard | ||
:asset="item" | ||
:selected="selectedAsset?.id === item.id" | ||
@click="handleAssetSelect(item)" | ||
@zoom="handleZoomClick(item)" | ||
/> | ||
</template> | ||
</VirtualGrid> | ||
<div v-else-if="loading"> | ||
<ProgressSpinner | ||
style="width: 50px; left: 50%; transform: translateX(-50%)" | ||
/> | ||
</div> | ||
<div v-else> | ||
<NoResultsPlaceholder | ||
icon="pi pi-info-circle" | ||
:title=" | ||
$t( | ||
activeTab === 'input' | ||
? 'sideToolbar.noImportedFiles' | ||
: 'sideToolbar.noGeneratedFiles' | ||
) | ||
" | ||
:message="$t('sideToolbar.noFilesFoundMessage')" | ||
/> | ||
</div> | ||
</template> | ||
</SidebarTabTemplate> | ||
<ResultGallery | ||
v-model:active-index="galleryActiveIndex" | ||
:all-gallery-items="galleryItems" | ||
/> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import ProgressSpinner from 'primevue/progressspinner' | ||
import Tab from 'primevue/tab' | ||
import TabList from 'primevue/tablist' | ||
import Tabs from 'primevue/tabs' | ||
import { computed, onMounted, ref, watch } from 'vue' | ||
|
||
import NoResultsPlaceholder from '@/components/common/NoResultsPlaceholder.vue' | ||
import VirtualGrid from '@/components/common/VirtualGrid.vue' | ||
import SidebarTabTemplate from '@/components/sidebar/tabs/SidebarTabTemplate.vue' | ||
import ResultGallery from '@/components/sidebar/tabs/queue/ResultGallery.vue' | ||
import MediaAssetCard from '@/platform/assets/components/MediaAssetCard.vue' | ||
import { useMediaAssets } from '@/platform/assets/composables/useMediaAssets' | ||
import type { AssetItem } from '@/platform/assets/schemas/assetSchema' | ||
import { ResultItemImpl } from '@/stores/queueStore' | ||
import { getMediaTypeFromFilenamePlural } from '@/utils/formatUtil' | ||
|
||
const activeTab = ref<'input' | 'output'>('input') | ||
const mediaAssets = ref<AssetItem[]>([]) | ||
const selectedAsset = ref<AssetItem | null>(null) | ||
|
||
// Use unified media assets implementation that handles cloud/internal automatically | ||
const { loading, error, fetchMediaList } = useMediaAssets() | ||
|
||
const galleryActiveIndex = ref(-1) | ||
const galleryItems = computed(() => { | ||
// Convert AssetItems to ResultItemImpl format for gallery | ||
return mediaAssets.value.map((asset) => { | ||
const resultItem = new ResultItemImpl({ | ||
filename: asset.name, | ||
subfolder: '', | ||
type: 'output', | ||
nodeId: '0', | ||
mediaType: getMediaTypeFromFilenamePlural(asset.name) | ||
}) | ||
|
||
// Override the url getter to use asset.preview_url | ||
Object.defineProperty(resultItem, 'url', { | ||
get() { | ||
return asset.preview_url || '' | ||
}, | ||
configurable: true | ||
}) | ||
|
||
return resultItem | ||
}) | ||
}) | ||
|
||
// Add key property for VirtualGrid | ||
const mediaAssetsWithKey = computed(() => { | ||
return mediaAssets.value.map((asset) => ({ | ||
...asset, | ||
key: asset.id | ||
})) | ||
}) | ||
|
||
const refreshAssets = async () => { | ||
const files = await fetchMediaList(activeTab.value) | ||
mediaAssets.value = files | ||
if (error.value) { | ||
console.error('Failed to refresh assets:', error.value) | ||
} | ||
} | ||
|
||
watch(activeTab, () => { | ||
void refreshAssets() | ||
}) | ||
|
||
onMounted(() => { | ||
void refreshAssets() | ||
}) | ||
|
||
const handleAssetSelect = (asset: AssetItem) => { | ||
// Toggle selection | ||
if (selectedAsset.value?.id === asset.id) { | ||
selectedAsset.value = null | ||
} else { | ||
selectedAsset.value = asset | ||
} | ||
} | ||
|
||
const handleZoomClick = (asset: AssetItem) => { | ||
// Find the index of the clicked asset | ||
const index = mediaAssets.value.findIndex((a) => a.id === asset.id) | ||
if (index !== -1) { | ||
galleryActiveIndex.value = index | ||
} | ||
} | ||
</script> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { markRaw } from 'vue' | ||
|
||
import AssetsSidebarTab from '@/components/sidebar/tabs/AssetsSidebarTab.vue' | ||
import type { SidebarTabExtension } from '@/types/extensionTypes' | ||
|
||
export const useAssetsSidebarTab = (): SidebarTabExtension => { | ||
return { | ||
id: 'assets', | ||
icon: 'icon-[comfy--image-ai-edit]', | ||
title: 'sideToolbar.assets', | ||
tooltip: 'sideToolbar.assets', | ||
label: 'sideToolbar.labels.assets', | ||
component: markRaw(AssetsSidebarTab), | ||
type: 'vue' | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.