mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-05 06:28:51 +00:00
working text field interactions and quote/replying
This commit is contained in:
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 React, { useState, useEffect } from "react";
|
||||||
|
import { useRecoilState } from "recoil";
|
||||||
import { makeStyles } from "@material-ui/core/styles";
|
import { makeStyles } from "@material-ui/core/styles";
|
||||||
import { Button, Paper } from "@material-ui/core";
|
import { Button, Paper } from "@material-ui/core";
|
||||||
import CloseIcon from "@material-ui/icons/Close";
|
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 Nui from "../../../os/nui-events/utils/Nui";
|
||||||
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 EmojiSelect from "./EmojiSelect";
|
import EmojiSelect from "./EmojiSelect";
|
||||||
import ImageDisplay from "./ImageDisplay";
|
import ImageDisplay from "./ImageDisplay";
|
||||||
import ImagePrompt from "./ImagePrompt";
|
import ImagePrompt from "./ImagePrompt";
|
||||||
@@ -16,17 +18,19 @@ import IconButtons from "./IconButtons";
|
|||||||
import AddTweetStatus from "./AddTweetStatus";
|
import AddTweetStatus from "./AddTweetStatus";
|
||||||
|
|
||||||
const useStyles = makeStyles((theme) => ({
|
const useStyles = makeStyles((theme) => ({
|
||||||
button: {
|
|
||||||
margin: 5,
|
|
||||||
marginTop: 20,
|
|
||||||
},
|
|
||||||
root: {
|
root: {
|
||||||
zIndex: 2,
|
zIndex: 10,
|
||||||
background: "#232323",
|
background: "#424242",
|
||||||
marginTop: "15px",
|
marginTop: "15px",
|
||||||
width: "90%",
|
width: "90%",
|
||||||
display: "flex",
|
display: "flex",
|
||||||
flexFlow: "column nowrap",
|
flexFlow: "column nowrap",
|
||||||
|
position: "absolute",
|
||||||
|
top: "35px",
|
||||||
|
},
|
||||||
|
button: {
|
||||||
|
margin: 5,
|
||||||
|
marginTop: 20,
|
||||||
},
|
},
|
||||||
close: {
|
close: {
|
||||||
position: "absolute",
|
position: "absolute",
|
||||||
@@ -59,13 +63,14 @@ const useStyles = makeStyles((theme) => ({
|
|||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
|
|
||||||
export const AddTweetModal = ({ visible, handleClose }) => {
|
export const AddTweetModal = () => {
|
||||||
const classes = useStyles();
|
const classes = useStyles();
|
||||||
|
const { message, setMessage, modalVisible, setModalVisible } = useModal();
|
||||||
|
|
||||||
const [showEmoji, setShowEmoji] = useState(false);
|
const [showEmoji, setShowEmoji] = useState(false);
|
||||||
const [showImagePrompt, setShowImagePrompt] = useState(false);
|
const [showImagePrompt, setShowImagePrompt] = useState(false);
|
||||||
const [link, setLink] = useState("");
|
const [link, setLink] = useState("");
|
||||||
|
|
||||||
const [message, setMessage] = useState("");
|
|
||||||
const [images, setImages] = useState([]);
|
const [images, setImages] = useState([]);
|
||||||
|
|
||||||
const reset = () => {
|
const reset = () => {
|
||||||
@@ -79,7 +84,7 @@ export const AddTweetModal = ({ visible, handleClose }) => {
|
|||||||
|
|
||||||
const _handleClose = () => {
|
const _handleClose = () => {
|
||||||
reset();
|
reset();
|
||||||
handleClose();
|
setModalVisible(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
// when the user presses escape we should close the modal
|
// when the user presses escape we should close the modal
|
||||||
@@ -95,11 +100,13 @@ export const AddTweetModal = ({ visible, handleClose }) => {
|
|||||||
return () => window.removeEventListener("keydown", listener);
|
return () => window.removeEventListener("keydown", listener);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const showHideClassName = visible
|
const showHideClassName = modalVisible
|
||||||
? classes.displayBlock
|
? classes.displayBlock
|
||||||
: classes.displayNone;
|
: classes.displayNone;
|
||||||
|
|
||||||
const submitTweet = () => {
|
const submitTweet = () => {
|
||||||
|
if (message.trim().length === 0) return;
|
||||||
|
|
||||||
const data = {
|
const data = {
|
||||||
message,
|
message,
|
||||||
images:
|
images:
|
||||||
|
|||||||
@@ -1,29 +1,16 @@
|
|||||||
import React, { memo } from "react";
|
import React, { memo } from "react";
|
||||||
import { makeStyles } from "@material-ui/core/styles";
|
|
||||||
import { Picker } from "emoji-mart";
|
import { Picker } from "emoji-mart";
|
||||||
|
|
||||||
import "./emoji.css";
|
import "./emoji.css";
|
||||||
import "emoji-mart/css/emoji-mart.css";
|
import "emoji-mart/css/emoji-mart.css";
|
||||||
|
|
||||||
const useStyles = makeStyles((theme) => ({
|
|
||||||
emojiPicker: {
|
|
||||||
background: "none",
|
|
||||||
border: "none",
|
|
||||||
boxShadow: "none",
|
|
||||||
},
|
|
||||||
}));
|
|
||||||
|
|
||||||
export const EmojiSelect = ({ visible, onEmojiClick }) => {
|
export const EmojiSelect = ({ visible, onEmojiClick }) => {
|
||||||
const classes = useStyles();
|
|
||||||
|
|
||||||
if (!visible) return null;
|
if (!visible) return null;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Picker
|
<Picker
|
||||||
className={classes.emojiPicker}
|
|
||||||
onClick={onEmojiClick}
|
onClick={onEmojiClick}
|
||||||
set="google"
|
set="google"
|
||||||
includes={["smileys"]}
|
|
||||||
theme="dark"
|
theme="dark"
|
||||||
showPreview={false}
|
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;
|
||||||
@@ -7,13 +7,13 @@ import MuiAvatar from "@material-ui/core/Avatar";
|
|||||||
import Button from "@material-ui/core/Button";
|
import Button from "@material-ui/core/Button";
|
||||||
import Typography from "@material-ui/core/Typography";
|
import Typography from "@material-ui/core/Typography";
|
||||||
import FavoriteBorderIcon from "@material-ui/icons/FavoriteBorder";
|
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 { ListItem } from "../../../ui/components/ListItem";
|
||||||
import { secondsToHumanReadable } from "../utils/time";
|
import { secondsToHumanReadable } from "../utils/time";
|
||||||
|
import ReplyButton from "./ReplyButton";
|
||||||
import ImageDisplay from "./ImageDisplay";
|
import ImageDisplay from "./ImageDisplay";
|
||||||
import Avatar from "./Avatar";
|
import Avatar from "./Avatar";
|
||||||
|
import { QuoteButton } from "./QuoteButton";
|
||||||
|
|
||||||
const useStyles = makeStyles(() => ({
|
const useStyles = makeStyles(() => ({
|
||||||
root: {
|
root: {
|
||||||
@@ -22,6 +22,7 @@ const useStyles = makeStyles(() => ({
|
|||||||
flexFlow: "row nowrap",
|
flexFlow: "row nowrap",
|
||||||
alignItems: "flex-start",
|
alignItems: "flex-start",
|
||||||
width: "100%",
|
width: "100%",
|
||||||
|
marginTop: "3px",
|
||||||
},
|
},
|
||||||
content: {
|
content: {
|
||||||
display: "flex",
|
display: "flex",
|
||||||
@@ -52,9 +53,12 @@ export const Tweet = (tweet) => {
|
|||||||
const classes = useStyles();
|
const classes = useStyles();
|
||||||
const { t } = useTranslation();
|
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 = () => (
|
const Message = () => (
|
||||||
<>
|
<>
|
||||||
<div>{message}</div>
|
<div dangerouslySetInnerHTML={{ __html: formattedMessage }} />
|
||||||
<ImageDisplay visible images={images} small />
|
<ImageDisplay visible images={images} small />
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
@@ -83,15 +87,11 @@ export const Tweet = (tweet) => {
|
|||||||
<div className={classes.content}>
|
<div className={classes.content}>
|
||||||
<ListItemText primary={<Primary />} secondary={<Message />} />
|
<ListItemText primary={<Primary />} secondary={<Message />} />
|
||||||
<div className={classes.buttonContainer}>
|
<div className={classes.buttonContainer}>
|
||||||
<Button>
|
<ReplyButton profile_name={profile_name} />
|
||||||
<ReplyIcon />
|
|
||||||
</Button>
|
|
||||||
<Button>
|
<Button>
|
||||||
<FavoriteBorderIcon />
|
<FavoriteBorderIcon />
|
||||||
</Button>
|
</Button>
|
||||||
<Button>
|
<QuoteButton message={message} />
|
||||||
<QuoteIcon />
|
|
||||||
</Button>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</ListItem>
|
</ListItem>
|
||||||
|
|||||||
@@ -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 { List } from "../../../ui/components/List";
|
||||||
import { useTweets } from "../hooks/useTweets";
|
|
||||||
import Tweet from "./Tweet";
|
import Tweet from "./Tweet";
|
||||||
|
|
||||||
const TWEETS_REFRESH_RATE = 50000000; // TODO move this to twitter config
|
export function TweetList({ tweets }) {
|
||||||
|
|
||||||
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);
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<List>
|
<List>
|
||||||
{tweets.map((tweet) => (
|
{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 { useTranslation } from "react-i18next";
|
||||||
import { makeStyles } from "@material-ui/core/styles";
|
import { makeStyles } from "@material-ui/core/styles";
|
||||||
import { TextField } from "@material-ui/core";
|
import { TextField } from "@material-ui/core";
|
||||||
@@ -20,6 +20,7 @@ const useStyles = makeStyles((theme) => ({
|
|||||||
export const TweetMessage = ({ message, handleChange }) => {
|
export const TweetMessage = ({ message, handleChange }) => {
|
||||||
const classes = useStyles();
|
const classes = useStyles();
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<TextField
|
<TextField
|
||||||
value={message}
|
value={message}
|
||||||
@@ -28,6 +29,7 @@ export const TweetMessage = ({ message, handleChange }) => {
|
|||||||
onChange={handleChange}
|
onChange={handleChange}
|
||||||
multiline
|
multiline
|
||||||
placeholder={t("APPS_TWITTER_PLACEHOLDER")}
|
placeholder={t("APPS_TWITTER_PLACEHOLDER")}
|
||||||
|
inputRef={(input) => input && input.focus()}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
import React, { useState, useEffect } from "react";
|
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 Nui from "../../../os/nui-events/utils/Nui";
|
||||||
import { AppWrapper } from "../../../ui/components";
|
import { AppWrapper } from "../../../ui/components";
|
||||||
import { AppContent } from "../../../ui/components/AppContent";
|
import { AppContent } from "../../../ui/components/AppContent";
|
||||||
import TweetList from "./TweetList";
|
import TweetListContainer from "./TweetListContainer";
|
||||||
import AddTweetModal from "./AddTweetModal";
|
import AddTweetModal from "./AddTweetModal";
|
||||||
import { AppLoader } from "../../../ui/components/AppLoader";
|
import { AppLoader } from "../../../ui/components/AppLoader";
|
||||||
import TweetButton from "./TweetButton";
|
import TweetButton from "./TweetButton";
|
||||||
@@ -14,18 +14,33 @@ import TwitterProfile from "./profile/TwitterProfile";
|
|||||||
import { useProfile } from "../hooks/useProfile";
|
import { useProfile } from "../hooks/useProfile";
|
||||||
|
|
||||||
import "./twitter.css";
|
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
|
// TODO move this to the router so the application back button works
|
||||||
const PAGE_COMPONENT_MAPPING = {
|
const PAGE_COMPONENT_MAPPING = {
|
||||||
0: <TweetList />,
|
0: <TweetListContainer />,
|
||||||
1: <TweetList />,
|
1: <TweetListContainer />,
|
||||||
2: <TwitterProfile />,
|
2: <TwitterProfile />,
|
||||||
};
|
};
|
||||||
const MINIMUM_LOAD_TIME = 750;
|
const MINIMUM_LOAD_TIME = 750;
|
||||||
|
|
||||||
export const TwitterApp = () => {
|
export const TwitterApp = () => {
|
||||||
|
const classes = useStyles();
|
||||||
|
const { modalVisible, setModalVisible } = useModal();
|
||||||
const [minimumLoadPassed, setMimimumLoadPassed] = useState(false);
|
const [minimumLoadPassed, setMimimumLoadPassed] = useState(false);
|
||||||
const [modalVisible, setModalVisible] = useState(false);
|
|
||||||
const [activePage, setActivePage] = useState(0);
|
const [activePage, setActivePage] = useState(0);
|
||||||
const { profile } = useProfile();
|
const { profile } = useProfile();
|
||||||
|
|
||||||
@@ -57,11 +72,10 @@ export const TwitterApp = () => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<AppWrapper id="twitter-app">
|
<AppWrapper id="twitter-app">
|
||||||
|
<AddTweetModal />
|
||||||
|
<div className={modalVisible ? classes.backgroundModal : null} />
|
||||||
<TwitterTitle />
|
<TwitterTitle />
|
||||||
<AppContent>
|
<AppContent>{component}</AppContent>
|
||||||
<AddTweetModal visible={modalVisible} handleClose={hideModal} />
|
|
||||||
{component}
|
|
||||||
</AppContent>
|
|
||||||
{showTweetButton && <TweetButton openModal={openModal} />}
|
{showTweetButton && <TweetButton openModal={openModal} />}
|
||||||
<BottomNavigation
|
<BottomNavigation
|
||||||
activePage={activePage}
|
activePage={activePage}
|
||||||
|
|||||||
@@ -1,6 +1,11 @@
|
|||||||
/* 00acee is "twitter blue" and we want to use that to override
|
/* 00acee is "twitter blue" and we want to use that to override
|
||||||
some of the Material UI primary theme settings */
|
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 */
|
/* override the bottom navigation active color */
|
||||||
#twitter-app .Mui-selected {
|
#twitter-app .Mui-selected {
|
||||||
color: #00acee !important;
|
color: #00acee !important;
|
||||||
|
|||||||
@@ -9,6 +9,14 @@ export const twitterState = {
|
|||||||
key: "tweets",
|
key: "tweets",
|
||||||
default: [],
|
default: [],
|
||||||
}),
|
}),
|
||||||
|
showCreateTweetModal: atom({
|
||||||
|
key: "showCreateTweetModal",
|
||||||
|
default: false,
|
||||||
|
}),
|
||||||
|
modalMessage: atom({
|
||||||
|
key: "modalMessage",
|
||||||
|
default: "",
|
||||||
|
}),
|
||||||
createTweetLoading: atom({
|
createTweetLoading: atom({
|
||||||
key: "createTweetLoading",
|
key: "createTweetLoading",
|
||||||
default: false,
|
default: false,
|
||||||
|
|||||||
@@ -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 };
|
||||||
|
};
|
||||||
Reference in new issue
Block a user