working app loader

This commit is contained in:
erik-sn committed 2020-09-27 00:55:25 -04:00
1 parent fb6ce054fc
commit c414116b49
5 files changed
+72 -32

No files matched your search

+13 -2
View File
@@ -30,8 +30,16 @@ const useStyles = makeStyles(() => ({
flexFlow: "column nowrap", flexFlow: "column nowrap",
width: "100%", width: "100%",
}, },
profile: {
fontSize: "24px",
fontWeight: "bold",
},
date: { date: {
marginLeft: "10px", marginLeft: "10px",
fontSize: "16px",
},
message: {
fontSize: "22px",
}, },
buttonContainer: { buttonContainer: {
display: "flex", display: "flex",
@@ -58,14 +66,17 @@ export const Tweet = (tweet) => {
const formattedMessage = message.replace(/\n\r?/g, "<br />"); const formattedMessage = message.replace(/\n\r?/g, "<br />");
const Message = () => ( const Message = () => (
<> <>
<div dangerouslySetInnerHTML={{ __html: formattedMessage }} /> <div
className={classes.message}
dangerouslySetInnerHTML={{ __html: formattedMessage }}
/>
<ImageDisplay visible images={images} small /> <ImageDisplay visible images={images} small />
</> </>
); );
const Primary = () => ( const Primary = () => (
<> <>
<strong>{`@${profile_name}`}</strong> <span className={classes.profile}>{`@${profile_name}`}</span>
<Typography <Typography
className={classes.date} className={classes.date}
component="span" component="span"
@@ -1,31 +1,10 @@
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 { useTweets } from "../hooks/useTweets";
import TweetList from "./TweetList"; import TweetList from "./TweetList";
const TWEETS_REFRESH_RATE = 50000000; // TODO move this to twitter config
export function TweetListContainer() { export function TweetListContainer() {
const { tweets } = useTweets(); 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} />; return <TweetList tweets={tweets} />;
} }
@@ -14,9 +14,11 @@ import TwitterTitle from "./TwitterTitle";
import BottomNavigation from "./BottomNavigation"; import BottomNavigation from "./BottomNavigation";
import TwitterProfile from "./profile/TwitterProfile"; import TwitterProfile from "./profile/TwitterProfile";
import AlertBar from "./alerts/AlertBar"; import AlertBar from "./alerts/AlertBar";
import TwitterLoader from "./TwitterLoader";
import "./twitter.css"; import "./twitter.css";
import "emoji-mart/css/emoji-mart.css"; import "emoji-mart/css/emoji-mart.css";
import { useTweets } from "../hooks/useTweets";
const useStyles = makeStyles((theme) => ({ const useStyles = makeStyles((theme) => ({
backgroundModal: { backgroundModal: {
@@ -38,6 +40,7 @@ const PAGE_COMPONENT_MAPPING = {
2: <TwitterProfile />, 2: <TwitterProfile />,
}; };
const MINIMUM_LOAD_TIME = 750; const MINIMUM_LOAD_TIME = 750;
const TWEETS_REFRESH_RATE = 50000000; // TODO move this to twitter config
export const TwitterApp = () => { export const TwitterApp = () => {
const classes = useStyles(); const classes = useStyles();
@@ -45,9 +48,23 @@ export const TwitterApp = () => {
const [minimumLoadPassed, setMimimumLoadPassed] = useState(false); const [minimumLoadPassed, setMimimumLoadPassed] = useState(false);
const [activePage, setActivePage] = useState(0); const [activePage, setActivePage] = useState(0);
const { profile } = useProfile(); const { profile } = useProfile();
const { tweets } = useTweets();
useEffect(() => { useEffect(() => {
Nui.send("phone:getOrCreateTwitterProfile", {}); Nui.send("phone:getOrCreateTwitterProfile", {});
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);
}, []); }, []);
useEffect(() => { useEffect(() => {
@@ -63,20 +80,17 @@ export const TwitterApp = () => {
// we add a minimum (but short) load time here so that // we add a minimum (but short) load time here so that
// there isn't a quick flash of loading and immediately // there isn't a quick flash of loading and immediately
// another flash to the tweets screen. // another flash to the tweets screen.
const hasLoaded = profile && minimumLoadPassed; const hasLoaded = tweets && profile && minimumLoadPassed;
const showTweetButton = hasLoaded && activePage === 0; const showTweetButton = hasLoaded && activePage === 0;
const component = hasLoaded ? (
PAGE_COMPONENT_MAPPING[activePage] if (!hasLoaded) return <TwitterLoader />;
) : (
<AppLoader />
);
return ( return (
<AppWrapper id="twitter-app"> <AppWrapper id="twitter-app">
<AddTweetModal /> <AddTweetModal />
<div className={modalVisible ? classes.backgroundModal : null} /> <div className={modalVisible ? classes.backgroundModal : null} />
<TwitterTitle /> <TwitterTitle />
<AppContent>{component}</AppContent> <AppContent>{PAGE_COMPONENT_MAPPING[activePage]}</AppContent>
{showTweetButton && <TweetButton openModal={openModal} />} {showTweetButton && <TweetButton openModal={openModal} />}
<AlertBar /> <AlertBar />
<BottomNavigation <BottomNavigation
@@ -0,0 +1,36 @@
// intended for use on initial application loads
import React from "react";
import { makeStyles } from "@material-ui/core";
import TwitterIcon from "@material-ui/icons/Twitter";
import { AppWrapper } from "../../../ui/components";
import { AppContent } from "../../../ui/components/AppContent";
const useStyles = makeStyles((theme) => ({
root: {
height: "100%",
width: "100%",
display: "flex",
flexFlow: "row nowrap",
justifyContent: "center",
alignItems: "center",
},
icon: {
color: "#00acee",
fontSize: "100px",
},
}));
export const TwitterLoader = () => {
const classes = useStyles();
return (
<AppWrapper id="twitter-app">
<AppContent>
<div className={classes.root}>
<TwitterIcon className={classes.icon} />
</div>
</AppContent>
</AppWrapper>
);
};
export default TwitterLoader;
+1 -1
View File
@@ -7,7 +7,7 @@ export const twitterState = {
}), }),
tweets: atom({ tweets: atom({
key: "tweets", key: "tweets",
default: [], default: null,
}), }),
showCreateTweetModal: atom({ showCreateTweetModal: atom({
key: "showCreateTweetModal", key: "showCreateTweetModal",