mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-04 14:38:45 +00:00
implemented twitter configuration parameters
This commit is contained in:
1 parent
345f591670
commit
7d287ccd08
18 files changed
+144
-37
No files matched your search
@@ -15,6 +15,7 @@ import ImagePrompt from "./images/ImagePrompt";
|
||||
import TweetMessage from "./tweet/TweetMessage";
|
||||
import ControlButtons from "./buttons/ControlButtons";
|
||||
import IconButtons from "./buttons/IconButtons";
|
||||
import { usePhone } from "../../../os/phone/hooks/usePhone";
|
||||
|
||||
const useStyles = makeStyles((theme) => ({
|
||||
root: {
|
||||
@@ -54,6 +55,7 @@ const useStyles = makeStyles((theme) => ({
|
||||
export const AddTweetModal = () => {
|
||||
const classes = useStyles();
|
||||
const { message, setMessage, modalVisible, setModalVisible } = useModal();
|
||||
const { config } = usePhone();
|
||||
|
||||
const [showEmoji, setShowEmoji] = useState(false);
|
||||
const [showImagePrompt, setShowImagePrompt] = useState(false);
|
||||
@@ -89,7 +91,9 @@ export const AddTweetModal = () => {
|
||||
}, []);
|
||||
|
||||
const submitTweet = () => {
|
||||
if (message.trim().length === 0) return;
|
||||
const cleanedMessage = message.trim();
|
||||
if (cleanedMessage.length === 0) return;
|
||||
if (cleanedMessage.length > config.twitter.characterLimit) return;
|
||||
|
||||
const data = {
|
||||
message,
|
||||
@@ -123,7 +127,7 @@ export const AddTweetModal = () => {
|
||||
withValidImage(cleanedLink, () => setImages([...images, image]));
|
||||
|
||||
setShowImagePrompt(false);
|
||||
setImages([]);
|
||||
setLink('')
|
||||
};
|
||||
const removeImage = (id) =>
|
||||
setImages(images.filter((image) => id !== image.id));
|
||||
@@ -146,6 +150,8 @@ export const AddTweetModal = () => {
|
||||
setMessage(message.concat(emojiObject.native));
|
||||
};
|
||||
|
||||
if (!config) return null;
|
||||
|
||||
return (
|
||||
<Modal visible={modalVisible} handleClose={_handleClose}>
|
||||
<Button className={classes.close} onClick={_handleClose}>
|
||||
@@ -165,7 +171,7 @@ export const AddTweetModal = () => {
|
||||
/>
|
||||
<div className={classes.buttonsContainer}>
|
||||
<IconButtons
|
||||
onImageClick={toggleShowImagePrompt}
|
||||
onImageClick={images.length < config.twitter.maxImages ? toggleShowImagePrompt : null}
|
||||
onEmojiClick={toggleShowEmoji}
|
||||
/>
|
||||
<ControlButtons
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import React, { useState } from "react";
|
||||
import { makeStyles } from "@material-ui/core/styles";
|
||||
|
||||
import { usePhone } from "../../../os/phone/hooks/usePhone";
|
||||
import { IMG_DEFAULT_AVATAR, IMG_INVALID_AVATAR } from "../utils/constants";
|
||||
|
||||
const useStyles = makeStyles({
|
||||
@@ -16,10 +17,13 @@ const useStyles = makeStyles({
|
||||
function Avatar({ avatarUrl, showInvalidImage, height, width }) {
|
||||
const classes = useStyles();
|
||||
const [showImageError, setShowImageError] = useState(false);
|
||||
const { config } = usePhone();
|
||||
|
||||
const handleImageError = () => setShowImageError(true);
|
||||
const handleImageLoad = () => setShowImageError(false);
|
||||
|
||||
if (!config || !config.twitter.enableAvatars) return null;
|
||||
|
||||
return (
|
||||
<div className={classes.root}>
|
||||
{showImageError && (
|
||||
|
||||
@@ -8,7 +8,6 @@ import { AppContent } from "../../../ui/components/AppContent";
|
||||
import TweetListContainer from "./tweet/TweetListContainer";
|
||||
import AddTweetModal from "./AddTweetModal";
|
||||
import { useModal } from "../hooks/useModal";
|
||||
import { useProfile } from "../hooks/useProfile";
|
||||
import TweetButton from "./buttons/TweetButton";
|
||||
import TwitterTitle from "./TwitterTitle";
|
||||
import BottomNavigation from "./BottomNavigation";
|
||||
@@ -19,7 +18,7 @@ import TwitterSearch from "./TwitterSearch";
|
||||
import "./twitter.css";
|
||||
import "emoji-mart/css/emoji-mart.css";
|
||||
|
||||
const useStyles = makeStyles((theme) => ({
|
||||
const useStyles = makeStyles(() => ({
|
||||
backgroundModal: {
|
||||
background: "black",
|
||||
opacity: "0.6",
|
||||
|
||||
@@ -3,8 +3,6 @@ import { useTranslation } from "react-i18next";
|
||||
import { makeStyles } from "@material-ui/core/styles";
|
||||
import { Button } from "@material-ui/core";
|
||||
|
||||
import { useTweetStatus } from "../../hooks/useTweetStatus";
|
||||
|
||||
const useStyles = makeStyles((theme) => ({
|
||||
buttons: {
|
||||
display: "flex",
|
||||
@@ -24,8 +22,6 @@ export const ControlButtons = ({
|
||||
onCloseClick,
|
||||
onPrimaryClick,
|
||||
}) => {
|
||||
const { createTweetLoading } = useTweetStatus();
|
||||
|
||||
const classes = useStyles();
|
||||
const { t } = useTranslation();
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ import { makeStyles } from "@material-ui/core/styles";
|
||||
import { Button } from "@material-ui/core";
|
||||
import InsertPhotoIcon from "@material-ui/icons/InsertPhoto";
|
||||
import EmojiIcon from "@material-ui/icons/SentimentSatisfied";
|
||||
import { usePhone } from "../../../../os/phone/hooks/usePhone";
|
||||
|
||||
const useStyles = makeStyles((theme) => ({
|
||||
buttons: {
|
||||
@@ -19,14 +20,19 @@ const useStyles = makeStyles((theme) => ({
|
||||
|
||||
export const IconButtons = ({ onImageClick, onEmojiClick }) => {
|
||||
const classes = useStyles();
|
||||
const { config } = usePhone();
|
||||
|
||||
if (!config) return null;
|
||||
const { enableImages, enableEmojis } = config.twitter;
|
||||
|
||||
return (
|
||||
<div className={classes.buttons}>
|
||||
<Button className={classes.button} onClick={onImageClick}>
|
||||
{enableImages && (<Button className={classes.button} onClick={onImageClick}>
|
||||
<InsertPhotoIcon color="action" />
|
||||
</Button>
|
||||
<Button className={classes.button} onClick={onEmojiClick}>
|
||||
</Button>)}
|
||||
{enableEmojis && (<Button className={classes.button} onClick={onEmojiClick}>
|
||||
<EmojiIcon color="action" />
|
||||
</Button>
|
||||
</Button>)}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -7,6 +7,7 @@ import { useProfile } from "../../hooks/useProfile";
|
||||
import Avatar from "../Avatar";
|
||||
import ProfileField from "./ProfileField";
|
||||
import ProfileUpdateButton from "../buttons/ProfileUpdateButton";
|
||||
import { usePhone } from "../../../../os/phone/hooks/usePhone";
|
||||
|
||||
const useStyles = makeStyles((theme) => ({
|
||||
root: {
|
||||
@@ -24,6 +25,8 @@ export function Profile() {
|
||||
const classes = useStyles();
|
||||
const { t } = useTranslation();
|
||||
const { profile } = useProfile();
|
||||
const { config } = usePhone();
|
||||
|
||||
|
||||
// note that this assumes we are defensively checking
|
||||
// that profile is not null in a parent above this component.
|
||||
@@ -47,19 +50,26 @@ export function Profile() {
|
||||
Nui.send("phone:updateTwitterProfile", data);
|
||||
};
|
||||
|
||||
// fetching the config is an asynchronous call so defend against it
|
||||
if (!config) return null;
|
||||
|
||||
const { enableAvatars, allowEdtiableProfileName } = config.twitter;
|
||||
|
||||
return (
|
||||
<div className={classes.root}>
|
||||
<Avatar avatarUrl={avatarUrl} showInvalidImage />
|
||||
{enableAvatars && <Avatar avatarUrl={avatarUrl} showInvalidImage />}
|
||||
<div className={classes.spacer} />
|
||||
<ProfileField
|
||||
label={t("APPS_TWITTER_EDIT_PROFILE_AVATAR")}
|
||||
value={avatarUrl}
|
||||
handleChange={handleAvatarChange}
|
||||
allowChange={enableAvatars}
|
||||
/>
|
||||
<ProfileField
|
||||
label={t("APPS_TWITTER_EDIT_PROFILE_NAME")}
|
||||
value={name}
|
||||
handleChange={handleNameChange}
|
||||
allowChange={allowEdtiableProfileName}
|
||||
/>
|
||||
<ProfileField
|
||||
label={t("APPS_TWITTER_EDIT_PROFILE_BIO")}
|
||||
|
||||
@@ -16,6 +16,7 @@ import ReplyButton from "../buttons/ReplyButton";
|
||||
import ImageDisplay from "../images/ImageDisplay";
|
||||
import Avatar from "../Avatar";
|
||||
import { QuoteButton } from "../buttons/QuoteButton";
|
||||
import { usePhone } from "../../../../os/phone/hooks/usePhone";
|
||||
|
||||
const useStyles = makeStyles(() => ({
|
||||
root: {
|
||||
@@ -70,6 +71,12 @@ export const Tweet = (tweet) => {
|
||||
} = tweet;
|
||||
const classes = useStyles();
|
||||
const { t } = useTranslation();
|
||||
const { config } = usePhone();
|
||||
|
||||
console.log(config);
|
||||
|
||||
if (!config) return null;
|
||||
const { enableAvatars, enableImages } = config.twitter;
|
||||
|
||||
// this is a workaround to transfer string new lines and returns that
|
||||
// are stored into the database into html for the UI to render
|
||||
@@ -77,11 +84,13 @@ export const Tweet = (tweet) => {
|
||||
|
||||
return (
|
||||
<ListItem className={classes.root} divider>
|
||||
<ListItemAvatar>
|
||||
<MuiAvatar>
|
||||
<Avatar avatarUrl={avatar_url} height="45px" width="45px" />
|
||||
</MuiAvatar>
|
||||
</ListItemAvatar>
|
||||
{enableAvatars && (
|
||||
<ListItemAvatar>
|
||||
<MuiAvatar>
|
||||
<Avatar avatarUrl={avatar_url} height="45px" width="45px" />
|
||||
</MuiAvatar>
|
||||
</ListItemAvatar>
|
||||
)}
|
||||
<div className={classes.content}>
|
||||
<div className={classes.primary}>
|
||||
<div className={classes.profile}>{`@${profile_name}`}</div>
|
||||
@@ -98,7 +107,7 @@ export const Tweet = (tweet) => {
|
||||
className={classes.message}
|
||||
dangerouslySetInnerHTML={{ __html: formattedMessage }}
|
||||
/>
|
||||
<ImageDisplay visible images={images} small />
|
||||
{enableImages && <ImageDisplay visible images={images} small />}
|
||||
<div className={classes.buttonContainer}>
|
||||
<ReplyButton profile_name={profile_name} />
|
||||
<Button>
|
||||
|
||||
@@ -2,6 +2,7 @@ import React, { useEffect, useRef } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { makeStyles } from "@material-ui/core/styles";
|
||||
import { TextField } from "@material-ui/core";
|
||||
import { usePhone } from "../../../../os/phone/hooks/usePhone";
|
||||
|
||||
const useStyles = makeStyles((theme) => ({
|
||||
textField: {
|
||||
@@ -19,8 +20,12 @@ const useStyles = makeStyles((theme) => ({
|
||||
|
||||
export const TweetMessage = ({ message, handleChange }) => {
|
||||
const classes = useStyles();
|
||||
const { config } = usePhone();
|
||||
const { t } = useTranslation();
|
||||
|
||||
const overCharacterLimit = message.trim().length > config.twitter.characterLimit;
|
||||
const characterWarningPrompt = `${t("APPS_TWITTER_TWEET_MESSAGE_CHAR_LIMIT")} (${config.twitter.characterLimit})`;
|
||||
|
||||
return (
|
||||
<TextField
|
||||
value={message}
|
||||
@@ -30,6 +35,8 @@ export const TweetMessage = ({ message, handleChange }) => {
|
||||
multiline
|
||||
placeholder={t("APPS_TWITTER_TWEET_MESSAGE_PLACEHOLDER")}
|
||||
inputRef={(input) => input && input.focus()}
|
||||
error={overCharacterLimit}
|
||||
helperText={overCharacterLimit ? characterWarningPrompt : null}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user