moved modal to standalone component

This commit is contained in:
erik-sn committed 2020-10-03 10:35:22 -04:00
1 parent b2b69365ba
commit 11977c48ef
4 files changed
+60 -18

No files matched your search

+1 -2
View File
@@ -18,7 +18,6 @@ import { useApps } from "./os/apps/hooks/useApps";
import { useContactsService } from "./apps/contacts/hooks/useContactsService"; import { useContactsService } from "./apps/contacts/hooks/useContactsService";
import { useTwitterService } from "./apps/twitter/hooks/useTwitterService"; import { useTwitterService } from "./apps/twitter/hooks/useTwitterService";
import { TwitterApp } from "./apps/twitter/components/TwitterApp";
// These events are just for testing. Comment it out before building. // These events are just for testing. Comment it out before building.
//setTimeout(() => { //setTimeout(() => {
@@ -110,7 +109,7 @@ function Phone() {
]} ]}
/> />
<div className="PhoneAppContainer"> <div className="PhoneAppContainer">
<Route exact path="/" component={TwitterApp} /> <Route exact path="/" component={HomeApp} />
{allApps.map((App) => ( {allApps.map((App) => (
<App.Route key={App.id} /> <App.Route key={App.id} />
))} ))}
@@ -6,6 +6,7 @@ import CloseIcon from "@material-ui/icons/Close";
import { v4 as uuidv4 } from "uuid"; import { v4 as uuidv4 } from "uuid";
import Nui from "../../../os/nui-events/utils/Nui"; import Nui from "../../../os/nui-events/utils/Nui";
import Modal from "../../../ui/components/Modal";
import { IMAGE_DELIMITER } from "../utils/images"; import { IMAGE_DELIMITER } from "../utils/images";
import { withValidImage } from "../utils/images"; import { withValidImage } from "../utils/images";
import { useModal } from "../hooks/useModal"; import { useModal } from "../hooks/useModal";
@@ -44,17 +45,6 @@ const useStyles = makeStyles((theme) => ({
justifyContent: "space-between", justifyContent: "space-between",
flex: "1 0 45px", flex: "1 0 45px",
}, },
displayBlock: {
/*Sets modal to center*/
display: "flex",
flexFlow: "column nowrap",
justifyContent: "center",
alignItems: "center",
position: "relative",
},
displayNone: {
display: "none",
},
emojiPicker: { emojiPicker: {
background: "none", background: "none",
border: "none", border: "none",
@@ -162,8 +152,7 @@ export const AddTweetModal = () => {
}; };
return ( return (
<div className={showHideClassName}> <Modal visible={modalVisible} handleClose={_handleClose}>
<Paper className={classes.root}>
<Button className={classes.close} onClick={_handleClose}> <Button className={classes.close} onClick={_handleClose}>
<CloseIcon color="action" /> <CloseIcon color="action" />
</Button> </Button>
@@ -191,8 +180,7 @@ export const AddTweetModal = () => {
onCloseClick={showEmoji ? toggleShowEmoji : toggleShowImagePrompt} onCloseClick={showEmoji ? toggleShowEmoji : toggleShowImagePrompt}
/> />
</div> </div>
</Paper> </Modal>
</div>
); );
}; };
@@ -66,7 +66,6 @@ export function TwitterProfile() {
value={bio} value={bio}
handleChange={handleBioChange} handleChange={handleBioChange}
multiline multiline
inputRef={(input) => input && input.focus()}
/> />
<ProfileField <ProfileField
label={t("APPS_TWITTER_EDIT_PROFILE_LOCATION")} label={t("APPS_TWITTER_EDIT_PROFILE_LOCATION")}
+56
View File
@@ -0,0 +1,56 @@
import React, { useEffect } from "react";
import { makeStyles } from "@material-ui/core/styles";
import { Paper } from "@material-ui/core";
const useStyles = makeStyles((theme) => ({
root: {
zIndex: 10,
background: "#424242",
marginTop: "15px",
width: "90%",
display: "flex",
flexFlow: "column nowrap",
position: "absolute",
top: "80px",
},
displayBlock: {
/*Sets modal to center*/
display: "flex",
flexFlow: "column nowrap",
justifyContent: "center",
alignItems: "center",
position: "relative",
},
displayNone: {
display: "none",
},
}));
export const Modal = ({ children, visible, handleClose }) => {
const classes = useStyles();
// when the user presses escape we should close the modal
const _handleEscape = (e) => {
const isEscapeKey = e.key == "Escape" || e.key == "Esc";
if (isEscapeKey) {
e.preventDefault();
handleClose();
}
};
useEffect(() => {
const listener = window.addEventListener("keydown", _handleEscape, true);
return () => window.removeEventListener("keydown", listener);
}, []);
const showHideClassName = visible
? classes.displayBlock
: classes.displayNone;
return (
<div className={showHideClassName}>
<Paper className={classes.root}>{children}</Paper>
</div>
);
};
export default Modal;