working text field interactions and quote/replying

This commit is contained in:
erik-sn committed 2020-09-26 20:18:29 -04:00
1 parent c9f27266bb
commit d54eb50739
12 files changed
+154 -66

No files matched your search

@@ -1,4 +1,5 @@
import React, { useState, useEffect } from "react";
import { useRecoilState } from "recoil";
import { makeStyles } from "@material-ui/core/styles";
import { Button, Paper } from "@material-ui/core";
import CloseIcon from "@material-ui/icons/Close";
@@ -7,6 +8,7 @@ import { v4 as uuidv4 } from "uuid";
import Nui from "../../../os/nui-events/utils/Nui";
import { IMAGE_DELIMITER } from "../utils/images";
import { withValidImage } from "../utils/images";
import { useModal } from "../hooks/useModal";
import EmojiSelect from "./EmojiSelect";
import ImageDisplay from "./ImageDisplay";
import ImagePrompt from "./ImagePrompt";
@@ -16,17 +18,19 @@ import IconButtons from "./IconButtons";
import AddTweetStatus from "./AddTweetStatus";
const useStyles = makeStyles((theme) => ({
button: {
margin: 5,
marginTop: 20,
},
root: {
zIndex: 2,
background: "#232323",
zIndex: 10,
background: "#424242",
marginTop: "15px",
width: "90%",
display: "flex",
flexFlow: "column nowrap",
position: "absolute",
top: "35px",
},
button: {
margin: 5,
marginTop: 20,
},
close: {
position: "absolute",
@@ -59,13 +63,14 @@ const useStyles = makeStyles((theme) => ({
},
}));
export const AddTweetModal = ({ visible, handleClose }) => {
export const AddTweetModal = () => {
const classes = useStyles();
const { message, setMessage, modalVisible, setModalVisible } = useModal();
const [showEmoji, setShowEmoji] = useState(false);
const [showImagePrompt, setShowImagePrompt] = useState(false);
const [link, setLink] = useState("");
const [message, setMessage] = useState("");
const [images, setImages] = useState([]);
const reset = () => {
@@ -79,7 +84,7 @@ export const AddTweetModal = ({ visible, handleClose }) => {
const _handleClose = () => {
reset();
handleClose();
setModalVisible(false);
};
// when the user presses escape we should close the modal
@@ -95,11 +100,13 @@ export const AddTweetModal = ({ visible, handleClose }) => {
return () => window.removeEventListener("keydown", listener);
}, []);
const showHideClassName = visible
const showHideClassName = modalVisible
? classes.displayBlock
: classes.displayNone;
const submitTweet = () => {
if (message.trim().length === 0) return;
const data = {
message,
images:
@@ -1,29 +1,16 @@
import React, { memo } from "react";
import { makeStyles } from "@material-ui/core/styles";
import { Picker } from "emoji-mart";
import "./emoji.css";
import "emoji-mart/css/emoji-mart.css";
const useStyles = makeStyles((theme) => ({
emojiPicker: {
background: "none",
border: "none",
boxShadow: "none",
},
}));
export const EmojiSelect = ({ visible, onEmojiClick }) => {
const classes = useStyles();
if (!visible) return null;
return (
<Picker
className={classes.emojiPicker}
onClick={onEmojiClick}
set="google"
includes={["smileys"]}
theme="dark"
showPreview={false}
/>
@@ -0,0 +1,24 @@
import React from "react";
import Button from "@material-ui/core/Button";
import QuoteIcon from "@material-ui/icons/FormatQuote";
import { useModal } from "../hooks/useModal";
export const QuoteButton = ({ message }) => {
const { setMessage, setModalVisible } = useModal();
const handleClick = () => {
setMessage(`> ${message}
`);
setModalVisible(true);
};
return (
<Button onClick={handleClick}>
<QuoteIcon />
</Button>
);
};
export default QuoteButton;
@@ -0,0 +1,21 @@
import React from "react";
import Button from "@material-ui/core/Button";
import ReplyIcon from "@material-ui/icons/Reply";
import { useModal } from "../hooks/useModal";
export const ReplyButton = ({ profile_name }) => {
const { setMessage, setModalVisible } = useModal();
const handleClick = () => {
setMessage(`@${profile_name} `);
setModalVisible(true);
};
return (
<Button onClick={handleClick}>
<ReplyIcon />
</Button>
);
};
export default ReplyButton;
+9 -9
View File
@@ -7,13 +7,13 @@ import MuiAvatar from "@material-ui/core/Avatar";
import Button from "@material-ui/core/Button";
import Typography from "@material-ui/core/Typography";
import FavoriteBorderIcon from "@material-ui/icons/FavoriteBorder";
import ReplyIcon from "@material-ui/icons/Reply";
import QuoteIcon from "@material-ui/icons/FormatQuote";
import { ListItem } from "../../../ui/components/ListItem";
import { secondsToHumanReadable } from "../utils/time";
import ReplyButton from "./ReplyButton";
import ImageDisplay from "./ImageDisplay";
import Avatar from "./Avatar";
import { QuoteButton } from "./QuoteButton";
const useStyles = makeStyles(() => ({
root: {
@@ -22,6 +22,7 @@ const useStyles = makeStyles(() => ({
flexFlow: "row nowrap",
alignItems: "flex-start",
width: "100%",
marginTop: "3px",
},
content: {
display: "flex",
@@ -52,9 +53,12 @@ export const Tweet = (tweet) => {
const classes = useStyles();
const { t } = useTranslation();
// this is a workaround to transfer string new lines and returns that
// are stored into the database into html for the UI to render
const formattedMessage = message.replace(/\n\r?/g, "<br />");
const Message = () => (
<>
<div>{message}</div>
<div dangerouslySetInnerHTML={{ __html: formattedMessage }} />
<ImageDisplay visible images={images} small />
</>
);
@@ -83,15 +87,11 @@ export const Tweet = (tweet) => {
<div className={classes.content}>
<ListItemText primary={<Primary />} secondary={<Message />} />
<div className={classes.buttonContainer}>
<Button>
<ReplyIcon />
</Button>
<ReplyButton profile_name={profile_name} />
<Button>
<FavoriteBorderIcon />
</Button>
<Button>
<QuoteIcon />
</Button>
<QuoteButton message={message} />
</div>
</div>
</ListItem>
+2 -24
View File
@@ -1,31 +1,9 @@
import React, { useEffect } from "react";
import React from "react";
import Nui from "../../../os/nui-events/utils/Nui";
import { List } from "../../../ui/components/List";
import { useTweets } from "../hooks/useTweets";
import Tweet from "./Tweet";
const TWEETS_REFRESH_RATE = 50000000; // TODO move this to twitter config
export function TweetList() {
const { tweets } = useTweets();
useEffect(() => {
Nui.send("phone:fetchTweets", {});
// this is a polling implementation. It is possible that
// there is some interaction where, on a new tweet, all
// clients are sent the updated query data. Until that can
// be accomplished this is naive but robust.
//
// TODO don't call fetchTweets - implement a function that only
// returns tweets that we don't already have
const timeout = window.setTimeout(() => {
Nui.send("phone:fetchTweets", {});
}, TWEETS_REFRESH_RATE);
return () => window.clearTimeout(timeout);
}, []);
export function TweetList({ tweets }) {
return (
<List>
{tweets.map((tweet) => (
@@ -0,0 +1,32 @@
import React, { useEffect } from "react";
import Nui from "../../../os/nui-events/utils/Nui";
import { List } from "../../../ui/components/List";
import { useTweets } from "../hooks/useTweets";
import TweetList from "./TweetList";
const TWEETS_REFRESH_RATE = 50000000; // TODO move this to twitter config
export function TweetListContainer() {
const { tweets } = useTweets();
useEffect(() => {
Nui.send("phone:fetchTweets", {});
// this is a polling implementation. It is possible that
// there is some interaction where, on a new tweet, all
// clients are sent the updated query data. Until that can
// be accomplished this is naive but robust.
//
// TODO don't call fetchTweets - implement a function that only
// returns tweets that we don't already have
const timeout = window.setTimeout(() => {
Nui.send("phone:fetchTweets", {});
}, TWEETS_REFRESH_RATE);
return () => window.clearTimeout(timeout);
}, []);
return <TweetList tweets={tweets} />;
}
export default TweetListContainer;
@@ -1,4 +1,4 @@
import React from "react";
import React, { useEffect, useRef } from "react";
import { useTranslation } from "react-i18next";
import { makeStyles } from "@material-ui/core/styles";
import { TextField } from "@material-ui/core";
@@ -20,6 +20,7 @@ const useStyles = makeStyles((theme) => ({
export const TweetMessage = ({ message, handleChange }) => {
const classes = useStyles();
const { t } = useTranslation();
return (
<TextField
value={message}
@@ -28,6 +29,7 @@ export const TweetMessage = ({ message, handleChange }) => {
onChange={handleChange}
multiline
placeholder={t("APPS_TWITTER_PLACEHOLDER")}
inputRef={(input) => input && input.focus()}
/>
);
};
@@ -1,10 +1,10 @@
import React, { useState, useEffect } from "react";
import { makeStyles } from "@material-ui/core";
import { makeStyles } from "@material-ui/core/styles";
import Nui from "../../../os/nui-events/utils/Nui";
import { AppWrapper } from "../../../ui/components";
import { AppContent } from "../../../ui/components/AppContent";
import TweetList from "./TweetList";
import TweetListContainer from "./TweetListContainer";
import AddTweetModal from "./AddTweetModal";
import { AppLoader } from "../../../ui/components/AppLoader";
import TweetButton from "./TweetButton";
@@ -14,18 +14,33 @@ import TwitterProfile from "./profile/TwitterProfile";
import { useProfile } from "../hooks/useProfile";
import "./twitter.css";
import { useModal } from "../hooks/useModal";
const useStyles = makeStyles((theme) => ({
backgroundModal: {
background: "black",
opacity: "0.6",
position: "absolute",
top: 0,
left: 0,
right: 0,
bottom: 0,
zIndex: 5,
},
}));
// TODO move this to the router so the application back button works
const PAGE_COMPONENT_MAPPING = {
0: <TweetList />,
1: <TweetList />,
0: <TweetListContainer />,
1: <TweetListContainer />,
2: <TwitterProfile />,
};
const MINIMUM_LOAD_TIME = 750;
export const TwitterApp = () => {
const classes = useStyles();
const { modalVisible, setModalVisible } = useModal();
const [minimumLoadPassed, setMimimumLoadPassed] = useState(false);
const [modalVisible, setModalVisible] = useState(false);
const [activePage, setActivePage] = useState(0);
const { profile } = useProfile();
@@ -57,11 +72,10 @@ export const TwitterApp = () => {
return (
<AppWrapper id="twitter-app">
<AddTweetModal />
<div className={modalVisible ? classes.backgroundModal : null} />
<TwitterTitle />
<AppContent>
<AddTweetModal visible={modalVisible} handleClose={hideModal} />
{component}
</AppContent>
<AppContent>{component}</AppContent>
{showTweetButton && <TweetButton openModal={openModal} />}
<BottomNavigation
activePage={activePage}
@@ -1,6 +1,11 @@
/* 00acee is "twitter blue" and we want to use that to override
some of the Material UI primary theme settings */
/* override buttons on the tweet modal */
#twitter-app .MuiButton-containedPrimary {
background: #00acee !important;
}
/* override the bottom navigation active color */
#twitter-app .Mui-selected {
color: #00acee !important;
+8
View File
@@ -9,6 +9,14 @@ export const twitterState = {
key: "tweets",
default: [],
}),
showCreateTweetModal: atom({
key: "showCreateTweetModal",
default: false,
}),
modalMessage: atom({
key: "modalMessage",
default: "",
}),
createTweetLoading: atom({
key: "createTweetLoading",
default: false,
+10
View File
@@ -0,0 +1,10 @@
import { useRecoilState } from "recoil";
import { twitterState } from "./state";
export const useModal = () => {
const [modalVisible, setModalVisible] = useRecoilState(
twitterState.showCreateTweetModal
);
const [message, setMessage] = useRecoilState(twitterState.modalMessage);
return { modalVisible, setModalVisible, message, setMessage };
};