Skip to content

Commit

Permalink
fix: fix a problem which deleted conversation can not get name occur …
Browse files Browse the repository at this point in the history
…crash
  • Loading branch information
moonrailgun committed Apr 29, 2024
1 parent f084d4b commit 88b05da
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
8 changes: 6 additions & 2 deletions client/shared/redux/hooks/useDMConverseName.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,20 @@ import type { ChatConverseState } from '../slices/chat';
import { useUserId } from './useUserInfo';
import type { FriendInfo } from '../slices/user';

export function useDMConverseName(converse: ChatConverseState) {
export function useDMConverseName(converse: ChatConverseState | undefined) {
const userId = useUserId();
const friends: FriendInfo[] = useAppSelector((state) => state.user.friends);
const { value: name = '' } = useAsync(async () => {
if (!converse) {
return '';
}

if (!isValidStr(userId)) {
return '';
}

return getDMConverseName(userId, converse);
}, [userId, converse.name, converse.members.join(','), friends]);
}, [userId, converse?.name, converse?.members.join(','), friends]);

return name;
}
10 changes: 8 additions & 2 deletions client/web/src/components/ConverseName.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import React from 'react';
import { useAppSelector, useDMConverseName } from 'tailchat-shared';
import {
ChatConverseState,
useAppSelector,
useDMConverseName,
} from 'tailchat-shared';

interface ConverseNameProps {
converseId: string;
Expand All @@ -9,7 +13,9 @@ interface ConverseNameProps {

export const ConverseName: React.FC<ConverseNameProps> = React.memo((props) => {
const { converseId, className, style } = props;
const converse = useAppSelector((state) => state.chat.converses[converseId]);
const converse = useAppSelector<ChatConverseState | undefined>(
(state) => state.chat.converses[converseId]
);
const converseName = useDMConverseName(converse);

return (
Expand Down

0 comments on commit 88b05da

Please sign in to comment.