Skip to content

Commit

Permalink
Merge branch 'andrew_testing' of https://github.com/andrew-bierman/Pa…
Browse files Browse the repository at this point in the history
…ckRat into feat/integrate_servers
  • Loading branch information
pinocchio-life-like committed Aug 5, 2024
2 parents 448d51d + acf2cae commit b655103
Show file tree
Hide file tree
Showing 15 changed files with 336 additions and 132 deletions.
30 changes: 24 additions & 6 deletions packages/app/components/ScoreContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import { Platform } from 'react-native';
import { YStack, XStack, RText, RStack, RButton } from '@packrat/ui';
import useTheme from '../hooks/useTheme';
import { Svg, Circle, Path, G, Text as SvgText } from 'react-native-svg';
import { Svg, Circle, Path, G, Text as SvgText, Line } from 'react-native-svg';
import useCustomStyles from 'app/hooks/useCustomStyles';
import {
useCalculateStore,
Expand Down Expand Up @@ -207,11 +207,11 @@ export const ScoreContainer: React.FC<ScoreContainerProps> = ({
<RText style={styles.scoreText}>
{isAlreadyScored ? title : 'Score this pack!'}
</RText>
<RText>{subheader}</RText>
<RText style={{ fontWeight: 300 }}>{description}</RText>
<RText style={{ fontWeight: 500, color:currentTheme.colors.white }}>{subheader}</RText>
<RText style={{ fontWeight: 300, color:currentTheme.colors.white }}>{description}</RText>
{isOwner && (
<RButton style={styles.button} onPress={handleScoreClick}>
<RText>Calculate Score</RText>
<RText style={styles.buttonText}>Calculate Score</RText>
</RButton>
)}
</YStack>
Expand All @@ -220,7 +220,7 @@ export const ScoreContainer: React.FC<ScoreContainerProps> = ({
style={{
flex: 1,
flexDirection: media.gtXs ? 'column' : 'row',
gap: 8,
gap: 15,
}}
>
<ScoreProgressChart score={totalScore} />
Expand All @@ -238,33 +238,50 @@ const loadStyles = (theme: any) => {
paddingHorizontal: 25,
marginVertical: 15,
padding: 26,
marginTop:25,
// borderColor: currentTheme.colors.border,
// borderWidth: 2,
borderColor: currentTheme.colors.border,
borderWidth: 1,
borderRadius: 10,
boxShadow: '0px 4px 8px rgba(0,0,0,0.1)',
backgroundColor: currentTheme.colors.background,
},
hStack: {
display: 'flex',
flexDirection: 'row',
justifyContent: 'space-between',
alignItems: 'center',
gap: 10,
},
vStack: {
justifyContent: 'center',
alignItems: 'flex-start',
width: '60%',

},
vStackXS: {
justifyContent: 'center',
alignItems: 'center',
width: '100%',
},
scoreText: {
color: currentTheme.colors.textPrimary,
color: currentTheme.colors.white,
fontSize: 26,
fontWeight: 'bold',
paddingBottom: 15,
},
button: {
backgroundColor: currentTheme.colors.primary,
marginTop: 15,
height: 50,
justifyContent: 'center',
boxShadow: '0px 2px 4px rgba(0,0,0,0.2)',
},
buttonText: {
color: currentTheme.colors.white,
fontSize: '1rem',
fontWeight: '500',
},
container: {
flex: 1,
Expand All @@ -274,6 +291,7 @@ const loadStyles = (theme: any) => {
graphWrapper: {
alignItems: 'center',
justifyContent: 'center',
padding: 10,
},
label: {
position: 'absolute',
Expand Down
74 changes: 0 additions & 74 deletions packages/app/components/dashboard/FeedPreview.tsx

This file was deleted.

145 changes: 145 additions & 0 deletions packages/app/components/feedPreview/FeedPreviewCard.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
import { useState } from 'react';
import { RText as OriginalRText, RStack } from '@packrat/ui';
import { RLink } from '@packrat/ui';
import { LayoutChangeEvent, View } from 'react-native';
import useCustomStyles from 'app/hooks/useCustomStyles';
import loadStyles from './feedpreview.style';
import { AntDesign, MaterialIcons } from '@expo/vector-icons';
import useTheme from 'app/hooks/useTheme';
import { useItemWeightUnit } from 'app/hooks/items';
import { convertWeight } from 'app/utils/convertWeight';
import { formatNumber } from 'app/utils/formatNumber';
import { hexToRGBA } from 'app/utils/colorFunctions';

// TODO FeedItem is one of: trip, pack, similar pack & item
export type FeedItem = any;

interface FeedPreviewCardProps {
linkStr: string;
item: FeedItem;
}

const RText: any = OriginalRText;

const FeedPreviewCard: React.FC<FeedPreviewCardProps> = ({ linkStr, item }) => {
const { currentTheme } = useTheme();
const styles = useCustomStyles(loadStyles);
const [weightUnit] = useItemWeightUnit();
const formattedWeight = convertWeight(item.total_weight, 'g', weightUnit);
const [cardWidth, setCardWidth] = useState<number | undefined>();

const handleSetCardWidth = (event: LayoutChangeEvent) => {
const { width } = event.nativeEvent.layout;
setCardWidth(width);
};

return (
<RLink href={linkStr}>
<View style={styles.cardStyles}>
<View
style={{
backgroundColor: currentTheme.colors.cardIconColor,
width: '100%',
paddingLeft: 16,
alignSelf: 'stretch',
}}
>
<View
style={{
backgroundColor: currentTheme.colors.primary,
padding: 4,
alignSelf: 'flex-start',
borderRadius: 8,
position: 'relative',
top: 16,
}}
>
<MaterialIcons
name="backpack"
size={24}
color={currentTheme.colors.cardIconColor}
/>
</View>
</View>
<View style={{ padding: 16 }}>
<RText style={[styles.feedItemTitle, { width: cardWidth }]}>
{item.name}
</RText>
<RStack
style={{
flexDirection: 'row',
alignItems: 'start',
fontWeight: 500,
}}
gap="$4"
onLayout={handleSetCardWidth}
>
<RText
color={hexToRGBA(currentTheme.colors.text, 0.8)}
style={{ fontWeight: 'bold', lineHeight: 'normal' }}
>
{formatNumber(formattedWeight)}
{weightUnit}
</RText>
<View
style={{
flexDirection: 'row',
alignItems: 'center',
gap: 8,
}}
>
<AntDesign
name="heart"
size={16}
color={hexToRGBA(currentTheme.colors.text, 0.8)}
/>
<RText
color={hexToRGBA(currentTheme.colors.text, 0.8)}
style={{ fontWeight: 'bold', lineHeight: 'normal' }}
>
{item.favorites_count}
</RText>
</View>
<View
style={{
flexDirection: 'row',
alignItems: 'center',
gap: 8,
}}
>
<AntDesign
name="clockcircle"
size={16}
color={hexToRGBA(currentTheme.colors.text, 0.8)}
/>
<RText
color={hexToRGBA(currentTheme.colors.text, 0.8)}
style={{ fontWeight: 'bold', lineHeight: 'normal' }}
>
{new Date(item.createdAt).toLocaleString('en-US', {
month: 'short',
day: '2-digit',
...(new Date(item.createdAt).getFullYear() ==
new Date().getFullYear()
? {}
: { year: 'numeric' }),
})}
</RText>
</View>
<RText
color={hexToRGBA(currentTheme.colors.text, 0.8)}
style={{ fontWeight: 'bold', lineHeight: 'normal' }}
>
Ttl Score: {item.total_score}
</RText>
</RStack>
{/* <RText style={{ color: styles.feedItemType.color }}>
{item.description}
</RText> */}
</View>
</View>
</RLink>
);
};

export default FeedPreviewCard;
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@ const loadStyles = (theme: any, appTheme: any) => {
marginBottom: 20,
},
cardStyles: {
height: 100,
width: '100%',
backgroundColor: appTheme.colors.primary,
borderRadius: 5,
padding: 20,
borderRadius: 8,
overflow: 'hidden',
},
feedItem: {
width: 250,
Expand All @@ -25,16 +23,12 @@ const loadStyles = (theme: any, appTheme: any) => {
},
feedItemTitle: {
fontWeight: 'bold',
fontSize: 17,
color: currentTheme.colors.text,
marginBottom: 5,
},
feedItemType: {
fontWeight: 'bold',
fontSize: 16,
fontSize: 18,
color: currentTheme.colors.text,
backgroundColor: currentTheme.colors.background,
marginBottom: 5,
marginBottom: 12,
overflow: 'hidden',
whiteSpace: 'nowrap',
textOverflow: 'ellipsis',
},
};
};
Expand Down
39 changes: 39 additions & 0 deletions packages/app/components/feedPreview/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import React from 'react';
import Carousel from '../carousel';
import { useFeed } from 'app/hooks/feed';
import { default as FeedPreviewCard, type FeedItem } from './FeedPreviewCard';

interface FeedPreviewScrollProps {
itemWidth: number;
feedType: string;
id?: string;
}

const FeedPreviewScroll: React.FC<FeedPreviewScrollProps> = ({
itemWidth,
feedType,
id,
}) => {
const { data: feedData } = useFeed({ feedType, id });

return (
<Carousel itemWidth={itemWidth}>
{feedData
?.filter((item): item is FeedItem => item.type !== null)
.map((item: FeedItem) => {
const linkStr = `/${item.type}/${item.id}`;
return linkStr ? (
<FeedPreviewCard {...{ linkStr, item }} key={linkStr} />
) : null;
})}
</Carousel>
);
};

const FeedPreview: React.FC<{ feedType: string; id?: string }> = ({
feedType,
id,
}) => {
return <FeedPreviewScroll itemWidth={200} feedType={feedType} id={id} />;
};
export default FeedPreview;
Loading

0 comments on commit b655103

Please sign in to comment.