Make modal responsive (#52)

This commit is contained in:
Oleksandr 2021-10-07 18:05:27 +02:00 committed by GitHub
parent 000ffa2aba
commit 2491bba0c6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 76 additions and 28 deletions

View File

@ -9,7 +9,12 @@ const macosPlatforms = ["Macintosh", "MacIntel", "MacPPC", "Mac68K"];
const windowsPlatforms = ["Win32", "Win64", "Windows", "WinCE"]; const windowsPlatforms = ["Win32", "Win64", "Windows", "WinCE"];
const iosPlatforms = ["iPhone", "iPad", "iPod"]; const iosPlatforms = ["iPhone", "iPad", "iPod"];
export const DownloadButton = ({ theme }: { theme: Theme }) => { interface DownloadButtonProps {
theme: Theme;
className?: string;
}
export const DownloadButton = ({ theme, className }: DownloadButtonProps) => {
const [link, setlink] = useState("https://status.im/get/"); const [link, setlink] = useState("https://status.im/get/");
const [os, setOs] = useState<string | null>(null); const [os, setOs] = useState<string | null>(null);
@ -43,7 +48,13 @@ export const DownloadButton = ({ theme }: { theme: Theme }) => {
}, []); }, []);
return ( return (
<Link href={link} theme={theme} target="_blank" rel="noopener noreferrer"> <Link
className={className}
href={link}
theme={theme}
target="_blank"
rel="noopener noreferrer"
>
{os ? `Download Status for ${os}` : "Download Status"} {os ? `Download Status for ${os}` : "Download Status"}
</Link> </Link>
); );

View File

