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

View File

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

View File

@ -3,6 +3,7 @@ import styled from "styled-components";
import { ChatMessage } from "../../models/ChatMessage";
import { Metadata } from "../../models/Metadata";
import { LoadingIcon } from "../Icons/LoadingIcon";
import { UserIcon } from "../Icons/UserIcon";
import { PictureModal } from "../Modals/PictureModal";
import { textSmallStyles } from "../Text";
@ -60,6 +61,9 @@ export function ChatMessages({
onClose={() => setImage("")}
image={image}
/>
<LoadingWrapper>
<LoadingIcon className="message" />
</LoadingWrapper>
{messages.map((message, idx) => {
return (
<MessageOuterWrapper key={message.date.getTime()}>
@ -101,6 +105,8 @@ export function ChatMessages({
}
const MessagesWrapper = styled.div`
display: flex;
flex-direction: column;
height: calc(100% - 44px);
overflow: auto;
padding: 8px 16px 0;
@ -184,3 +190,12 @@ const MessageText = styled.div`
white-space: pre-wrap;
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
width="13"
height="12"
viewBox="0 0 13 12"
xmlns="http://www.w3.org/2000/svg"
className={className}
>
<path
fillRule="evenodd"
@ -30,4 +35,10 @@ const Icon = styled.svg`
fill: ${({ theme }) => theme.primary};
}
animation: ${rotation} 2s linear infinite;
&.message {
& > path {
fill: ${({ theme }) => theme.secondary};
}
}
`;