Skip to content
This repository has been archived by the owner on Sep 16, 2024. It is now read-only.

Commit

Permalink
Add all tv show seasons list
Browse files Browse the repository at this point in the history
Closes #17
  • Loading branch information
sikelio committed Apr 25, 2023
1 parent eba0eaf commit 8ced692
Show file tree
Hide file tree
Showing 4 changed files with 197 additions and 102 deletions.
228 changes: 129 additions & 99 deletions src/screens/SingleLibrary.jsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
// Dependencies
import React, { useState } from "react";
import axios from "axios";
// Components
import { ScrollView, View } from "react-native";
import { Card, Button, ListItem, Avatar } from "@rneui/themed";
import FastImage from "react-native-fast-image";
import Spinner from "react-native-loading-spinner-overlay";
// Functions
import { sendPutRequest, sendRequest } from "../functions/ServerRequest";
// Styles
Expand All @@ -13,114 +15,142 @@ const SingleLibrary = ({ route, navigation }) => {
const { medias, library, server } = route.params;

const [ mediaList, setMediaList ] = useState(false);
const [ spinner, setSpinner ] = useState(false);

return (
<ScrollView>
<Card>
<Card.Title>Actions</Card.Title>
<Card.Divider />
<View style={ [style.container, style.upperContainer] }>
<Button
title='Scan'
containerStyle={{
width: '48%'
}}
buttonStyle={{
backgroundColor: '#e5a00d'
}}
onPress={() => {
sendRequest(`${server.protocol}://${server.ip}:${server.port}/library/sections/${library.key}/refresh?X-Plex-Token=${server.token}`);
}}
/>
<View style={ [style.libraryContainer] }>
<Spinner
visible={ spinner }
textContent={'Loading...'}
/>

<Button
title='Metadata'
containerStyle={{
width: '48%'
}}
buttonStyle={{
backgroundColor: '#e5a00d'
}}
onPress={() => {
sendRequest(`${server.protocol}://${server.ip}:${server.port}/library/sections/${library.key}/refresh?force=1&X-Plex-Token=${server.token}`);
}}
/>
</View>
<ScrollView>
<Card>
<Card.Title>Actions</Card.Title>
<Card.Divider />
<View style={ [style.container, style.upperContainer] }>
<Button
title='Scan'
containerStyle={{
width: '48%'
}}
buttonStyle={{
backgroundColor: '#e5a00d'
}}
onPress={() => {
sendRequest(`${server.protocol}://${server.ip}:${server.port}/library/sections/${library.key}/refresh?X-Plex-Token=${server.token}`);
}}
/>

<View style={ [style.container] }>
<Button
title='Empty Trash'
containerStyle={{
width: '100%'
}}
buttonStyle={{
backgroundColor: '#e5a00d'
}}
<Button
title='Metadata'
containerStyle={{
width: '48%'
}}
buttonStyle={{
backgroundColor: '#e5a00d'
}}
onPress={() => {
sendRequest(`${server.protocol}://${server.ip}:${server.port}/library/sections/${library.key}/refresh?force=1&X-Plex-Token=${server.token}`);
}}
/>
</View>

<View style={ [style.container] }>
<Button
title='Empty Trash'
containerStyle={{
width: '100%'
}}
buttonStyle={{
backgroundColor: '#e5a00d'
}}
onPress={() => {
sendPutRequest(`${server.protocol}://${server.ip}:${server.port}/library/sections/${library.key}/emptyTrash?X-Plex-Token=${server.token}`);
}}
/>
</View>
</Card>

<Card>
<ListItem.Accordion
content={
<ListItem.Content>
<ListItem.Title style={ [style.accordionTitle] }>Medias</ListItem.Title>
</ListItem.Content>
}
isExpanded={ mediaList }
onPress={() => {
sendPutRequest(`${server.protocol}://${server.ip}:${server.port}/library/sections/${library.key}/emptyTrash?X-Plex-Token=${server.token}`);
setMediaList(!mediaList);
}}
/>
</View>
</Card>
>
{medias.map((media, index) => {
return (
<ListItem
key={ index }
bottomDivider
onPress={async () => {
setSpinner(true);

if (library.type !== 'show') {
return navigation.navigate('SingleMedia', {
title: media.title,
library: library,
media: media,
server: server
});
}

try {
let seasons = await axios.get(`${server.protocol}://${server.ip}:${server.port}${media.key}?X-Plex-Token=${server.token}`);

navigation.navigate('SingleMedia', {
title: media.title,
library: library,
media: media,
server: server,
seasons: seasons.data.MediaContainer.Metadata
});

<Card>
<ListItem.Accordion
content={
<ListItem.Content>
<ListItem.Title style={ [style.accordionTitle] }>Medias</ListItem.Title>
</ListItem.Content>
}
isExpanded={ mediaList }
onPress={() => {
setMediaList(!mediaList);
}}
>
{medias.map((media, index) => {
return (
<ListItem
key={ index }
bottomDivider
onPress={() => {
navigation.navigate('SingleMedia', {
title: media.title,
library: library,
media: media,
server: server
});
}}
>
<Avatar
ImageComponent={() => (
<FastImage
style={{
width: 32,
height: 32,
position: 'absolute'
}}
source={{
uri: `${server.protocol}://${server.ip}:${server.port}${media.thumb}?X-Plex-Token=${server.token}`,
priority: FastImage.priority.normal,
}}
resizeMode={ FastImage.resizeMode.contain }
/>
)}
overlayContainerStyle={{
justifyContent: 'center',
alignItems: 'center',
setSpinner(false);
} catch (e) {
console.error(e)
}
}}
/>
>
<Avatar
ImageComponent={() => (
<FastImage
style={{
width: 32,
height: 32,
position: 'absolute'
}}
source={{
uri: `${server.protocol}://${server.ip}:${server.port}${media.thumb}?X-Plex-Token=${server.token}`,
priority: FastImage.priority.normal,
}}
resizeMode={ FastImage.resizeMode.contain }
/>
)}
overlayContainerStyle={{
justifyContent: 'center',
alignItems: 'center',
}}
/>

<ListItem.Content>
<ListItem.Title>{ media.title }</ListItem.Title>
<ListItem.Subtitle>{ media.studio }</ListItem.Subtitle>
</ListItem.Content>
<ListItem.Chevron />
</ListItem>
);
})}
</ListItem.Accordion>
</Card>
</ScrollView>
<ListItem.Content>
<ListItem.Title>{ media.title }</ListItem.Title>
<ListItem.Subtitle>{ media.studio }</ListItem.Subtitle>
</ListItem.Content>
<ListItem.Chevron />
</ListItem>
);
})}
</ListItem.Accordion>
</Card>
</ScrollView>
</View>
);
}

Expand Down
62 changes: 60 additions & 2 deletions src/screens/SingleMedia.jsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
// Dependencies
import React, { useState } from "react";
// Components
import { Dimensions, ScrollView, Text, View } from "react-native";
import { Card } from "@rneui/themed";
import { Avatar, Card, ListItem } from "@rneui/themed";
import FastImage from "react-native-fast-image";
// Functions
import { getDateFromTimestamp, getTimeFromTimestamp } from "../functions/GlobalUtiles";
// Styles
import style from "../style/SingleMediaStyle";

const SingleMedia = ({ route }) => {
const { media, server } = route.params;
const { media, library, server, seasons } = route.params;

const [ seasonsList, setSeasonsList ] = useState(false);

const mainImgWidth = Dimensions.get('window').width;
const mainImgHeight = (Dimensions.get('window').width * 9 / 16);
Expand Down Expand Up @@ -53,6 +57,60 @@ const SingleMedia = ({ route }) => {
</Text>
</View>
</Card>

{library.type === 'show' ? (
<Card>
<ListItem.Accordion
content={
<ListItem.Content>
<ListItem.Title style={ [style.accordionTitle] }>Seasons</ListItem.Title>
</ListItem.Content>
}
isExpanded={ seasonsList }
onPress={() => {
setSeasonsList(!seasonsList);
}}
>
{seasons.map((season, index) => {
return (
<ListItem
key={ index }
bottomDivider
>
<Avatar
ImageComponent={() => (
<FastImage
style={{
width: 32,
height: 32,
position: 'absolute'
}}
source={{
uri: `${server.protocol}://${server.ip}:${server.port}${season.thumb}?X-Plex-Token=${server.token}`,
priority: FastImage.priority.normal,
}}
resizeMode={ FastImage.resizeMode.contain }
/>
)}
overlayContainerStyle={{
justifyContent: 'center',
alignItems: 'center',
}}
/>

<ListItem.Content>
<ListItem.Title>{ season.title }</ListItem.Title>
<ListItem.Subtitle>{ season.year ? season.year : season.parentYear }</ListItem.Subtitle>
</ListItem.Content>
<ListItem.Chevron></ListItem.Chevron>
</ListItem>
)
})}
</ListItem.Accordion>
</Card>
) : (
<Text></Text>
)}
</ScrollView>
);
}
Expand Down
3 changes: 3 additions & 0 deletions src/style/LibraryManageStyle.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
import { StyleSheet } from "react-native";

const style = StyleSheet.create({
libraryContainer: {
flex: 1
},
container: {
flexDirection: 'row',
justifyContent: 'space-between',
Expand Down
6 changes: 5 additions & 1 deletion src/style/SingleMediaStyle.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ const style = StyleSheet.create({
},
textLabel: {
fontWeight: 'bold'
}
},
accordionTitle: {
fontWeight: 'bold',
fontSize: 14
},
});

export default style;

0 comments on commit 8ced692

Please sign in to comment.