Files
jellyfin-audio-player/src/screens/Player/components/Queue.tsx

75 lines
2.6 KiB
TypeScript
Raw Normal View History

2020-07-10 15:47:03 +02:00
import React, { useCallback } from 'react';
2020-06-21 10:30:41 +02:00
import useQueue from 'utility/useQueue';
import { View, StyleSheet } from 'react-native';
2020-06-16 17:51:51 +02:00
import styled, { css } from 'styled-components/native';
2020-06-21 10:30:41 +02:00
import useCurrentTrack from 'utility/useCurrentTrack';
import TouchableHandler from 'components/TouchableHandler';
2020-07-10 15:47:03 +02:00
import TrackPlayer from 'react-native-track-player';
2020-11-02 22:50:00 +01:00
import { t } from '@localisation';
import useDefaultStyles from 'components/Colors';
import Text from 'components/Text';
import Button from 'components/Button';
2022-01-01 19:09:21 +01:00
import { THEME_COLOR } from 'CONSTANTS';
2020-06-16 17:51:51 +02:00
2020-07-26 14:45:32 +02:00
const QueueItem = styled.View<{ active?: boolean, alreadyPlayed?: boolean, isDark?: boolean }>`
2020-06-16 17:51:51 +02:00
padding: 10px;
border-bottom-width: 1px;
${props => props.active && css`
font-weight: 900;
padding: 20px 35px;
margin: 0 -25px;
`}
${props => props.alreadyPlayed && css`
2020-07-26 14:45:32 +02:00
opacity: 0.5;
2020-06-16 17:51:51 +02:00
`}
`;
2020-08-28 12:45:00 +02:00
const ClearQueue = styled.View`
margin: 20px 0;
`;
2020-07-26 14:45:32 +02:00
const styles = StyleSheet.create({
trackTitle: {
marginBottom: 2
2020-07-26 14:45:32 +02:00
}
});
2020-06-16 17:51:51 +02:00
export default function Queue() {
const defaultStyles = useDefaultStyles();
2020-06-16 17:51:51 +02:00
const queue = useQueue();
const { index: currentIndex } = useCurrentTrack();
const playTrack = useCallback(async (index: number) => {
await TrackPlayer.skip(index);
2020-07-10 15:47:03 +02:00
await TrackPlayer.play();
}, []);
2020-08-28 12:45:00 +02:00
const clearQueue = useCallback(async () => {
await TrackPlayer.reset();
}, []);
2020-06-16 17:51:51 +02:00
return (
<View>
2020-11-02 22:50:00 +01:00
<Text style={{ marginTop: 20, marginBottom: 20 }}>{t('queue')}</Text>
{queue.map((track, i) => (
<TouchableHandler id={i} onPress={playTrack} key={i}>
2020-07-26 14:45:32 +02:00
<QueueItem
active={currentIndex === i}
2020-07-26 14:45:32 +02:00
key={i}
alreadyPlayed={currentIndex ? i < currentIndex : false}
style={[
defaultStyles.border,
currentIndex === i ? defaultStyles.activeBackground : {},
]}
2020-07-26 14:45:32 +02:00
>
2022-01-01 19:09:21 +01:00
<Text style={currentIndex === i ? { color: THEME_COLOR, fontWeight: '700' } : styles.trackTitle}>{track.title}</Text>
<Text style={currentIndex === i ? { color: THEME_COLOR, fontWeight: '400' } : defaultStyles.textHalfOpacity}>{track.artist}</Text>
</QueueItem>
</TouchableHandler>
2020-06-16 17:51:51 +02:00
))}
2020-08-28 12:45:00 +02:00
<ClearQueue>
<Button title={t('clear-queue')} onPress={clearQueue} />
2020-08-28 12:45:00 +02:00
</ClearQueue>
2020-06-16 17:51:51 +02:00
</View>
);
}