Skip to content

Commit

Permalink
♻️ Add null checks
Browse files Browse the repository at this point in the history
  • Loading branch information
zivavu committed May 11, 2024
1 parent 131135b commit 8f12862
Show file tree
Hide file tree
Showing 7 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/common/chatsManage/getChatLastMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { IChat } from '@/types/chat';

export default function getChatNewestMessage(chat: IChat) {
const sortedMessages = [...chat.messages].sort(
(a, b) => b.createdAt.seconds - a.createdAt.seconds,
(a, b) => b.createdAt?.seconds - a.createdAt?.seconds,
);
return sortedMessages[0];
}
2 changes: 1 addition & 1 deletion src/common/misc/photoManagment/getPicturesSortedByDate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ export default function getPicturesSortedByDate({ picturesMap, type }: IGetPictu
return picturesMap
? Object.values(picturesMap[type])
.filter((picture) => !!picture.createdAt)
.sort((a, b) => b.createdAt.seconds - a.createdAt.seconds)
.sort((a, b) => b.createdAt?.seconds - a.createdAt?.seconds)
: [];
}
2 changes: 1 addition & 1 deletion src/components/molecules/Comments/Comment/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export default function Comment({
</InteractButton>

<Typography variant='body2' color={theme.palette.text.secondary}>
{getShortDate(comment.createdAt.seconds)}
{getShortDate(comment.createdAt?.seconds)}
</Typography>
</Stack>
</StyledRoot>
Expand Down
2 changes: 1 addition & 1 deletion src/components/molecules/Comments/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export default function Comments({

const sortedComments = Object.values(comments || {})
.filter((picture) => !!picture.createdAt)
.sort((a, b) => b.createdAt.seconds - a.createdAt.seconds);
.sort((a, b) => b.createdAt?.seconds - a.createdAt?.seconds);

const commentsToRender = onlyUniqueUsers
? sortedComments.filter((comment, i, self) => {
Expand Down
2 changes: 1 addition & 1 deletion src/components/molecules/ElementOwnerInfoDisplay/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export default function ElementOwnerInfoDisplay({
lineHeight='1rem'
/>
<Typography variant='body2' color={theme.palette.text.secondary}>
{getShortDate(createdAt.seconds, 'week')}
{getShortDate(createdAt?.seconds, 'week')}
</Typography>
</Stack>
{loggedUser?.id === element.ownerId && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export default function ListUserButton({
const lastMessage = getChatNewestMessage(chat);
const handleChatOpen = useHandleOpenChat(friendId);

const { largestDiff } = getDateDiffs(lastMessage.createdAt.seconds);
const { largestDiff } = getDateDiffs(lastMessage.createdAt?.seconds);
return (
<StyledRoot
sx={sx}
Expand Down
2 changes: 1 addition & 1 deletion src/components/organisms/ChatsListPopper/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export default function ChatsListPopper({
loggedUserChats &&
[...loggedUserChats].sort(
(a, b) =>
getChatNewestMessage(b).createdAt.seconds - getChatNewestMessage(a).createdAt.seconds,
getChatNewestMessage(b).createdAt?.seconds - getChatNewestMessage(a).createdAt?.seconds,
);

if (!open) return null;
Expand Down

0 comments on commit 8f12862

Please sign in to comment.