1
1
<script lang="ts" setup>
2
- import { onActivated , onDeactivated , onMounted , ref , watch } from ' vue' ;
2
+ import { computed , onActivated , onDeactivated , onMounted , ref , watch } from ' vue' ;
3
3
4
- import type { OnScroll , OnUpdated } from ' ~/components/common/list/ListScroll.model' ;
4
+ import type {
5
+ ListScrollItem ,
6
+ OnScroll ,
7
+ OnUpdated ,
8
+ } from ' ~/components/common/list/ListScroll.model' ;
5
9
6
10
import ListScroll from ' ~/components/common/list/ListScroll.vue' ;
7
- import HistoryItem from ' ~/components/views/history/HistoryItem.vue' ;
8
11
9
12
import { useHistoryStore , useHistoryStoreRefs } from ' ~/stores/data/history.store' ;
10
13
import { useUserSettingsStoreRefs } from ' ~/stores/settings/user.store' ;
11
14
12
- const {
13
- filteredHistory : history,
14
- pagination,
15
- loading,
16
- pageSize,
17
- belowThreshold,
18
- } = useHistoryStoreRefs ();
15
+ const { filteredHistory, pagination, loading, pageSize, belowThreshold } =
16
+ useHistoryStoreRefs ();
19
17
const { fetchHistory, clearState } = useHistoryStore ();
20
18
21
19
const { user } = useUserSettingsStoreRefs ();
@@ -41,6 +39,26 @@ onMounted(() => {
41
39
});
42
40
});
43
41
42
+ const history = computed <ListScrollItem []>(() => {
43
+ const array = filteredHistory .value ;
44
+ if (! array .length ) return [];
45
+ return array .map ((item , index ) => {
46
+ const _item: ListScrollItem = { ... item , index , loading: item .id < 0 };
47
+ if (! item .watched_at ) return _item ;
48
+
49
+ const date: ListScrollItem [' date' ] = { current: new Date (item .watched_at ) };
50
+ if (index > 1 && array [index - 1 ]?.watched_at ) {
51
+ date .previous = new Date (array [index - 1 ]?.watched_at );
52
+ }
53
+ if (array [index + 1 ]?.watched_at ) {
54
+ date .next = new Date (array [index + 1 ]?.watched_at );
55
+ }
56
+ date .sameDay =
57
+ date .previous ?.toLocaleDateString () === date .current ?.toLocaleDateString ();
58
+ return { ... _item , date };
59
+ });
60
+ });
61
+
44
62
const onScroll: OnScroll = async listRef => {
45
63
const key = history .value [history .value .length - 1 ].id ;
46
64
await fetchHistory ({
@@ -72,8 +90,8 @@ const onUpdated: OnUpdated = listRef => {
72
90
@on-scroll-top =" () => console.info('Scrolled to top')"
73
91
@on-updated =" onUpdated"
74
92
>
75
- <template #default = " { item , loading: itemLoading } " >
76
- <HistoryItem :item = " item " :loading = " itemLoading " / >
93
+ <template #default >
94
+ <!-- TODO buttons here -- >
77
95
</template >
78
96
</ListScroll >
79
97
</template >
0 commit comments