From de07fc65c498f4544ef97dfa54723ae1f6419ddd Mon Sep 17 00:00:00 2001 From: Lei Nelissen Date: Tue, 17 May 2022 23:34:25 +0200 Subject: [PATCH] Restyle the downloads screen --- src/components/Button.tsx | 32 ++++++++++--- src/screens/Downloads/index.tsx | 85 ++++++++++++++++++++------------- src/utility/formatBytes.ts | 2 +- 3 files changed, 79 insertions(+), 40 deletions(-) diff --git a/src/components/Button.tsx b/src/components/Button.tsx index cc58a91..cebcb2d 100644 --- a/src/components/Button.tsx +++ b/src/components/Button.tsx @@ -7,13 +7,16 @@ import { THEME_COLOR } from 'CONSTANTS'; import styled, { css } from 'styled-components/native'; import useDefaultStyles from './Colors'; +type ButtonSize = 'default' | 'small'; + interface ButtonProps extends PressableProps { icon?: React.FC; - title: string; + title?: string; style?: ViewProps['style']; + size?: ButtonSize; } -const BaseButton = styled.Pressable` +const BaseButton = styled.Pressable<{ size: ButtonSize }>` padding: 12px; border-radius: 8px; flex-direction: row; @@ -24,16 +27,25 @@ const BaseButton = styled.Pressable` ${(props) => props.disabled && css` opacity: 0.25; `} + + ${(props) => props.size === 'small' && css` + flex-grow: 0; + padding: 10px; + `} `; -const ButtonText = styled.Text<{ active?: boolean }>` +const ButtonText = styled.Text<{ active?: boolean, size: ButtonSize }>` color: ${THEME_COLOR}; font-weight: 500; font-size: 14px; + + ${(props) => props.size === 'small' && css` + font-size: 12px; + `} `; const Button = React.forwardRef(function Button(props, ref) { - const { icon: Icon, title, disabled, ...rest } = props; + const { icon: Icon, title, disabled, size = 'default', ...rest } = props; const defaultStyles = useDefaultStyles(); const [isPressed, setPressed] = useState(false); const handlePressIn = useCallback(() => setPressed(true), []); @@ -48,8 +60,12 @@ const Button = React.forwardRef(function Button(props, ref) { onPressOut={handlePressOut} style={[ props.style, - { backgroundColor: isPressed ? defaultStyles.activeBackground.backgroundColor : defaultStyles.button.backgroundColor } + { backgroundColor: isPressed + ? defaultStyles.activeBackground.backgroundColor + : defaultStyles.button.backgroundColor + } ]} + size={size} > {Icon && (function Button(props, ref) { height={14} fill={THEME_COLOR} style={{ - marginRight: 8, + marginRight: title ? 8 : 0, }} /> } - {title} + {title ? ( + {title} + ) : undefined} ); }); diff --git a/src/screens/Downloads/index.tsx b/src/screens/Downloads/index.tsx index 72bce4c..e05fa29 100644 --- a/src/screens/Downloads/index.tsx +++ b/src/screens/Downloads/index.tsx @@ -1,13 +1,12 @@ import useDefaultStyles from 'components/Colors'; import React, { useCallback, useMemo } from 'react'; -import { FlatListProps, Text, TouchableOpacity, View } from 'react-native'; +import { FlatListProps, View } from 'react-native'; import { FlatList } from 'react-native-gesture-handler'; import { SafeAreaView } from 'react-native-safe-area-context'; import { useTypedSelector } from 'store'; import formatBytes from 'utility/formatBytes'; import TrashIcon from 'assets/icons/trash.svg'; import ArrowClockwise from 'assets/icons/arrow-clockwise.svg'; -import { THEME_COLOR } from 'CONSTANTS'; import { useDispatch } from 'react-redux'; import { EntityId } from '@reduxjs/toolkit'; import { queueTrackForDownload, removeDownloadedTrack } from 'store/downloads/actions'; @@ -15,6 +14,10 @@ import Button from 'components/Button'; import { t } from 'i18n-js'; import DownloadIcon from 'components/DownloadIcon'; import styled from 'styled-components/native'; +import { Text } from 'components/Typography'; +import FastImage from 'react-native-fast-image'; +import { useGetImage } from 'utility/JellyfinApi'; +import { ShadowWrapper } from 'components/Shadow'; const DownloadedTrack = styled.View` flex: 1 0 auto; @@ -24,9 +27,16 @@ const DownloadedTrack = styled.View` margin: 0 20px; `; +const AlbumImage = styled(FastImage)` + height: 32px; + width: 32px; + border-radius: 4px; +`; + function Downloads() { const defaultStyles = useDefaultStyles(); const dispatch = useDispatch(); + const getImage = useGetImage(); const { entities, ids } = useTypedSelector((state) => state.downloads); const tracks = useTypedSelector((state) => state.music.tracks.entities); @@ -64,57 +74,68 @@ function Downloads() { */ const ListHeaderComponent = useMemo(() => ( - - - {t('total-download-size')}: {formatBytes(totalDownloadSize)} - -