Skip to content

Commit 466f39c

Browse files
committed
refactor:
- refactor(components): Use defineModel in TabList.vue for cleaner v-model implementation - refactor(components): Extract MediaTitle component to eliminate duplication across media bottom components - Consolidate title rendering logic from MediaImageBottom, MediaVideoBottom, MediaAudioBottom, Media3DBottom - Improve code reusability and maintainability - refactor(composables): Restructure useMediaAssets directory structure - Rename directory from 'useMediaAssets' to 'media' - Rename index.ts to useMediaAssets.ts to avoid index pattern - Update all import paths accordingly - refactor(utils): Simplify UUID utility exports - Remove isValidUuid wrapper function - Export validate directly from uuid library - Update tests to use validate instead of isValidUuid - test(formatUtil): Apply it.for pattern for better test readability - Convert repetitive test cases to data-driven tests using it.for
1 parent ce54700 commit 466f39c

File tree

17 files changed

+75
-86
lines changed

17 files changed

+75
-86
lines changed

src/components/sidebar/tabs/AssetsSidebarTab.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ import Tab from '@/components/tab/Tab.vue'
100100
import TabList from '@/components/tab/TabList.vue'
101101
import { t } from '@/i18n'
102102
import MediaAssetCard from '@/platform/assets/components/MediaAssetCard.vue'
103-
import { useMediaAssets } from '@/platform/assets/composables/useMediaAssets'
103+
import { useMediaAssets } from '@/platform/assets/composables/media/useMediaAssets'
104104
import { getOutputAssetMetadata } from '@/platform/assets/schemas/assetMetadataSchema'
105105
import type { AssetItem } from '@/platform/assets/schemas/assetSchema'
106106
import { ResultItemImpl } from '@/stores/queueStore'

src/components/tab/TabList.vue

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,13 @@
55
</template>
66

77
<script setup lang="ts">
8-
import { provide, toRef } from 'vue'
8+
import { provide } from 'vue'
99
10-
const props = defineProps<{
11-
modelValue: string
12-
}>()
13-
14-
const emit = defineEmits<{
15-
'update:modelValue': [value: string]
16-
}>()
10+
const modelValue = defineModel<string>({ required: true })
1711
1812
// Provide for child Tab components
19-
provide('tabs-value', toRef(props, 'modelValue'))
20-
provide('tabs-update', (value: string) => emit('update:modelValue', value))
13+
provide('tabs-value', modelValue)
14+
provide('tabs-update', (value: string) => {
15+
modelValue.value = value
16+
})
2117
</script>

