From 7883d45caacad800bd9e3d5f05f1164f7f2b8d8c Mon Sep 17 00:00:00 2001 From: Hirbod Mirjavadi Date: Wed, 27 Sep 2023 20:36:40 +0200 Subject: [PATCH] fix: plenty of issues with channels --- .../components/audio-player/audio-player.tsx | 43 +++++++------ .../creator-channels/channels.web.tsx | 4 +- .../components/creator-badge.tsx | 12 ++-- .../creator-channels/components/lean-text.tsx | 2 +- .../components/lean-text.web.tsx | 10 +--- .../components/message-input-toolbar.tsx | 8 +-- .../components/message-input.tsx | 25 ++++---- .../components/message-item.tsx | 60 +++++++++---------- .../components/messages-header.tsx | 22 +++---- .../app/components/creator-channels/list.tsx | 3 +- packages/app/utilities.ts | 35 +++++++---- 11 files changed, 115 insertions(+), 109 deletions(-) diff --git a/packages/app/components/audio-player/audio-player.tsx b/packages/app/components/audio-player/audio-player.tsx index 543851dd8b..b0ab1db023 100644 --- a/packages/app/components/audio-player/audio-player.tsx +++ b/packages/app/components/audio-player/audio-player.tsx @@ -7,11 +7,10 @@ import { useIsDarkMode } from "@showtime-xyz/universal.hooks"; import { PauseOutline, Play } from "@showtime-xyz/universal.icon"; import { Pressable } from "@showtime-xyz/universal.pressable"; import Spinner from "@showtime-xyz/universal.spinner"; -import { Text } from "@showtime-xyz/universal.text"; -import { View } from "@showtime-xyz/universal.view"; import TrackPlayer, { State } from "design-system/track-player"; +import { LeanText, LeanView } from "../creator-channels/components/lean-text"; import { useTrackProgress } from "./hooks/use-track-progress"; import { setupPlayer } from "./service"; import { @@ -122,10 +121,10 @@ export const AudioPlayer = memo( }, [id, prepare, url]); return ( - - - - + + + + ) : ( - + - + )} - - - - + + + + {formatTime( tempScrubPosition !== null ? tempScrubPosition : localScrubPosition || trackInfo.position || 0 )} - - - + + + - - - + + + {duration || trackInfo.duration ? formatTime(duration || trackInfo.duration || 0) : "-:--"} - - - - + + + + ); } ); diff --git a/packages/app/components/creator-channels/channels.web.tsx b/packages/app/components/creator-channels/channels.web.tsx index 0ab0f47010..ee657c5561 100644 --- a/packages/app/components/creator-channels/channels.web.tsx +++ b/packages/app/components/creator-channels/channels.web.tsx @@ -229,12 +229,14 @@ const CreatorChannelsListItem = memo( CreatorChannelsListItem.displayName = "CreatorChannelsListItem"; +const timeFormatter = new Intl.NumberFormat(); + const CreatorChannelsListCreator = memo( ({ item }: { item: CreatorChannelsListItemProps }) => { const joinChannel = useJoinChannel(); const router = useRouter(); - const memberCount = new Intl.NumberFormat().format(item.member_count); + const memberCount = timeFormatter.format(item.member_count); return ( diff --git a/packages/app/components/creator-channels/components/creator-badge.tsx b/packages/app/components/creator-channels/components/creator-badge.tsx index 53d28f914b..963f6fa43d 100644 --- a/packages/app/components/creator-channels/components/creator-badge.tsx +++ b/packages/app/components/creator-channels/components/creator-badge.tsx @@ -1,18 +1,16 @@ -import { View } from "@showtime-xyz/universal.view"; - -import { LeanText } from "./lean-text"; +import { LeanText, LeanView } from "./lean-text"; export const CreatorBadge = () => { return ( - - + + Creator - - + + ); }; diff --git a/packages/app/components/creator-channels/components/lean-text.tsx b/packages/app/components/creator-channels/components/lean-text.tsx index d795ee46eb..6f314a94d8 100644 --- a/packages/app/components/creator-channels/components/lean-text.tsx +++ b/packages/app/components/creator-channels/components/lean-text.tsx @@ -17,7 +17,7 @@ const ComponentView = forwardRef((props, ref) => { ComponentView.displayName = "RCTView"; -export const LeanView = styled(Component); +export const LeanView = styled(ComponentView); /* export const LeanText = ({ tw, ...rest }) => { diff --git a/packages/app/components/creator-channels/components/lean-text.web.tsx b/packages/app/components/creator-channels/components/lean-text.web.tsx index fe6669190f..3ade18c975 100644 --- a/packages/app/components/creator-channels/components/lean-text.web.tsx +++ b/packages/app/components/creator-channels/components/lean-text.web.tsx @@ -1,11 +1,5 @@ import { Text } from "@showtime-xyz/universal.text"; +import { View } from "@showtime-xyz/universal.view"; export const LeanText = Text; - -/* -export const LeanText = ({ tw, ...rest }) => { - const style = useMemo(() => (Array.isArray(tw) ? tw.join(" ") : tw), [tw]); - - return ; -}; -*/ +export const LeanView = View; diff --git a/packages/app/components/creator-channels/components/message-input-toolbar.tsx b/packages/app/components/creator-channels/components/message-input-toolbar.tsx index 58a588a8dd..3e71b9e7b1 100644 --- a/packages/app/components/creator-channels/components/message-input-toolbar.tsx +++ b/packages/app/components/creator-channels/components/message-input-toolbar.tsx @@ -6,15 +6,13 @@ import * as ImagePicker from "expo-image-picker"; import { Gallery, MusicBadge, Photo } from "@showtime-xyz/universal.icon"; import { Pressable } from "@showtime-xyz/universal.pressable"; -import { Text } from "@showtime-xyz/universal.text"; -import { View } from "@showtime-xyz/universal.view"; import { Logger } from "app/lib/logger"; import { toast } from "design-system/toast"; import { useSendChannelMessage } from "../hooks/use-send-channel-message"; -import { LeanText } from "./lean-text"; +import { LeanText, LeanView } from "./lean-text"; export const MessageInputToolbar = memo( ({ @@ -143,7 +141,7 @@ export const MessageInputToolbar = memo( }, [uploadFile]); return ( - + Camera - + ); } ); diff --git a/packages/app/components/creator-channels/components/message-input.tsx b/packages/app/components/creator-channels/components/message-input.tsx index 3c316af8cd..1ac0c60489 100644 --- a/packages/app/components/creator-channels/components/message-input.tsx +++ b/packages/app/components/creator-channels/components/message-input.tsx @@ -36,7 +36,7 @@ import { useEditChannelMessage } from "../hooks/use-edit-channel-message"; import { useSendChannelMessage } from "../hooks/use-send-channel-message"; import { MissingStarDropModal } from "../missing-star-drop-modal"; import { ChannelById } from "../types"; -import { LeanText } from "./lean-text"; +import { LeanText, LeanView } from "./lean-text"; import { MessageInputToolbar } from "./message-input-toolbar"; export const ScrollToBottomButton = ({ onPress }: { onPress: any }) => { @@ -207,20 +207,20 @@ export const MessageInput = memo( if (!isUserAdmin && edition && !hasUnlockedMessages) { return ( - - + Collecting a Star Drop unlocks privileges with this artist like exclusive channel content, a Star Badge, and more - - + + ); } @@ -229,10 +229,13 @@ export const MessageInput = memo( {permissions?.can_send_messages ? ( <> - + {permissions?.can_upload_media ? ( + + ) : null} + - + - + ) : null } diff --git a/packages/app/components/creator-channels/components/message-item.tsx b/packages/app/components/creator-channels/components/message-item.tsx index c12c59e367..d5bd6d5f84 100644 --- a/packages/app/components/creator-channels/components/message-item.tsx +++ b/packages/app/components/creator-channels/components/message-item.tsx @@ -55,7 +55,7 @@ import { useReactOnMessage } from "../hooks/use-react-on-message"; import { ChannelMessageItem, MessageItemProps } from "../types"; import { generateLoremIpsum } from "../utils"; import { CreatorBadge } from "./creator-badge"; -import { LeanText } from "./lean-text"; +import { LeanText, LeanView } from "./lean-text"; const width = Dimensions.get("window").width; const height = Dimensions.get("window").height; @@ -217,20 +217,20 @@ export const MessageItem = memo( return ( - + - + - + - - + + - + {formatDateRelativeWithIntl(channel_message.created_at)} @@ -253,9 +253,9 @@ export const MessageItem = memo( ) : null} - + - - - + + {messageNotViewable && !isUserAdmin ? ( - + {Platform.OS === "web" ? ( // INFO: I had to do it like that because blur-sm would crash for no reason even with web prefix - + {loremText} - + ) : ( <> @@ -439,7 +439,7 @@ export const MessageItem = memo( /> )} - + ) : ( <> {item.channel_message.body_text_length > 0 ? ( @@ -484,7 +484,7 @@ export const MessageItem = memo( {item.channel_message?.attachments?.length > 0 && item.channel_message?.attachments[0].mime.includes("image") ? ( - - + ) : null} {item.channel_message?.attachments?.length > 0 && @@ -570,8 +570,8 @@ export const MessageItem = memo( ) : null} - - + + ); } @@ -581,23 +581,23 @@ MessageItem.displayName = "MessageItem"; export const MessageSkeleton = () => { return ( - - + + {new Array(8).fill(0).map((_, i) => { return ( - - + + - - + + - + - - + + ); })} - - + + ); }; diff --git a/packages/app/components/creator-channels/components/messages-header.tsx b/packages/app/components/creator-channels/components/messages-header.tsx index 5f0ebfa367..ef36fd19bc 100644 --- a/packages/app/components/creator-channels/components/messages-header.tsx +++ b/packages/app/components/creator-channels/components/messages-header.tsx @@ -12,7 +12,7 @@ import { View } from "@showtime-xyz/universal.view"; import { AvatarHoverCard } from "app/components/card/avatar-hover-card"; import { HeaderProps } from "../types"; -import { LeanText } from "./lean-text"; +import { LeanText, LeanView } from "./lean-text"; export const MessagesHeader = (props: HeaderProps) => { const router = useRouter(); @@ -41,11 +41,11 @@ export const MessagesHeader = (props: HeaderProps) => { }, [props.channelId, router]); return ( - - + { router.back(); @@ -59,18 +59,18 @@ export const MessagesHeader = (props: HeaderProps) => { color={isDark ? "white" : "black"} /> - + - - + + {props.channelId ? ( <> - + router.push(`/@${props.username}`)} tw="text-sm font-bold text-gray-900 dark:text-gray-100" @@ -83,8 +83,8 @@ export const MessagesHeader = (props: HeaderProps) => { > {props.members ?? 0} members - - + + {!props.isCurrentUserOwner ? ( { - + ) : null} - + ); }; diff --git a/packages/app/components/creator-channels/list.tsx b/packages/app/components/creator-channels/list.tsx index 4df13dbce5..1c8137d001 100644 --- a/packages/app/components/creator-channels/list.tsx +++ b/packages/app/components/creator-channels/list.tsx @@ -254,6 +254,7 @@ const CreatorChannelsListItem = memo( CreatorChannelsListItem.displayName = "CreatorChannelsListItem"; +const timeFormatter = new Intl.NumberFormat(); const CreatorChannelsListCreator = memo( ({ item, @@ -265,7 +266,7 @@ const CreatorChannelsListCreator = memo( const joinChannel = useJoinChannel(); const router = useRouter(); const time = formatDateRelativeWithIntl(item.updated_at); - const memberCount = new Intl.NumberFormat().format(item.member_count); + const memberCount = timeFormatter.format(item.member_count); return ( diff --git a/packages/app/utilities.ts b/packages/app/utilities.ts index 4bdc961829..2bad177a36 100644 --- a/packages/app/utilities.ts +++ b/packages/app/utilities.ts @@ -953,6 +953,12 @@ export const generateFakeData = ( })); }; +const timeFormatter = new Intl.DateTimeFormat("en-US", { + hour: "2-digit", + minute: "2-digit", + hour12: true, +}); + export function formatDateRelativeWithIntl( isoDateString: string | number | Date, isDisplayCompleteUnit = false @@ -967,11 +973,6 @@ export function formatDateRelativeWithIntl( if (diffInMinutes < 1) { return "now"; } else if (diffInDays < 1) { - const timeFormatter = new Intl.DateTimeFormat("en-US", { - hour: "2-digit", - minute: "2-digit", - hour12: true, - }); return timeFormatter.format(date); } else if (diffInDays >= 1 && diffInDays < 7) { return `${diffInDays}${isDisplayCompleteUnit ? " days ago" : "d"}`; @@ -1094,9 +1095,10 @@ export const getCurrencySymbol = (currency: string | null | undefined) => { return "$"; }; +const formattersCache: Record> = {}; + export const getCurrencyPrice = ( currency: string | null | undefined, - // TODO: Fix price type, ensure safetey of this function (CC @alan, @jorge, @maxime) price: number | null | undefined | string ): string => { // Handle null, undefined, or non-numeric strings @@ -1105,13 +1107,22 @@ export const getCurrencyPrice = ( } const numberValue = typeof price === "string" ? parseFloat(price) : price; + const currentCurrency = currency ?? "USD"; + + if (!formattersCache[locale]) { + formattersCache[locale] = {}; + } + + if (!formattersCache[locale][currentCurrency]) { + formattersCache[locale][currentCurrency] = new Intl.NumberFormat(locale, { + style: "currency", + minimumFractionDigits: 0, + maximumFractionDigits: 2, + currency: currentCurrency, + }); + } - return new Intl.NumberFormat(locale ?? "en-US", { - style: "currency", - minimumFractionDigits: 0, - maximumFractionDigits: 2, - currency: currency ?? "USD", - }).format(numberValue); + return formattersCache[locale][currentCurrency].format(numberValue); }; export const getCreatorEarnedMoney = (