mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-04 14:38:45 +00:00
working profile creation and deletion, app loader
This commit is contained in:
1 parent
a01993e178
commit
5072a31aab
10 files changed
+171
-18
No files matched your search
@@ -1,12 +1,15 @@
|
||||
import React, { useState, useCallback } from "react";
|
||||
import React, { useState, useCallback, useEffect } from "react";
|
||||
import { blue } from "@material-ui/core/colors";
|
||||
import { makeStyles, Button } from "@material-ui/core";
|
||||
import AddCircleIcon from "@material-ui/icons/AddCircle";
|
||||
|
||||
import Nui from "../../../os/nui-events/utils/Nui";
|
||||
import { AppTitle } from "../../../ui/components/AppTitle";
|
||||
import { AppWrapper } from "../../../ui/components";
|
||||
import { AppContent } from "../../../ui/components/AppContent";
|
||||
import { AppLoader } from "../../../ui/components/AppLoader";
|
||||
import { useApp } from "../../../os/apps/hooks/useApps";
|
||||
|
||||
import { useProfile } from "../hooks/useProfile";
|
||||
import TweetList from "./TweetList";
|
||||
import AddTweetModal from "./AddTweetModal";
|
||||
|
||||
@@ -25,13 +28,33 @@ const useStyles = makeStyles((theme) => ({
|
||||
},
|
||||
}));
|
||||
|
||||
const MINIMUM_LOAD_TIME = 750;
|
||||
|
||||
export const TwitterApp = () => {
|
||||
const [modalVisible, setModalVisible] = useState(false);
|
||||
const [minimumLoadPassed, setMimimumLoadPassed] = useState(false);
|
||||
const classes = useStyles();
|
||||
const twitter = useApp("TWITTER");
|
||||
const { profile } = useProfile();
|
||||
|
||||
const openModal = useCallback(() => setModalVisible(true), []);
|
||||
const hideModal = useCallback(() => setModalVisible(false), []);
|
||||
useEffect(() => {
|
||||
Nui.send("phone:getOrCreateTwitterProfile", {});
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
const timeout = window.setTimeout(() => {
|
||||
setMimimumLoadPassed(true);
|
||||
}, MINIMUM_LOAD_TIME);
|
||||
return () => window.clearTimeout(timeout);
|
||||
});
|
||||
|
||||
const openModal = () => setModalVisible(true);
|
||||
const hideModal = () => setModalVisible(false);
|
||||
|
||||
// we add a minimum (but short) load time here so that
|
||||
// there isn't a quick flash of loading and immediately
|
||||
// another flash to the tweets screen.
|
||||
const hasLoaded = profile && minimumLoadPassed;
|
||||
|
||||
return (
|
||||
<AppWrapper>
|
||||
@@ -44,8 +67,14 @@ export const TwitterApp = () => {
|
||||
<AddCircleIcon color="action" />
|
||||
</Button>
|
||||
<AppContent>
|
||||
<AddTweetModal visible={modalVisible} handleClose={hideModal} />
|
||||
<TweetList />
|
||||
{hasLoaded ? (
|
||||
<>
|
||||
<AddTweetModal visible={modalVisible} handleClose={hideModal} />
|
||||
<TweetList />
|
||||
</>
|
||||
) : (
|
||||
<AppLoader />
|
||||
)}
|
||||
</AppContent>
|
||||
</AppWrapper>
|
||||
);
|
||||
|
||||
Reference in new issue
Block a user