src/platform/assets/components/Media3DBottom.vue

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
<template>
22
<div class="flex flex-col items-center gap-1">
3-
<h3
4-
class="m-0 line-clamp-1 text-sm font-bold text-zinc-900 dark-theme:text-white"
5-
:title="asset.name"
6-
>
7-
{{ truncateFilename(fileName) }}
8-
</h3>
3+
<MediaTitle :file-name="fileName" />
94
<div class="flex items-center gap-2 text-xs text-zinc-400">
105
<span>{{ formatSize(asset.size) }}</span>
116
</div>
@@ -15,13 +10,10 @@
1510
<script setup lang="ts">
1611
import { computed } from 'vue'
1712
18-
import {
19-
formatSize,
20-
getFilenameDetails,
21-
truncateFilename
22-
} from '@/utils/formatUtil'
13+
import { formatSize, getFilenameDetails } from '@/utils/formatUtil'
2314
2415
import type { AssetMeta } from '../schemas/mediaAssetSchema'
16+
import MediaTitle from './MediaTitle.vue'
2517
2618
const { asset } = defineProps<{
2719
asset: AssetMeta

src/platform/assets/components/MediaAssetCard.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,8 @@ import SquareChip from '@/components/chip/SquareChip.vue'
143143
import { formatDuration, getMediaTypeFromFilename } from '@/utils/formatUtil'
144144
import { cn } from '@/utils/tailwindUtil'
145145
146+
import { getAssetType } from '../composables/media/assetMappers'
146147
import { useMediaAssetActions } from '../composables/useMediaAssetActions'
147-
import { getAssetType } from '../composables/useMediaAssets/assetMappers'
148148
import type { AssetItem } from '../schemas/assetSchema'
149149
import type { MediaKind } from '../schemas/mediaAssetSchema'
150150
import { MediaAssetKey } from '../schemas/mediaAssetSchema'

src/platform/assets/components/MediaAudioBottom.vue

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
<template>
22
<div class="flex flex-col items-center gap-1">
3-
<h3
4-
class="m-0 line-clamp-1 text-sm font-bold text-zinc-900 dark-theme:text-white"
5-
:title="asset.name"
6-
>
7-
{{ truncateFilename(fileName) }}
8-
</h3>
3+
<MediaTitle :file-name="fileName" />
94
<div class="flex items-center gap-2 text-xs text-zinc-400">
105
<span>{{ formatSize(asset.size) }}</span>
116
</div>
@@ -15,13 +10,10 @@
1510
<script setup lang="ts">
1611
import { computed } from 'vue'
1712
18-
import {
19-
formatSize,
20-
getFilenameDetails,
21-
truncateFilename
22-
} from '@/utils/formatUtil'
13+
import { formatSize, getFilenameDetails } from '@/utils/formatUtil'
2314
2415
import type { AssetContext, AssetMeta } from '../schemas/mediaAssetSchema'
16+
import MediaTitle from './MediaTitle.vue'
2517
2618
const { asset } = defineProps<{
2719
asset: AssetMeta

src/platform/assets/components/MediaImageBottom.vue

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
<template>
22
<div class="flex flex-col items-center gap-1">
3-
<h3
4-
class="m-0 line-clamp-1 text-sm font-bold text-zinc-900 dark-theme:text-white"
5-
:title="asset.name"
6-
>
7-
{{ truncateFilename(fileName) }}
8-
</h3>
3+
<MediaTitle :file-name="fileName" />
94
<div class="flex items-center text-xs text-zinc-400">
105
<span v-if="asset.dimensions"
116
>{{ asset.dimensions?.width }}x{{ asset.dimensions?.height }}</span
@@ -17,9 +12,10 @@
1712
<script setup lang="ts">
1813
import { computed } from 'vue'
1914
20-
import { getFilenameDetails, truncateFilename } from '@/utils/formatUtil'
15+
import { getFilenameDetails } from '@/utils/formatUtil'
2116
2217
import type { AssetContext, AssetMeta } from '../schemas/mediaAssetSchema'
18+
import MediaTitle from './MediaTitle.vue'
2319
2420
const { asset } = defineProps<{
2521
asset: AssetMeta
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<template>
2+
<h3
3+
class="m-0 line-clamp-1 text-sm font-bold text-zinc-900 dark-theme:text-white"
4+
:title="fullName"
5+
>
6+
{{ displayName }}
7+
</h3>
8+
</template>
9+
10+
<script setup lang="ts">
11+
import { computed } from 'vue'
12+
13+
import { truncateFilename } from '@/utils/formatUtil'
14+
15+
const props = defineProps<{
16+
fileName: string
17+
}>()
18+
19+
const fullName = computed(() => props.fileName)
20+
const displayName = computed(() => truncateFilename(props.fileName))
21+
</script>

src/platform/assets/components/MediaVideoBottom.vue

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
<template>
22
<div class="flex flex-col items-center gap-1">
3-
<h3
4-
class="m-0 line-clamp-1 text-sm font-bold text-zinc-900 dark-theme:text-white"
5-
:title="asset.name"
6-
>
7-
{{ truncateFilename(fileName) }}
8-
</h3>
3+
<MediaTitle :file-name="fileName" />
94
<div class="flex items-center text-xs text-zinc-400">
105
<span>{{ formatSize(asset.size) }}</span>
116
</div>
@@ -15,13 +10,10 @@
1510
<script setup lang="ts">
1611
import { computed } from 'vue'
1712
18-
import {
19-
formatSize,
20-
getFilenameDetails,
21-
truncateFilename
22-
} from '@/utils/formatUtil'
13+
import { formatSize, getFilenameDetails } from '@/utils/formatUtil'
2314
2415
import type { AssetContext, AssetMeta } from '../schemas/mediaAssetSchema'
16+
import MediaTitle from './MediaTitle.vue'
2517
2618
const { asset } = defineProps<{
2719
asset: AssetMeta

0 commit comments

Comments
 (0)