-
Notifications
You must be signed in to change notification settings - Fork 22
/
MediaNameImage.tsx
112 lines (107 loc) · 3.08 KB
/
MediaNameImage.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
import { ResizeMode } from "expo-av";
import { FC } from "react";
import { ImageStyle, StyleProp, View, ViewStyle } from "react-native";
import { BrandText } from "../BrandText";
import { OmniLink } from "../OmniLink";
import { OptimizedImage } from "../OptimizedImage";
import { SpacerRow } from "../spacer";
import { Username } from "../user/Username";
import defaultThumbnailImage from "@/assets/default-images/default-track-thumbnail.png";
import defaultVideoThumbnail from "@/assets/default-images/default-video-thumbnail.webp";
import { usePost } from "@/hooks/feed/usePost";
import { zodTryParseJSON } from "@/utils/sanitize";
import { neutral77 } from "@/utils/style/colors";
import { fontSemibold12 } from "@/utils/style/fonts";
import {
PostCategory,
ZodSocialFeedTrackMetadata,
ZodSocialFeedVideoMetadata,
zodSocialFeedCommonMetadata,
} from "@/utils/types/feed";
import { Media } from "@/utils/types/mediaPlayer";
const IMAGE_SIZE = 32;
export const MediaNameImage: FC<{
media: Media | undefined;
style?: StyleProp<ViewStyle>;
}> = ({ media, style }) => {
const { post } = usePost(media?.postId);
if (!media || !post) return <View />;
const baseMetadata = zodTryParseJSON(
zodSocialFeedCommonMetadata,
post.metadata,
);
const title =
baseMetadata?.title ||
`${media.isVideo ? "Video" : "Audio"} from Social Feed`;
let imageURI = media.isVideo ? defaultVideoThumbnail : defaultThumbnailImage;
switch (post.category) {
case PostCategory.MusicAudio: {
const metadata = zodTryParseJSON(
ZodSocialFeedTrackMetadata,
post.metadata,
);
if (metadata?.audioFile.thumbnailFileData?.url) {
imageURI = metadata.audioFile.thumbnailFileData.url;
}
break;
}
case PostCategory.Video: {
const metadata = zodTryParseJSON(
ZodSocialFeedVideoMetadata,
post.metadata,
);
if (metadata?.videoFile.thumbnailFileData?.url) {
imageURI = metadata.videoFile.thumbnailFileData.url;
}
break;
}
}
return (
<OmniLink
style={[{ alignSelf: "flex-start" }, style]}
to={{
screen: "FeedPostView",
params: {
id: media.postId,
},
}}
>
<View
style={{
flexDirection: "row",
alignItems: "center",
}}
>
<OptimizedImage
sourceURI={imageURI}
style={imageCStyle}
height={IMAGE_SIZE}
width={IMAGE_SIZE}
resizeMode={ResizeMode.COVER}
/>
<SpacerRow size={1.5} />
<View
style={{
justifyContent: "space-between",
flex: 1,
}}
>
<BrandText style={fontSemibold12} isTicker numberOfLines={1}>
{title}
</BrandText>
<Username
userId={post?.authorId}
textStyle={fontSemibold12}
anonColor={neutral77}
namedColor={neutral77}
/>
</View>
</View>
</OmniLink>
);
};
const imageCStyle: ImageStyle = {
height: IMAGE_SIZE,
width: IMAGE_SIZE,
borderRadius: 8,
};