Skip to content

Commit

Permalink
fix: message list shouldn't get stuck loading (#1009)
Browse files Browse the repository at this point in the history
  • Loading branch information
Elise Alix committed Oct 30, 2022
1 parent 6bee0c6 commit 210d819
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 13 deletions.
1 change: 1 addition & 0 deletions data/feature-flags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export const featureFlags = [
'0x016b24', // bhavyam.lens
'0x016b0b', // xmtplabs.lens
'0xf5ff', // anoopr.lens
'0x016b2e', // kenziestokes.lens
'0x0122d4' // darick.lens
]
},
Expand Down
6 changes: 4 additions & 2 deletions src/components/Messages/Composer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ import toast from 'react-hot-toast';
interface Props {
sendMessage: (message: string) => Promise<boolean>;
conversationKey: string;
disabledInput: boolean;
}

const Composer: FC<Props> = ({ sendMessage, conversationKey }) => {
const Composer: FC<Props> = ({ sendMessage, conversationKey, disabledInput }) => {
const [message, setMessage] = useState<string>('');
const [sending, setSending] = useState<boolean>(false);

const canSendMessage = !sending && message.length > 0;
const canSendMessage = !disabledInput && !sending && message.length > 0;

const handleSend = async () => {
if (!canSendMessage) {
Expand Down Expand Up @@ -47,6 +48,7 @@ const Composer: FC<Props> = ({ sendMessage, conversationKey }) => {
type="text"
placeholder="Type Something"
value={message}
disabled={disabledInput}
onKeyDown={handleKeyDown}
onChange={(event) => setMessage(event.target.value)}
/>
Expand Down
6 changes: 5 additions & 1 deletion src/components/Messages/Message.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,11 @@ const Message: FC<MessageProps> = ({ conversationKey }) => {
hasMore={hasMore}
missingXmtpAuth={missingXmtpAuth ?? false}
/>
<Composer sendMessage={sendMessage} conversationKey={conversationKey} />
<Composer
sendMessage={sendMessage}
conversationKey={conversationKey}
disabledInput={missingXmtpAuth ?? false}
/>
</>
)}
</Card>
Expand Down
2 changes: 1 addition & 1 deletion src/components/Messages/MessagesList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ const DateDivider: FC<{ date?: Date }> = ({ date }) => (
);

const MissingXmtpAuth: FC = () => (
<Card as="aside" className="mb-4 border-gray-400 !bg-gray-300 !bg-opacity-20 space-y-2.5 p-5">
<Card as="aside" className="mb-2 mr-4 border-gray-400 !bg-gray-300 !bg-opacity-20 space-y-2.5 p-5">
<div className="flex items-center space-x-2 font-bold">
<EmojiSadIcon className="w-5 h-5" />
<p>This fren hasn't enabled DMs yet</p>
Expand Down
15 changes: 6 additions & 9 deletions src/components/utils/hooks/useGetConversation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,20 @@ import { useMessageStore } from 'src/store/message';

const useGetConversation = (conversationKey: string, profile?: Profile) => {
const client = useMessageStore((state) => state.client);
const conversations = useMessageStore((state) => state.conversations);
const setConversations = useMessageStore((state) => state.setConversations);
const selectedConversation = useMessageStore((state) => state.conversations.get(conversationKey));
const addConversation = useMessageStore((state) => state.addConversation);
const currentProfile = useAppStore((state) => state.currentProfile);
const [missingXmtpAuth, setMissingXmtpAuth] = useState<boolean>();

const reset = () => {
setConversations(new Map());
setMissingXmtpAuth(false);
};

useEffect(() => {
if (!profile || !client) {
return;
}
const conversation = conversations.get(conversationKey);
if (conversation) {
if (selectedConversation) {
setMissingXmtpAuth(false);
return;
}
Expand All @@ -39,12 +37,11 @@ const useGetConversation = (conversationKey: string, profile?: Profile) => {
conversationId: conversationId,
metadata: {}
});
conversations.set(conversationKey, conversation);
setConversations(new Map(conversations));
addConversation(conversationKey, conversation);
};
createNewConversation();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [profile]);
}, [profile, selectedConversation]);

useEffect(() => {
if (!currentProfile) {
Expand All @@ -54,7 +51,7 @@ const useGetConversation = (conversationKey: string, profile?: Profile) => {
}, [currentProfile]);

return {
selectedConversation: conversations.get(conversationKey),
selectedConversation,
missingXmtpAuth
};
};
Expand Down
8 changes: 8 additions & 0 deletions src/store/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ interface MessageState {
setClient: (client: Client | undefined) => void;
conversations: Map<string, Conversation>;
setConversations: (conversations: Map<string, Conversation>) => void;
addConversation: (key: string, newConversation: Conversation) => void;
messages: Map<string, DecodedMessage[]>;
setMessages: (messages: Map<string, DecodedMessage[]>) => void;
addMessages: (key: string, newMessages: DecodedMessage[]) => number;
Expand All @@ -26,6 +27,13 @@ export const useMessageStore = create<MessageState>((set) => ({
setClient: (client) => set(() => ({ client })),
conversations: new Map(),
setConversations: (conversations) => set(() => ({ conversations })),
addConversation: (key: string, newConverstaion: Conversation) => {
set((state) => {
const conversations = new Map(state.conversations);
conversations.set(key, newConverstaion);
return { conversations };
});
},
messages: new Map(),
setMessages: (messages) => set(() => ({ messages })),
addMessages: (key: string, newMessages: DecodedMessage[]) => {
Expand Down

1 comment on commit 210d819

@vercel
Copy link

@vercel vercel bot commented on 210d819 Oct 30, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.