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

77 lines
2.4 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';
2020-08-28 12:45:00 +02:00
import { View, Text, StyleSheet, Button } 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-07-10 15:25:32 +02:00
import { THEME_COLOR } from 'CONSTANTS';
2020-07-26 14:45:32 +02:00
import { colors } from 'components/Colors';
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({
title: {
...colors.text,
marginBottom: 2,
},
artist: {
...colors.text,
opacity: 0.5,
}
});
2020-06-16 17:51:51 +02:00
export default function Queue() {
const queue = useQueue();
const currentTrack = useCurrentTrack();
const currentIndex = queue.findIndex(d => d.id === currentTrack?.id);
2020-07-10 15:47:03 +02:00
const playTrack = useCallback(async (trackId: string) => {
await TrackPlayer.skip(trackId);
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>
<Text style={{ marginTop: 20, marginBottom: 20 }}>Queue</Text>
{queue.map((track, i) => (
2020-06-21 10:58:47 +02:00
<TouchableHandler id={track.id} onPress={playTrack} key={i}>
2020-07-26 14:45:32 +02:00
<QueueItem
active={currentTrack?.id === track.id}
key={i}
alreadyPlayed={i < currentIndex}
style={{
...colors.border,
...currentTrack?.id === track.id ? colors.activeBackground : {},
}}
>
<Text style={styles.title}>{track.title}</Text>
<Text style={styles.artist}>{track.artist}</Text>
</QueueItem>
</TouchableHandler>
2020-06-16 17:51:51 +02:00
))}
2020-08-28 12:45:00 +02:00
<ClearQueue>
<Button title="Clear Queue" color={THEME_COLOR} onPress={clearQueue} />
</ClearQueue>
2020-06-16 17:51:51 +02:00
</View>
);
}