@ -15,7 +15,7 @@ interface ChannelsProps {
community: CommunityData; community: CommunityData;
notifications: { [id: string]: number }; notifications: { [id: string]: number };
clearNotifications: (id: string) => void; clearNotifications: (id: string) => void;
onCommunityClick: () => void;
setActiveChannel: (val: ChannelData) => void; setActiveChannel: (val: ChannelData) => void;
activeChannelId: number; activeChannelId: number;
} }
@ -27,6 +27,7 @@ export function Channels({
setActiveChannel, setActiveChannel,
clearNotifications, clearNotifications,
activeChannelId, activeChannelId,
onCommunityClick,
}: ChannelsProps) { }: ChannelsProps) {
useEffect(() => { useEffect(() => {
const channel = channels.find((channel) => channel.id === activeChannelId); const channel = channels.find((channel) => channel.id === activeChannelId);
@ -39,7 +40,11 @@ export function Channels({
return ( return (
<ChannelsWrapper theme={theme}> <ChannelsWrapper theme={theme}>
<StyledCommunity theme={theme} community={community} /> <StyledCommunity
onClick={onCommunityClick}
theme={theme}
community={community}
/>
<ChannelList> <ChannelList>
{channels.map((channel) => ( {channels.map((channel) => (
<Channel <Channel

View File

@ -11,6 +11,7 @@ import { Theme } from "../styles/themes";
import { Channels } from "./Channels"; import { Channels } from "./Channels";
import { ChatBody } from "./Chat/ChatBody"; import { ChatBody } from "./Chat/ChatBody";
import { Members } from "./Members"; import { Members } from "./Members";
import { CommunityModal } from "./Modals/CommunityModal";
interface ChatProps { interface ChatProps {
theme: Theme; theme: Theme;
@ -37,6 +38,9 @@ export function Chat({ theme, community, fetchMetadata }: ChatProps) {
channels.map((channel) => channel.name) channels.map((channel) => channel.name)
); );
const [isModalVisible, setIsModalVisible] = useState(false);
const showModal = () => setIsModalVisible(true);
return ( return (
<ChatWrapper> <ChatWrapper>
{showChannels && !narrow && ( {showChannels && !narrow && (
@ -47,6 +51,7 @@ export function Chat({ theme, community, fetchMetadata }: ChatProps) {
community={community} community={community}
setActiveChannel={setActiveChannel} setActiveChannel={setActiveChannel}
activeChannelId={activeChannel.id} activeChannelId={activeChannel.id}
onCommunityClick={showModal}
/> />
)} )}
<ChatBody <ChatBody
@ -63,6 +68,7 @@ export function Chat({ theme, community, fetchMetadata }: ChatProps) {
community={community} community={community}
showCommunity={!showChannels} showCommunity={!showChannels}
loadNextDay={() => loadNextDay(activeChannel.name)} loadNextDay={() => loadNextDay(activeChannel.name)}
onCommunityClick={showModal}
lastMessage={lastMessage} lastMessage={lastMessage}
fetchMetadata={fetchMetadata} fetchMetadata={fetchMetadata}
/> />
@ -73,6 +79,16 @@ export function Chat({ theme, community, fetchMetadata }: ChatProps) {
setShowChannels={setShowChannels} setShowChannels={setShowChannels}
/> />
)} )}
<CommunityModal
isVisible={isModalVisible}
onClose={() => setIsModalVisible(false)}
icon={community.icon}
name={community.name}
theme={theme}
subtitle="Public Community"
description={community.description}
publicKey="0xD95DBdaB08A9FED2D71ac9C3028AAc40905d8CF3"
/>
</ChatWrapper> </ChatWrapper>
); );
} }

View File

@ -33,6 +33,7 @@ interface ChatBodyProps {
setActiveChannel: (val: ChannelData) => void; setActiveChannel: (val: ChannelData) => void;
activeChannelId: number; activeChannelId: number;
loadNextDay: () => void; loadNextDay: () => void;
onCommunityClick: () => void;
lastMessage: Date; lastMessage: Date;
fetchMetadata?: (url: string) => Promise<Metadata | undefined>; fetchMetadata?: (url: string) => Promise<Metadata | undefined>;
} }
@ -51,6 +52,7 @@ export function ChatBody({
setActiveChannel, setActiveChannel,
activeChannelId, activeChannelId,
loadNextDay, loadNextDay,
onCommunityClick,
lastMessage, lastMessage,
fetchMetadata, fetchMetadata,
}: ChatBodyProps) { }: ChatBodyProps) {
@ -80,7 +82,11 @@ export function ChatBody({
<ChannelWrapper className={className}> <ChannelWrapper className={className}>
{(showCommunity || narrow) && ( {(showCommunity || narrow) && (
<CommunityWrap theme={theme} className={className}> <CommunityWrap theme={theme} className={className}>
<Community community={community} theme={theme} /> <Community
onClick={onCommunityClick}
community={community}
theme={theme}
/>
</CommunityWrap> </CommunityWrap>
)} )}
<Channel <Channel

View File

@ -1,25 +1,28 @@
import React, { useState } from "react"; import React from "react";
import { CommunityData } from "../helpers/communityMock"; import { CommunityData } from "../helpers/communityMock";
import { Theme } from "../styles/themes"; import { Theme } from "../styles/themes";
import { CommunityIdentity } from "./CommunityIdentity"; import { CommunityIdentity } from "./CommunityIdentity";
import { CommunityModal } from "./Modals/CommunityModal";
interface CommunityProps { interface CommunityProps {
theme: Theme; theme: Theme;
community: CommunityData; community: CommunityData;
onClick: () => void;
className?: string; className?: string;
} }
export function Community({ theme, community, className }: CommunityProps) { export function Community({
const { name, icon, members, description } = community; theme,
community,
const [isModalVisible, setIsModalVisible] = useState(false); onClick,
className,
}: CommunityProps) {
const { name, icon, members } = community;
return ( return (
<> <>
<button className={className} onClick={() => setIsModalVisible(true)}> <button className={className} onClick={onClick}>
<CommunityIdentity <CommunityIdentity
name={name} name={name}
icon={icon} icon={icon}
@ -27,16 +30,6 @@ export function Community({ theme, community, className }: CommunityProps) {
theme={theme} theme={theme}
/> />
</button> </button>
<CommunityModal
isVisible={isModalVisible}
onClose={() => setIsModalVisible(false)}
icon={icon}
name={name}
theme={theme}
subtitle="Public Community"
description={description}
publicKey="0xD95DBdaB08A9FED2D71ac9C3028AAc40905d8CF3"
/>
</> </>
); );
} }

View File

@ -17,7 +17,7 @@ export const CopyInput = ({ label, value, theme }: CopyInputProps) => (
<Label theme={theme}>{label}</Label> <Label theme={theme}>{label}</Label>
<Wrapper theme={theme}> <Wrapper theme={theme}>
<Text theme={theme}>{reduceString(value, 15, 15)}</Text> <Text theme={theme}>{reduceString(value, 15, 15)}</Text>
<CopyButtonWrapper> <CopyButtonWrapper theme={theme}>
<CopyButton theme={theme} onClick={() => copy(value)}> <CopyButton theme={theme} onClick={() => copy(value)}>
Copy Copy
</CopyButton> </CopyButton>

View File

@ -1,6 +1,7 @@
import React from "react"; import React from "react";
import styled from "styled-components"; import styled from "styled-components";
import { useNarrow } from "../../contexts/narrowProvider";
import { DownloadButton } from "../Buttons/DownloadButton"; import { DownloadButton } from "../Buttons/DownloadButton";
import { import {
CommunityIdentity, CommunityIdentity,
@ -27,6 +28,8 @@ export const CommunityModal = ({
publicKey, publicKey,
theme, theme,
}: CommunityModalProps) => { }: CommunityModalProps) => {
const narrow = useNarrow();
return ( return (
<Modal theme={theme} isVisible={isVisible} onClose={onClose}> <Modal theme={theme} isVisible={isVisible} onClose={onClose}>
<Section theme={theme}> <Section theme={theme}>
@ -48,13 +51,16 @@ export const CommunityModal = ({
/> />
<Hint theme={theme}> <Hint theme={theme}>
To access this community, paste community public key in Status desktop To access this community, paste community public key in Status desktop
or mobile app or mobile app.
{narrow && <StyledDownloadButton theme={theme} />}
</Hint> </Hint>
</Section> </Section>
<BottomSection theme={theme}> {!narrow && (
<StatusLogo theme={theme} /> <BottomSection theme={theme}>
<DownloadButton theme={theme} /> <StatusLogo theme={theme} />
</BottomSection> <DownloadButton theme={theme} />
</BottomSection>
)}
</Modal> </Modal>
); );
}; };
@ -85,3 +91,14 @@ const BottomSection = styled(Section)`
flex-direction: column; flex-direction: column;
align-items: center; align-items: center;
`; `;
const StyledDownloadButton = styled(DownloadButton)`
display: inline;
padding: 0;
margin-left: 4px;
background: none;
font-size: 13px;
line-height: 18px;
text-decoration: underline;
color: ${({ theme }) => theme.secondary};
`;