reorganization

This commit is contained in:
erik-sn committed 2020-10-03 10:50:13 -04:00
1 parent 11977c48ef
commit 2a6429c446
24 files changed
+43 -85

No files matched your search

@@ -0,0 +1,117 @@
import React from "react";
import { useTranslation } from "react-i18next";
import { makeStyles } from "@material-ui/core/styles";
import {
ListItemAvatar,
Avatar as MuiAvatar,
Button,
Typography,
} from "@material-ui/core";
import FavoriteBorderIcon from "@material-ui/icons/FavoriteBorder";
import MoreIcon from "@material-ui/icons/MoreVert";
import { ListItem } from "../../../../ui/components/ListItem";
import { secondsToHumanReadable } from "../../utils/time";
import ReplyButton from "../buttons/ReplyButton";
import ImageDisplay from "../images/ImageDisplay";
import Avatar from "../Avatar";
import { QuoteButton } from "../buttons/QuoteButton";
const useStyles = makeStyles(() => ({
root: {
overflowX: "hidden",
display: "flex",
flexFlow: "row nowrap",
alignItems: "flex-start",
width: "100%",
marginTop: "3px",
},
content: {
display: "flex",
marginTop: "-10px", // easier to do this here than override the MUI styles
flexFlow: "column nowrap",
width: "100%",
},
primary: {
display: "flex",
flexFlow: "row nowrap",
width: "100%",
alignItems: "flex-end",
},
profile: {
fontSize: "18px",
fontWeight: "bold",
},
date: {
marginLeft: "10px",
fontSize: "14px",
},
message: {
fontSize: "18px",
color: "rgba(255, 255, 255, 0.7)",
},
buttonContainer: {
display: "flex",
flexFlow: "row nowrap",
justifyContent: "space-between",
width: "100%",
marginLeft: "-20px", // easier to do this here than override the MUI styles
marginTop: "3px",
},
}));
export const Tweet = (tweet) => {
const {
message,
images,
avatar_url,
profile_name,
seconds_since_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 />");
return (
<ListItem className={classes.root} divider>
<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>
<Typography
className={classes.date}
component="div"
variant="body2"
color="textSecondary"
>
{secondsToHumanReadable(t, seconds_since_tweet)}
</Typography>
</div>
<div
className={classes.message}
dangerouslySetInnerHTML={{ __html: formattedMessage }}
/>
<ImageDisplay visible images={images} small />
<div className={classes.buttonContainer}>
<ReplyButton profile_name={profile_name} />
<Button>
<FavoriteBorderIcon />
</Button>
<QuoteButton message={message} />
<Button>
<MoreIcon />
</Button>
</div>
</div>
</ListItem>
);
};
export default Tweet;
@@ -0,0 +1,18 @@
import React from "react";
import { List } from "../../../../ui/components/List";
import Tweet from "./Tweet";
import TweetSkeletonList from "./TweetSkeletonList";
export function TweetList({ tweets }) {
if (!tweets) return <TweetSkeletonList />;
return (
<List>
{tweets.map((tweet) => (
<Tweet key={tweet.id} {...tweet} />
))}
</List>
);
}
export default TweetList;
@@ -0,0 +1,11 @@
import React from "react";
import { useTweets } from "../../hooks/useTweets";
import TweetList from "./TweetList";
export function TweetListContainer() {
const { tweets } = useTweets();
return <TweetList tweets={tweets} />;
}
export default TweetListContainer;
@@ -0,0 +1,37 @@
import React, { useEffect, useRef } from "react";
import { useTranslation } from "react-i18next";
import { makeStyles } from "@material-ui/core/styles";
import { TextField } from "@material-ui/core";
const useStyles = makeStyles((theme) => ({
textField: {
flex: "1 1 100%",
padding: "10px 15px",
marginTop: "15px",
},
textFieldInput: {
fontSize: "22px",
},
display: {
height: "200px",
},
}));
export const TweetMessage = ({ message, handleChange }) => {
const classes = useStyles();
const { t } = useTranslation();
return (
<TextField
value={message}
inputProps={{ className: classes.textFieldInput }}
className={classes.textField}
onChange={handleChange}
multiline
placeholder={t("APPS_TWITTER_TWEET_MESSAGE_PLACEHOLDER")}
inputRef={(input) => input && input.focus()}
/>
);
};
export default TweetMessage;
@@ -0,0 +1,39 @@
import React from "react";
import Divider from "@material-ui/core/Divider";
import { makeStyles } from "@material-ui/core/styles";
import Skeleton from "@material-ui/lab/Skeleton";
const useStyles = makeStyles({
root: {
width: "100%",
padding: "15px",
display: "flex",
flexFlow: "row nowrap",
marginTop: "3px",
marginBottom: "3px",
},
left: {},
right: {
marginLeft: "15px",
marginTop: "-5px",
},
});
export default function TweetSkeleton() {
const classes = useStyles();
return (
<>
<div className={classes.root}>
<div className={classes.left}>
<Skeleton variant="circle" width={60} height={60} />
</div>
<div className={classes.right}>
<Skeleton variant="text" />
<Skeleton variant="rect" width={250} height={118} />
</div>
</div>
<Divider />
</>
);
}
@@ -0,0 +1,23 @@
import React from "react";
import { List } from "../../../../ui/components/List";
import TweetSkeleton from "./TweetSkeleton";
export function TweetSkeletonList() {
return (
<List>
<TweetSkeleton />
<TweetSkeleton />
<TweetSkeleton />
<TweetSkeleton />
<TweetSkeleton />
<TweetSkeleton />
<TweetSkeleton />
<TweetSkeleton />
<TweetSkeleton />
<TweetSkeleton />
</List>
);
}
export default TweetSkeletonList;