Skip to content
This repository has been archived by the owner on Dec 21, 2023. It is now read-only.

fix: channel image and audio preview when locked #2443

Merged
merged 3 commits into from
Sep 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions packages/app/components/audio-player/audio-player.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@ export const AudioPlayer = memo(
id,
url,
duration,
isViewable = true,
}: {
id: number;
url: string;
duration?: number | null;
isViewable?: boolean;
}) => {
const isDark = useIsDarkMode();
const timeoutRef = useRef<NodeJS.Timeout | null>(null);
Expand Down Expand Up @@ -236,6 +238,13 @@ export const AudioPlayer = memo(
</LeanText>
</LeanView>
</LeanView>
{!isViewable ? (
<LeanView tw="absolute bottom-0 left-0 right-0 top-0 items-center justify-center bg-gray-800 bg-opacity-90">
<LeanText tw="select-none text-center text-lg text-white dark:text-gray-300">
Unlock to listen
</LeanText>
</LeanView>
) : null}
</LeanView>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Image } from "@showtime-xyz/universal.image";
import { LightBox } from "@showtime-xyz/universal.light-box";

import { ChannelMessageAttachment } from "../types";
import { LeanView } from "./lean-text";
import { LeanText, LeanView } from "./lean-text";

const width = Dimensions.get("window").width;
const height = Dimensions.get("window").height;
Expand Down Expand Up @@ -37,7 +37,13 @@ const getImageAttachmentHeight = (attachment: ChannelMessageAttachment) => {
};

export const ImagePreview = memo(
({ attachment }: { attachment: ChannelMessageAttachment }) => {
({
attachment,
isViewable,
}: {
attachment: ChannelMessageAttachment;
isViewable?: boolean;
}) => {
const imageAttachmentWidth = useMemo(
() => getImageAttachmentWidth(attachment),
[attachment]
Expand Down Expand Up @@ -68,11 +74,12 @@ export const ImagePreview = memo(

return (
<LeanView
tw="web:cursor-pointer overflow-hidden rounded-xl bg-gray-600"
tw="overflow-hidden rounded-xl bg-gray-600"
style={{
width: imageAttachmentWidth,
height: imageAttachmentHeight,
}}
pointerEvents={isViewable ? "auto" : "none"}
>
<LightBox
width={imageAttachmentWidth}
Expand All @@ -99,6 +106,7 @@ export const ImagePreview = memo(
}
>
<Image
tw="web:cursor-pointer"
transition={100}
recyclingKey={attachment?.media_upload}
source={
Expand All @@ -113,6 +121,13 @@ export const ImagePreview = memo(
}}
/>
</LightBox>
{!isViewable ? (
<LeanView tw="absolute bottom-0 left-0 right-0 top-0 items-center justify-center bg-gray-800 bg-opacity-90">
<LeanText tw="text-center text-lg text-white dark:text-gray-300">
Unlock to view
</LeanText>
</LeanView>
) : null}
</LeanView>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,9 @@ export const MessageInput = memo(

<MessageBox
ref={inputRef}
placeholder="Send an update..."
placeholder={
isUserAdmin ? "Send an update..." : "Write a message..."
}
textInputProps={{
maxLength: 2000,
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
import { ImagePreview } from "./image-preview";
import { LeanText, LeanView } from "./lean-text";

const PlatformAnimateHeight = Platform.OS === "web" ? AnimateHeight : View;

Check warning on line 58 in packages/app/components/creator-channels/components/message-item.tsx

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

packages/app/components/creator-channels/components/message-item.tsx#L58

[unused-imports/no-unused-vars] 'PlatformAnimateHeight' is assigned a value but never used. Allowed unused vars must match /^_/u.
const AnimatedView = Animated.createAnimatedComponent(View);

export const MessageItem = memo(
Expand Down Expand Up @@ -373,7 +373,7 @@
</LeanView>
) : (
<>
<LeanText tw="text-sm text-gray-900 dark:text-gray-100">
<LeanText tw="py-1.5 text-sm text-gray-900 dark:text-gray-100">
{loremText}
</LeanText>
<BlurView
Expand All @@ -392,7 +392,6 @@
<>
{item.channel_message.body_text_length > 0 ? (
<LeanText
selectable
tw={"text-sm text-gray-900 dark:text-gray-100"}
style={
Platform.OS === "web"
Expand All @@ -405,10 +404,7 @@
>
{linkifiedMessage}
{messageWasEdited && (
<LeanText
tw="text-xs text-gray-500 dark:text-gray-200"
selectable
>
<LeanText tw="text-xs text-gray-500 dark:text-gray-200">
{` • edited`}
</LeanText>
)}
Expand All @@ -432,7 +428,10 @@

{item.channel_message?.attachments?.length > 0 &&
item.channel_message?.attachments[0].mime.includes("image") ? (
<ImagePreview attachment={item.channel_message?.attachments[0]} />
<ImagePreview
attachment={item.channel_message?.attachments[0]}
isViewable={permissions?.can_view_creator_messages}
/>
) : null}

{item.channel_message?.attachments?.length > 0 &&
Expand All @@ -441,6 +440,7 @@
id={item.channel_message.id}
url={item.channel_message.attachments[0]?.url}
duration={item.channel_message.attachments[0]?.duration}
isViewable={permissions?.can_view_creator_messages}
/>
) : null}
{item.reaction_group.length > 0 ? (
Expand Down
28 changes: 26 additions & 2 deletions packages/app/hooks/use-network-connection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,47 @@ import { useIsOnline } from "./use-is-online";

export const useNetWorkConnection = () => {
const connectionWasLost = useRef(false);
const ignoreNextNetworkChange = useRef(false);
const wasBackgrounded = useRef(false);

// Check if app is in foreground
const isForeground = useIsForeground();
// Check if device is online
const { isOnline } = useIsOnline();

useEffect(() => {
if (!isForeground) {
wasBackgrounded.current = true;
ignoreNextNetworkChange.current = true;
setTimeout(() => {
ignoreNextNetworkChange.current = false;
}, 1000); // Ignore for 1 second after coming to foreground
} else {
wasBackgrounded.current = false;
}
}, [isForeground]);

useEffect(() => {
const getNetwork = async () => {
// If we're set to ignore this network change, just return
if (ignoreNextNetworkChange.current) {
return;
}

// Show error message if app is in foreground and device is offline
if (isForeground && !isOnline && !connectionWasLost.current) {
toast.error("No network connection");
connectionWasLost.current = true;
return;
}

// Show success message if app is in foreground and device is back online
if (isForeground && isOnline && connectionWasLost.current) {
// But only if the app wasn't backgrounded
if (
isForeground &&
isOnline &&
connectionWasLost.current &&
!wasBackgrounded.current
) {
toast.success("Network connected");
connectionWasLost.current = false;
}
Expand Down
Loading