-
Notifications
You must be signed in to change notification settings - Fork 8
/
index.tsx
97 lines (89 loc) · 3.47 KB
/
index.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import {PropsWithNavigation} from '@global';
import {logger, printException} from '@helper/log';
import {useAppDispatch, useAppSelector} from '@hook/store';
import { fetchAlbumMediaAsync } from '@store/embySlice';
import {LayoutType, selectThemeBasicStyle, selectThemedPageStyle} from '@store/themeSlice';
import {ListView, kFullScreenStyle} from '@view/ListView';
import {MediaCard, MediaCardInLine} from '@view/MediaCard';
import {Spin} from '@view/Spin';
import _ from 'lodash';
import React, {useEffect, useState} from 'react';
import {StyleSheet, View} from 'react-native';
const style = StyleSheet.create({
root: {
flex: 1,
flexDirection: 'column',
flexWrap: 'wrap',
alignItems: 'center',
justifyContent: 'center',
},
});
export function Page({ route}: PropsWithNavigation<'album'>) {
const data = useAppSelector(state => state.emby?.source?.albumMedia?.[route.params.albumId]);
const [loading, setLoading] = useState(true);
const theme = useAppSelector(selectThemeBasicStyle);
const pageStyle = useAppSelector(selectThemedPageStyle);
const dispatch = useAppDispatch()
const layoutType = useAppSelector(state => state.theme.albumLayoutType);
const cached = data?.length ?? 0 > 0
useEffect(() => {
setLoading(!cached);
logger.info("fetch album medias", route.params.albumId)
const id = route.params.albumId;
const query = {
id,
options: {
SortBy: "DateLastContentAdded,SortName"
}
}
dispatch(fetchAlbumMediaAsync(query))
.then(() => {
setLoading(false)
})
.catch(printException)
.finally(() => setLoading(false));
}, [route.params.albumId]);
const onVisibleIndicesChanged = () => {
};
const onEndReached = () => {};
const rowItemWidth =
(kFullScreenStyle.width - 20) /
Math.floor((kFullScreenStyle.width - 20) / 120);
logger.info(`data[0] = ${data?.[0]}`)
return (
<View style={{...style.root, paddingTop: pageStyle.paddingTop}}>
{data && data.length > 0 ? (
<ListView
items={data}
style={{width: '100%', flex: 1, padding: 10}}
typeForIndex={() => layoutType ?? LayoutType.Card}
layoutForType={(i, dim) => {
if (i === LayoutType.Card) {
dim.width = rowItemWidth;
dim.height = 200;
} else {
dim.width = kFullScreenStyle.width;
dim.height = 200;
}
}}
onVisibleIndicesChanged={onVisibleIndicesChanged}
onEndReached={onEndReached}
render={(media, i, type) => (
type == LayoutType.Card ?
<MediaCard
key={media?.Id ?? `media-${i}`}
media={media}
theme={theme}
/> :
<MediaCardInLine
key={media?.Id ?? `media-${i}`}
media={media}
theme={theme}
/>
)}
/>
) : null}
{loading ? <Spin color={theme.color} /> : null}
</View>
);
}