Add loading messages button (#58)

This commit is contained in:
Maria Rushkova 2021-10-11 17:09:41 +02:00 committed by GitHub
parent fab6113163
commit 2b0a50282c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 27 additions and 8 deletions

View File

@ -32,7 +32,6 @@ export function Chat({ theme, community, fetchMetadata }: ChatProps) {
notifications, notifications,
clearNotifications, clearNotifications,
loadNextDay, loadNextDay,
lastMessage,
} = useMessenger( } = useMessenger(
activeChannel.name, activeChannel.name,
channels.map((channel) => channel.name) channels.map((channel) => channel.name)
@ -68,7 +67,6 @@ export function Chat({ theme, community, fetchMetadata }: ChatProps) {
showCommunity={!showChannels} showCommunity={!showChannels}
loadNextDay={() => loadNextDay(activeChannel.name)} loadNextDay={() => loadNextDay(activeChannel.name)}
onCommunityClick={showModal} onCommunityClick={showModal}
lastMessage={lastMessage}
fetchMetadata={fetchMetadata} fetchMetadata={fetchMetadata}
/> />
{showMembers && !narrow && ( {showMembers && !narrow && (

View File

@ -34,7 +34,6 @@ interface ChatBodyProps {
activeChannelId: number; activeChannelId: number;
loadNextDay: () => void; loadNextDay: () => void;
onCommunityClick: () => void; onCommunityClick: () => void;
lastMessage: Date;
fetchMetadata?: (url: string) => Promise<Metadata | undefined>; fetchMetadata?: (url: string) => Promise<Metadata | undefined>;
} }
@ -53,7 +52,6 @@ export function ChatBody({
activeChannelId, activeChannelId,
loadNextDay, loadNextDay,
onCommunityClick, onCommunityClick,
lastMessage,
fetchMetadata, fetchMetadata,
}: ChatBodyProps) { }: ChatBodyProps) {
const narrow = useNarrow(); const narrow = useNarrow();
@ -108,9 +106,6 @@ export function ChatBody({
<> <>
{!showChannelsList && !showMembersList && ( {!showChannelsList && !showMembersList && (
<> <>
<button onClick={loadNextDay}>
Last message date {lastMessage.toDateString()}
</button>{" "}
{messages.length > 0 ? ( {messages.length > 0 ? (
messenger ? ( messenger ? (
<ChatMessages <ChatMessages

View File

@ -3,6 +3,7 @@ import styled from "styled-components";
import { ChatMessage } from "../../models/ChatMessage"; import { ChatMessage } from "../../models/ChatMessage";
import { Metadata } from "../../models/Metadata"; import { Metadata } from "../../models/Metadata";
import { LoadingIcon } from "../Icons/LoadingIcon";
import { UserIcon } from "../Icons/UserIcon"; import { UserIcon } from "../Icons/UserIcon";
import { PictureModal } from "../Modals/PictureModal"; import { PictureModal } from "../Modals/PictureModal";
import { textSmallStyles } from "../Text"; import { textSmallStyles } from "../Text";
@ -60,6 +61,9 @@ export function ChatMessages({
onClose={() => setImage("")} onClose={() => setImage("")}
image={image} image={image}
/> />
<LoadingWrapper>
<LoadingIcon className="message" />
</LoadingWrapper>
{messages.map((message, idx) => { {messages.map((message, idx) => {
return ( return (
<MessageOuterWrapper key={message.date.getTime()}> <MessageOuterWrapper key={message.date.getTime()}>
@ -101,6 +105,8 @@ export function ChatMessages({
} }
const MessagesWrapper = styled.div` const MessagesWrapper = styled.div`
display: flex;
flex-direction: column;
height: calc(100% - 44px); height: calc(100% - 44px);
overflow: auto; overflow: auto;
padding: 8px 16px 0; padding: 8px 16px 0;
@ -184,3 +190,12 @@ const MessageText = styled.div`
white-space: pre-wrap; white-space: pre-wrap;
color: ${({ theme }) => theme.primary}; color: ${({ theme }) => theme.primary};
`; `;
const LoadingWrapper = styled.div`
display: flex;
align-self: center;
align-items: center;
justify-content: center;
background: ${({ theme }) => theme.bodyBackgroundColor};
position: relative;
`;

View File

@ -10,12 +10,17 @@ const rotation = keyframes`
} }
`; `;
export const LoadingIcon = () => ( interface LoadingIconProps {
className?: string;
}
export const LoadingIcon = ({ className }: LoadingIconProps) => (
<Icon <Icon
width="13" width="13"
height="12" height="12"
viewBox="0 0 13 12" viewBox="0 0 13 12"
xmlns="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg"
className={className}
> >
<path <path
fillRule="evenodd" fillRule="evenodd"
@ -30,4 +35,10 @@ const Icon = styled.svg`
fill: ${({ theme }) => theme.primary}; fill: ${({ theme }) => theme.primary};
} }
animation: ${rotation} 2s linear infinite; animation: ${rotation} 2s linear infinite;
&.message {
& > path {
fill: ${({ theme }) => theme.secondary};
}
}
`; `;