Skip to content

Commit

Permalink
Correct pinned msg type & do null check eariler
Browse files Browse the repository at this point in the history
  • Loading branch information
gdbroman committed Jun 20, 2023
1 parent a25d3c0 commit 153124f
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
8 changes: 4 additions & 4 deletions app/src/renderer/apps/Courier/components/PinnedMessage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export const PinnedContainer = ({ message, onClick }: PinnedContainerProps) => {
const { getOptions, setOptions } = useContextMenu();
const [authorColor, setAuthorColor] = useState<string | undefined>();

const pinnedRowId = useMemo(() => `pinned-${message?.id}`, [message?.id]);
const pinnedRowId = useMemo(() => `pinned-${message.id}`, [message.id]);
const contextMenuOptions = useMemo(() => {
const menu: MenuItemProps[] = [];
if (!selectedChat || !loggedInAccount) return menu;
Expand All @@ -69,7 +69,7 @@ export const PinnedContainer = ({ message, onClick }: PinnedContainerProps) => {
disabled: false,
onClick: (evt: React.MouseEvent<HTMLDivElement>) => {
evt.stopPropagation();
selectedChat.clearPinnedMessage(message?.id);
selectedChat.clearPinnedMessage(message.id);
},
});
}
Expand All @@ -83,15 +83,15 @@ export const PinnedContainer = ({ message, onClick }: PinnedContainerProps) => {
}, [contextMenuOptions, getOptions, setOptions, pinnedRowId]);

useEffect(() => {
const contact = friends.getContactAvatarMetadata(message?.sender);
const contact = friends.getContactAvatarMetadata(message.sender);
// NOTE: #000 is the default color, so we want to default to undefined
// and use the accent color instead
const authorColorDisplay =
(contact.color && flipColorIfLowContrast(contact.color, theme.mode)) ||
'rgba(var(--rlm-text-rgba))';

setAuthorColor(authorColorDisplay);
}, [message?.sender]);
}, [message.sender]);

if (!message) return null;
return (
Expand Down
3 changes: 1 addition & 2 deletions app/src/renderer/apps/Courier/views/ChatLog/ChatLog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import { useTrayApps } from 'renderer/apps/store';
import { trackEvent } from 'renderer/lib/track';
import { useStorage } from 'renderer/lib/useStorage';
import { useAppState } from 'renderer/stores/app.store';
import { ChatMessageType } from 'renderer/stores/models/chat.model';
import { useShipStore } from 'renderer/stores/ship.store';

import { ChatLogBody } from './ChatLogBody';
Expand Down Expand Up @@ -173,7 +172,7 @@ export const ChatLogPresenter = ({ isStandaloneChat = false }: Props) => {
storage={storage}
isMuted={selectedChat.muted}
showPin={showPin}
pinnedChatMessage={selectedChat.pinnedChatMessage as ChatMessageType}
pinnedChatMessage={selectedChat.pinnedChatMessage}
ourColor={ourColor}
themeMode={theme.mode as 'light' | 'dark'}
listRef={listRef}
Expand Down
4 changes: 2 additions & 2 deletions app/src/renderer/apps/Courier/views/ChatLog/ChatLogBody.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { ChatLogList } from './ChatLogList';
type Props = {
path: string;
showPin: boolean;
pinnedChatMessage: ChatMessageType;
pinnedChatMessage: ChatMessageType | null | undefined;
storage: any;
isMuted: boolean;
ourColor: string;
Expand Down Expand Up @@ -106,7 +106,7 @@ const ChatLogBodyPresenter = ({

return (
<ChatLogListContainer isStandaloneChat={isStandaloneChat}>
{showPin && (
{showPin && pinnedChatMessage && (
<FullWidthAnimatePresence>
<PinnedContainer
message={pinnedChatMessage}
Expand Down

0 comments on commit 153124f

Please sign in to comment.