Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-sort inbox list on message sent/received #1846

Merged
merged 6 commits into from
Jun 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/src/renderer/apps/Courier/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const CourierAppPresenter = () => {
clearInnerNavigation();
}, [chatStore.subroute]);

if (chatStore.loader.isFirstLoad) {
if (chatStore.inboxInitLoader.isFirstLoad) {
return (
<Flex
position="absolute"
Expand Down
12 changes: 6 additions & 6 deletions app/src/renderer/apps/Courier/components/ChatLogHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useMemo } from 'react';
import { observer } from 'mobx-react';
import styled from 'styled-components';

import { Button, Flex, Icon } from '@holium/design-system/general';
import { Button, Flex, Icon, Spinner } from '@holium/design-system/general';
import { Menu, MenuItemProps } from '@holium/design-system/navigation';

import { useAppState } from 'renderer/stores/app.store';
Expand Down Expand Up @@ -30,15 +30,13 @@ type Props = {
path: string;
isMuted: boolean;
hasMenu: boolean;
rightAction?: React.ReactNode;
forceBackButton?: boolean;
isStandaloneChat?: boolean;
onBack: () => void;
};

const ChatLogHeaderPresenter = ({
path,
rightAction,
isMuted,
hasMenu = true,
forceBackButton = false,
Expand All @@ -47,7 +45,7 @@ const ChatLogHeaderPresenter = ({
}: Props) => {
const { loggedInAccount, shellStore } = useAppState();
const { chatStore } = useShipStore();
const { selectedChat, setSubroute, toggleMuted } = chatStore;
const { selectedChat, chatLoader, setSubroute, toggleMuted } = chatStore;
const isSpaceChat = selectedChat?.type === 'space';

const chatLogId = useMemo(() => `chat-log-${path}`, [path]);
Expand Down Expand Up @@ -144,8 +142,10 @@ const ChatLogHeaderPresenter = ({
)}
<ChatLogHeaderContent isStandaloneChat={isStandaloneChat} />
</Flex>
<Flex>
{rightAction}
<Flex gap={8}>
{chatLoader.isLoading && (
<Spinner size="16px" width={1.5} color="var(--rlm-text-color)" />
)}
{hasMenu && (
<Menu
id={`chat-${path}-menu`}
Expand Down
24 changes: 14 additions & 10 deletions app/src/renderer/apps/Courier/components/ChatRow/ChatRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ type ChatRowProps = {
title: string;
peers: string[];
isAdmin: boolean;
muted: boolean;
metadata: any;
timestamp: number;
type: ChatPathType;
Expand Down Expand Up @@ -230,14 +229,7 @@ export const ChatRowPresenter = ({
>
{lastMessageTimestamp}
</Text.Custom>
{isMuted && (
<Icon
name="NotificationOff"
size={12}
fill="text"
opacity={0.3}
/>
)}
{unreadCount > 0 && <UnreadBadge count={unreadCount} />}
</Flex>
</Flex>
<Flex
Expand Down Expand Up @@ -265,7 +257,19 @@ export const ChatRowPresenter = ({
>
{lastMessageUpdated}
</Text.Custom>
<UnreadBadge count={unreadCount} />
<Flex gap="6px" alignItems="center">
{isMuted && (
<Icon
name="NotificationOff"
size={12}
fill="text"
opacity={0.3}
/>
)}
{isPinned && (
<Icon name="Pin" size={12} fill="text" opacity={0.3} />
)}
</Flex>
</Flex>
</Flex>
</Flex>
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 @@ -50,7 +50,7 @@ const ChatLogBodyPresenter = ({
onSend,
}: Props) => {
const { chatStore } = useShipStore();
const { selectedChat, setSubroute, inboxLoader } = chatStore;
const { selectedChat, setSubroute, chatLoader } = chatStore;

const messages = selectedChat?.messages ?? [];

Expand Down Expand Up @@ -93,7 +93,7 @@ const ChatLogBodyPresenter = ({
pinnedChatMessage={pinnedChatMessage}
isStandaloneChat={isStandaloneChat}
isEmpty={messages.length === 0}
isLoaded={inboxLoader.isLoaded}
isLoaded={chatLoader.isLoaded}
/>
</Flex>
<ChatInputContainer isStandaloneChat={isStandaloneChat}>
Expand Down
16 changes: 10 additions & 6 deletions app/src/renderer/apps/Courier/views/ChatLog/ChatLogBodyList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,16 @@ export const ChatLogBodyList = ({
isStandaloneChat,
pinnedChatMessage,
}: Props) => {
if (isEmpty && isLoaded) {
return (
<Text.Custom textAlign="center" width={300} fontSize={3} opacity={0.5}>
You haven't sent or received any messages in this chat yet.
</Text.Custom>
);
if (isEmpty) {
if (isLoaded) {
return (
<Text.Custom textAlign="center" width={300} fontSize={3} opacity={0.5}>
You haven't sent or received any messages in this chat yet.
</Text.Custom>
);
}

return null;
}

return (
Expand Down
15 changes: 11 additions & 4 deletions app/src/renderer/apps/Courier/views/Inbox/Inbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,15 @@ export const InboxPresenter = ({ isStandaloneChat = false }: Props) => {
const { loggedInAccount, shellStore } = useAppState();
const { chatStore, spacesStore } = useShipStore();

const { sortedChatList, loader, setChat, setSubroute, isChatPinned } =
chatStore;
const {
sortedChatList,
sortedStandaloneChatList,
inboxLoader,
inboxMetadataLoader,
setChat,
setSubroute,
isChatPinned,
} = chatStore;
const currentSpace = spacesStore.selected;

useEffect(() => {
Expand All @@ -25,11 +32,11 @@ export const InboxPresenter = ({ isStandaloneChat = false }: Props) => {

return (
<InboxBody
inboxes={sortedChatList}
inboxes={isStandaloneChat ? sortedStandaloneChatList : sortedChatList}
accountIdentity={loggedInAccount?.serverId}
spacePath={currentSpace?.path}
isStandaloneChat={isStandaloneChat}
isLoading={loader.isLoading}
isLoading={inboxLoader.isLoading || inboxMetadataLoader.isLoading}
isChatPinned={isChatPinned}
onClickInbox={(path) => {
setChat(path);
Expand Down
2 changes: 1 addition & 1 deletion app/src/renderer/apps/Courier/views/Inbox/InboxBody.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export const InboxBody = ({
</Button.IconButton>
</Flex>
</InboxBodyHeaderContainer>
{isLoading && <InboxBodyLoadingHeader />}
{isLoading && isStandaloneChat && <InboxBodyLoadingHeader />}
<InboxBodyList
inboxes={filteredInboxes}
spacePath={spacePath}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ export const InboxBodyLoadingHeader = () => (
transition={{ duration: 0.2, ease: 'easeInOut' }}
>
<Spinner size="16px" width={1.5} color="var(--rlm-text-color)" />
<Text.Body>Loading new messages...</Text.Body>
<Text.Body>Syncing messages...</Text.Body>
</Container>
);
10 changes: 1 addition & 9 deletions app/src/renderer/apps/Courier/views/Inbox/InboxRow.styles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,10 @@ export const StyledInboxRowContainer = styled(Box)<{
`}
`;

export const StyledInboxRow = styled(Box)<{
isPinned: boolean;
}>`
export const StyledInboxRow = styled(Box)`
width: 100%;
min-width: 0;
align-items: center;
z-index: 2;
border-radius: 6px;

${({ isPinned }) =>
isPinned &&
`
background: var(--rlm-overlay-hover-color);
`}
`;
8 changes: 1 addition & 7 deletions app/src/renderer/apps/Courier/views/Inbox/InboxRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,7 @@ export const InboxRow = ({
isSelectedSpaceChat={isSelectedSpaceChat}
className={className}
>
<StyledInboxRow
className="chat-inbox-row"
isPinned={isPinned}
// layout="preserve-aspect"
// layoutId={isStandaloneChat ? undefined : `chat-${inbox.path}-container`}
>
<StyledInboxRow className="chat-inbox-row">
<ChatRow
path={inbox.path}
title={inbox.metadata.title}
Expand All @@ -54,7 +49,6 @@ export const InboxRow = ({
timestamp={inbox.createdAt || inbox.metadata.timestamp}
metadata={inbox.metadata}
peersGetBacklog={inbox.peersGetBacklog}
muted={inbox.muted}
isStandaloneChat={isStandaloneChat}
onClick={(evt) => {
evt.stopPropagation();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export const StandaloneChatBodyPresenter = () => {
}
}, [chatStore.subroute, chatStore.selectedChat, chatStore.inbox]);

if (chatStore.loader.isFirstLoad) {
if (chatStore.inboxInitLoader.isFirstLoad) {
return (
<Flex
position="absolute"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ const StandaloneChatPassportPresenter = ({ onBack }: Props) => {
>
<ChatLogHeader
path={loggedInAccount.serverId}
rightAction={null}
isMuted={false}
hasMenu={false}
forceBackButton
Expand Down
Loading