Skip to content

Commit

Permalink
Merge pull request #438 from xmtp-labs/dj/mobile
Browse files Browse the repository at this point in the history
Remove mobile logic, redirect mobile users
  • Loading branch information
daria-github authored Feb 22, 2024
2 parents 96a6888 + 3896095 commit a510755
Show file tree
Hide file tree
Showing 11 changed files with 65 additions and 119 deletions.
14 changes: 4 additions & 10 deletions src/component-library/components/AddressInput/AddressInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ export const AddressInput = ({
!resolvedAddress?.displayAddress
? "bg-indigo-50 border-b border-indigo-500"
: "border-b border-gray-200",
"flex items-center px-2 md:px-4 py-3 border-l-0 z-10 max-md:h-fit md:max-h-sm w-full h-16",
"flex items-center px-2 md:px-4 py-3 border-l-0 z-10 max-h-sm w-full h-16",
)}>
<div className="max-md:w-fit md:hidden flex w-24 p-0 justify-start">
<div className="hidden flex w-24 p-0 justify-start">
<ChevronLeftIcon onClick={onLeftIconClick} width={24} />
</div>
<form
Expand All @@ -91,7 +91,7 @@ export const AddressInput = ({
<input
data-testid="message-to-input"
tabIndex={0}
className="bg-transparent text-gray-900 px-0 h-4 m-1 ml-0 font-mono max-md:text-[16px] md:text-sm w-full leading-tight border border-2 border-transparent focus:border-transparent focus:ring-0 cursor-text"
className="bg-transparent text-gray-900 px-0 h-4 m-1 ml-0 font-mono text-sm w-full leading-tight border border-2 border-transparent focus:border-transparent focus:ring-0 cursor-text"
id="address"
type="search"
spellCheck="false"
Expand All @@ -108,13 +108,7 @@ export const AddressInput = ({
/>
)}
<div
className={classNames(
"font-mono",
"text-sm",
"max-md:text-xs",
"h-5",
subtextColor,
)}
className={classNames("font-mono", "text-sm", "h-5", subtextColor)}
data-testid="message-to-subtext">
{subtext
? t(subtext)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,11 @@ interface HeaderDropdownProps {
* What is the recipient input?
*/
recipientInput: string;
/**
* Boolean to determine if screen width is mobile size
*/
isMobileView?: boolean;
}

export const HeaderDropdown = ({
onClick,
recipientInput,
isMobileView,
}: HeaderDropdownProps) => {
const { t } = useTranslation();

Expand Down Expand Up @@ -61,7 +56,7 @@ export const HeaderDropdown = ({
{t(`consent.${name}`)}
</button>
))}
{(recipientInput || isMobileView) && (
{recipientInput && (
<IconButton
onClick={() => onClick?.()}
label={<PlusIcon color="white" width="20" />}
Expand Down
3 changes: 0 additions & 3 deletions src/component-library/components/LearnMore/LearnMore.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,11 @@ interface LearnMoreProps {
description: string;
tags: React.ReactNode;
}>;
version: string;
setStartedFirstMessage: () => void;
}

export const LearnMore = ({
highlightedCompanies = [],
// eslint-disable-next-line @typescript-eslint/no-unused-vars
version,
setStartedFirstMessage,
}: LearnMoreProps) => {
const { t } = useTranslation();
Expand Down
12 changes: 3 additions & 9 deletions src/component-library/components/MessageInput/MessageInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,14 @@ import { ContentTypeScreenEffect } from "@xmtp/experimental-content-type-screen-
import { IconButton } from "../IconButton/IconButton";
import { useAttachmentChange } from "../../../hooks/useAttachmentChange";
import { typeLookup, type contentTypes } from "../../../helpers/attachments";
import { TAILWIND_MD_BREAKPOINT, classNames } from "../../../helpers";
import { classNames } from "../../../helpers";
import type { RecipientAddress } from "../../../store/xmtp";
import { useXmtpStore } from "../../../store/xmtp";
import { useVoiceRecording } from "../../../hooks/useVoiceRecording";
import { useRecordingTimer } from "../../../hooks/useRecordingTimer";
import "react-tooltip/dist/react-tooltip.css";
import { useLongPress } from "../../../hooks/useLongPress";
import { EffectDialog } from "../EffectDialog/EffectDialog";
import useWindowSize from "../../../hooks/useWindowSize";

type InputProps = {
/**
Expand Down Expand Up @@ -96,8 +95,6 @@ export const MessageInput = ({
setAttachmentPreview,
setIsDragActive,
}: InputProps) => {
const [width] = useWindowSize();

const { getCachedByPeerAddress } = useConversation();
// For effects
const { sendMessage: _sendMessage } = _useSendMessage();
Expand Down Expand Up @@ -126,7 +123,7 @@ export const MessageInput = ({
textAreaRef?.current?.scrollHeight <= 32
? "max-h-8"
: "max-h-40"
} min-h-8 outline-none border-none focus:ring-0 resize-none mx-2 p-1 w-full max-md:text-[16px] md:text-md text-gray-900`;
} min-h-8 outline-none border-none focus:ring-0 resize-none mx-2 p-1 w-full text-md text-gray-900`;

useLayoutEffect(() => {
const MIN_TEXTAREA_HEIGHT = 32;
Expand Down Expand Up @@ -246,10 +243,7 @@ export const MessageInput = ({
]);

const handleLongPress = () => {
// Don't run effect on mobile
if (width > TAILWIND_MD_BREAKPOINT) {
setOpenEffectDialog(true);
}
setOpenEffectDialog(true);
};

const handleSendEffect = (effectType: string) => {
Expand Down
28 changes: 28 additions & 0 deletions src/component-library/components/Mobile/Mobile.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { DeviceMobileIcon } from "@heroicons/react/solid";
import { useTranslation } from "react-i18next";

export const Mobile = () => {
const { t } = useTranslation();
return (
<div className="flex flex-col items-center justify-center h-screen p-4 text-center">
<DeviceMobileIcon width="100" className="text-indigo-600" />
<h1 className="text-2xl font-bold">{t("mobile.mobile_detected")}</h1>
<p className="mt-8">{t("mobile.group_chat_cta")}</p>
<a
href="https://testflight.apple.com/join/xEJOvzEx"
target="_blank"
className="flex justify-center text-blue-600 text-center cursor-pointer"
rel="noreferrer">
https://testflight.apple.com/join/xEJOvzEx
</a>
<p className="mt-8">{t("mobile.reference_app_cta")}</p>
<a
href="https://github.com/xmtp-labs/xmtp-inbox-mobile"
target="_blank"
className="flex justify-center text-blue-600 cursor-pointer"
rel="noreferrer">
https://github.com/xmtp-labs/xmtp-inbox-mobile
</a>
</div>
);
};
13 changes: 2 additions & 11 deletions src/controllers/AddressInputController.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { useEffect } from "react";
import { useConversation, useConsent } from "@xmtp/react-sdk";
import { AddressInput } from "../component-library/components/AddressInput/AddressInput";
import { getRecipientInputSubtext, shortAddress } from "../helpers";
import useWindowSize from "../hooks/useWindowSize";
import { getRecipientInputSubtext } from "../helpers";
import { useXmtpStore } from "../store/xmtp";
import { useAddressInput } from "../hooks/useAddressInput";

Expand All @@ -29,8 +28,6 @@ export const AddressInputController = () => {
// manage address input state
useAddressInput();

const size = useWindowSize();

useEffect(() => {
const selectConversation = async () => {
// if there's a valid network address, look for an existing conversation
Expand Down Expand Up @@ -80,13 +77,7 @@ export const AddressInputController = () => {
: ""
}
resolvedAddress={{
displayAddress:
recipientName ??
(size[0] < 700
? recipientAddress
? shortAddress(recipientAddress)
: ""
: recipientAddress ?? ""),
displayAddress: recipientName ?? recipientAddress ?? "",
walletAddress: recipientName
? recipientAddress ?? undefined
: undefined,
Expand Down
62 changes: 9 additions & 53 deletions src/controllers/ConversationListController.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useEffect, useMemo } from "react";
import { useClient, useConsent, useDb } from "@xmtp/react-sdk";
import { useConsent, useDb } from "@xmtp/react-sdk";
import type { CachedConversation } from "@xmtp/react-sdk";
import type { ActiveTab } from "../store/xmtp";
import { useXmtpStore } from "../store/xmtp";
Expand Down Expand Up @@ -27,11 +27,8 @@ export const ConversationListController = ({
const { isAllowed, isDenied } = useConsent();

const { db } = useDb();
// const [messages, setMessages] = useState<CachedMessage[]>([]);
// const messagesDb = db.table("messages");

useStreamAllMessages();
const { client: walletAddress } = useClient();
const recipientInput = useXmtpStore((s) => s.recipientInput);
const changedConsentCount = useXmtpStore((s) => s.changedConsentCount);

Expand All @@ -45,50 +42,19 @@ export const ConversationListController = ({
}
};
void runUpdate();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [isLoaded, activeTab, changedConsentCount]);

// To-do: remove if not needed after consent goes out
// useEffect(() => {
// // This may make more sense to come from the React SDK, but we're pulling from here for now
// const fetchMessages = async () =>
// messagesDb
// .where("senderAddress")
// .equals(walletAddress?.address as string)
// .toArray()
// .then((dbMessages: CachedMessage[]) => {
// setMessages(dbMessages);
// })
// .catch((error: Error) => {
// console.error("Error querying messages:", error);
// });

// void fetchMessages();
// }, [conversations.length, messagesDb, walletAddress?.address]);
}, [isLoaded, activeTab, changedConsentCount, conversations, db]);

const messagesToPass = useMemo(() => {
const conversationsWithTab = conversations.map(
(conversation: CachedConversation) => {
const tab = isAllowed(conversation.peerAddress)
? "messages"
: isDenied(conversation.peerAddress)
? "blocked"
: "requests";
return (
<MessagePreviewCardController
key={conversation.topic}
convo={conversation}
tab={tab}
/>
);
},
(conversation: CachedConversation) => (
<MessagePreviewCardController
key={conversation.topic}
convo={conversation}
/>
),
);
const sortedConvos = conversationsWithTab.filter(
(item: NodeWithConsent) => {
// To-do: remove commented out code in this block if not needed after consent goes out
// const hasSentMessages = messages.find(
// (message) => message?.conversationTopic === item.props.convo.topic,
// );
const isAddressBlocked = isDenied(item.props.convo.peerAddress);
const isAddressAllowed = isAllowed(item.props.convo.peerAddress);

Expand All @@ -105,17 +71,7 @@ export const ConversationListController = ({
},
);
return sortedConvos;
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [
conversations,
// messages,
isLoading,
walletAddress,
db,
changedConsentCount,
isAllowed,
isDenied,
]);
}, [activeTab, conversations, isAllowed, isDenied]);

return (
<ConversationList
Expand Down
4 changes: 0 additions & 4 deletions src/controllers/HeaderDropdownController.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import { HeaderDropdown } from "../component-library/components/HeaderDropdown/HeaderDropdown";
import { TAILWIND_MD_BREAKPOINT } from "../helpers";
import useWindowSize from "../hooks/useWindowSize";
import { useXmtpStore } from "../store/xmtp";

export const HeaderDropdownController = () => {
const resetRecipient = useXmtpStore((s) => s.resetRecipient);
const setConversationTopic = useXmtpStore((s) => s.setConversationTopic);
const recipientInput = useXmtpStore((s) => s.recipientInput);
const setStartedFirstMessage = useXmtpStore((s) => s.setStartedFirstMessage);
const [width] = useWindowSize();

return (
<HeaderDropdown
Expand All @@ -18,7 +15,6 @@ export const HeaderDropdownController = () => {
setConversationTopic();
setStartedFirstMessage(true);
}}
isMobileView={width <= TAILWIND_MD_BREAKPOINT}
/>
);
};
4 changes: 0 additions & 4 deletions src/controllers/MessagePreviewCardController.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import { ContentTypeScreenEffect } from "@xmtp/experimental-content-type-screen-
import { MessagePreviewCard } from "../component-library/components/MessagePreviewCard/MessagePreviewCard";
import type { ETHAddress } from "../helpers";
import { shortAddress } from "../helpers";
import type { ActiveTab } from "../store/xmtp";
import { useXmtpStore } from "../store/xmtp";
import {
getCachedPeerAddressAvatar,
Expand All @@ -28,13 +27,10 @@ import {

interface MessagePreviewCardControllerProps {
convo: CachedConversation;
tab: ActiveTab;
}

export const MessagePreviewCardController = ({
convo,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
tab,
}: MessagePreviewCardControllerProps) => {
const { t } = useTranslation();
const { allow } = useConsent();
Expand Down
5 changes: 5 additions & 0 deletions src/locales/en_US.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@
"collapse_header": "Collapse",
"messages_header": "Messages"
},
"mobile": {
"mobile_detected": "It looks like you may be on a mobile device!",
"group_chat_cta": "Download the Converse TestFlight to try group chat:",
"reference_app_cta": "In addition, please note that our React Native XMTP Reference Application is now live:"
},
"status_messaging": {
"error_1_header": "Sorry, the app encountered an error",
"error_1_subheader": "Not to worry. Let’s try again. If the error persists, <0>we're here to help!</0>",
Expand Down
Loading

0 comments on commit a510755

Please sign in to comment.