1
1
<script setup lang="ts">
2
- import { NEmpty , NFlex , NImage , NSkeleton , NTime , NTimelineItem } from ' naive-ui' ;
2
+ import { NEmpty , NFlex , NSkeleton , NTime , NTimelineItem } from ' naive-ui' ;
3
3
4
4
import {
5
5
computed ,
@@ -9,14 +9,13 @@ import {
9
9
type PropType ,
10
10
ref ,
11
11
toRefs ,
12
- watch ,
13
12
} from ' vue' ;
14
13
15
- import PosterPlaceholder from ' ~/assets/images/poster-placholder.webp' ;
14
+ import type { PosterItem } from ' ~/models/poster.model' ;
15
+
16
16
import ListItemPanel from ' ~/components/common/list/ListItemPanel.vue' ;
17
+ import PosterComponent from ' ~/components/common/poster/PosterComponent.vue' ;
17
18
import { type ListScrollItem , ListScrollItemType } from ' ~/models/list-scroll.model' ;
18
-
19
- import { useImageStore } from ' ~/stores/data/image.store' ;
20
19
import { Colors } from ' ~/styles/colors.style' ;
21
20
import { useI18n } from ' ~/utils' ;
22
21
@@ -110,50 +109,6 @@ const year = new Date().getFullYear();
110
109
const sameYear = computed (() => date .value ?.getFullYear () === year );
111
110
const loading = computed (() => item ?.value ?.loading );
112
111
113
- const { getImageUrl } = useImageStore ();
114
-
115
- const resolvedPoster = computed (() => {
116
- if (poster ?.value ) return poster .value ;
117
- if (item .value .poster ) return item .value .poster ;
118
- const image = item .value .posterRef ?.value ;
119
- if (! image ) return ;
120
- if (typeof image === ' string' ) return image ;
121
- if (episode .value && ' backdrop' in image ) return image .backdrop ;
122
- return image .poster ;
123
- });
124
-
125
- const objectFit = computed (() =>
126
- resolvedPoster .value === PosterPlaceholder ? ' contain' : ' cover' ,
127
- );
128
-
129
- const imgLoaded = ref (true );
130
-
131
- const onLoad = () => {
132
- imgLoaded .value = true ;
133
- };
134
-
135
- const transition = ref (false );
136
- const timeout = ref ();
137
-
138
- const getPosters = (_item : ListScrollItem ) => {
139
- imgLoaded .value = false ;
140
- if (_item .posterRef ?.value ) return ;
141
- if (! _item .posterRef ) return ;
142
- const query = _item .getPosterQuery ?.();
143
- if (! query ) return ;
144
- if (! episode .value && _item .type === ' episode' ) {
145
- query .type = ' show' ;
146
- delete query .episode ;
147
- }
148
- setTimeout (() => {
149
- if (resolvedPoster .value ) return ;
150
- transition .value = true ;
151
- }, 100 );
152
- getImageUrl (query , 300 , _item .posterRef );
153
- };
154
-
155
- watch (item , getPosters , { immediate: true , flush: ' post' });
156
-
157
112
const itemRef = ref <HTMLElement & InstanceType <typeof NTimelineItem >>();
158
113
159
114
onMounted (() => {
@@ -165,7 +120,6 @@ onMounted(() => {
165
120
});
166
121
167
122
onBeforeUnmount (() => {
168
- clearTimeout (timeout .value );
169
123
if (! scrollIntoView .value ) return ;
170
124
emit (' onScrollOutOfView' , {
171
125
item: item ?.value ,
@@ -243,32 +197,10 @@ const onClick = () => emit('onItemClick', { item: item?.value });
243
197
</NFlex >
244
198
</slot >
245
199
<NFlex v-else class =" tile" :wrap =" false" >
246
- <NImage
247
- alt =" poster-image"
248
- class =" poster"
249
- :class =" {
250
- episode,
251
- loading: !imgLoaded,
252
- transition,
253
- }"
254
- :object-fit =" objectFit"
255
- width =" 100%"
256
- lazy
257
- preview-disabled
258
- :src =" resolvedPoster"
259
- :fallback-src =" PosterPlaceholder"
260
- :on-load =" onLoad"
261
- />
262
- <NImage
263
- alt =" poster-image-fallback"
264
- class =" poster placeholder"
265
- :class =" { episode }"
266
- object-fit =" contain"
267
- width =" 100%"
268
- lazy
269
- preview-disabled
270
- :src =" PosterPlaceholder"
271
- :fallback-src =" PosterPlaceholder"
200
+ <PosterComponent
201
+ :item =" item as PosterItem"
202
+ :poster =" poster"
203
+ :episode =" episode"
272
204
/>
273
205
<ListItemPanel
274
206
:item =" item"
0 commit comments