mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-04 22:16:40 +00:00
working profile and editing of profile
This commit is contained in:
1 parent
5072a31aab
commit
9fe4cf0188
27 files changed
+458
-50
No files matched your search
+2
-1
@@ -27,5 +27,6 @@ files {
|
|||||||
'resources/html/*.js',
|
'resources/html/*.js',
|
||||||
'resources/html/media/frames/*.png',
|
'resources/html/media/frames/*.png',
|
||||||
'resources/html/media/backgrounds/*.png',
|
'resources/html/media/backgrounds/*.png',
|
||||||
'resources/html/media/backgrounds/*.jpg'
|
'resources/html/media/backgrounds/*.jpg',
|
||||||
|
'resources/html/media/twitter/*'
|
||||||
}
|
}
|
||||||
Vendored
+3
@@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"editor.formatOnSave": true
|
||||||
|
}
|
||||||
+2
-1
@@ -18,6 +18,7 @@ import { useApps } from "./os/apps/hooks/useApps";
|
|||||||
|
|
||||||
import { useContactsService } from "./apps/contacts/hooks/useContactsService";
|
import { useContactsService } from "./apps/contacts/hooks/useContactsService";
|
||||||
import { useTwitterService } from "./apps/twitter/hooks/useTwitterService";
|
import { useTwitterService } from "./apps/twitter/hooks/useTwitterService";
|
||||||
|
import { TwitterApp } from "./apps/twitter/components/TwitterApp";
|
||||||
|
|
||||||
// These events are just for testing. Comment it out before building.
|
// These events are just for testing. Comment it out before building.
|
||||||
//setTimeout(() => {
|
//setTimeout(() => {
|
||||||
@@ -109,7 +110,7 @@ function Phone() {
|
|||||||
]}
|
]}
|
||||||
/>
|
/>
|
||||||
<div className="PhoneAppContainer">
|
<div className="PhoneAppContainer">
|
||||||
<Route exact path="/" component={HomeApp} />
|
<Route exact path="/" component={TwitterApp} />
|
||||||
{allApps.map((App) => (
|
{allApps.map((App) => (
|
||||||
<App.Route key={App.id} />
|
<App.Route key={App.id} />
|
||||||
))}
|
))}
|
||||||
|
|||||||
@@ -0,0 +1,58 @@
|
|||||||
|
import React, { useState } from "react";
|
||||||
|
import { makeStyles } from "@material-ui/core/styles";
|
||||||
|
|
||||||
|
import { IMG_DEFAULT_AVATAR, IMG_INVALID_AVATAR } from "../utils/constants";
|
||||||
|
|
||||||
|
const useStyles = makeStyles({
|
||||||
|
root: {
|
||||||
|
width: "100%",
|
||||||
|
},
|
||||||
|
imgContainer: {},
|
||||||
|
button: {
|
||||||
|
background: "none",
|
||||||
|
border: "none",
|
||||||
|
},
|
||||||
|
img: {
|
||||||
|
height: "125px",
|
||||||
|
width: "125px",
|
||||||
|
borderRadius: "50%",
|
||||||
|
objectFit: "cover",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
function Avatar({ avatarUrl, showInvalidImage }) {
|
||||||
|
const classes = useStyles();
|
||||||
|
const [showImageError, setShowImageError] = useState(false);
|
||||||
|
|
||||||
|
const handleImageError = () => setShowImageError(true);
|
||||||
|
const handleImageLoad = () => setShowImageError(false);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className={classes.root}>
|
||||||
|
<div className={classes.imgContainer}>
|
||||||
|
{showImageError && (
|
||||||
|
<img
|
||||||
|
className={classes.img}
|
||||||
|
src={showInvalidImage ? IMG_INVALID_AVATAR : IMG_DEFAULT_AVATAR}
|
||||||
|
alt="Invalid avatar image"
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
<img
|
||||||
|
className={classes.img}
|
||||||
|
src={avatarUrl || IMG_DEFAULT_AVATAR}
|
||||||
|
alt="Your profile avatar"
|
||||||
|
onError={handleImageError}
|
||||||
|
onLoad={handleImageLoad}
|
||||||
|
style={{ display: showImageError ? "none" : "block" }}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Avatar.defaultProps = {
|
||||||
|
avatarUrl: null,
|
||||||
|
showInvalidImage: false,
|
||||||
|
};
|
||||||
|
|
||||||
|
export default Avatar;
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
import React from "react";
|
||||||
|
import { makeStyles } from "@material-ui/core/styles";
|
||||||
|
import BottomNavigation from "@material-ui/core/BottomNavigation";
|
||||||
|
import BottomNavigationAction from "@material-ui/core/BottomNavigationAction";
|
||||||
|
import HomeIcon from "@material-ui/icons/Home";
|
||||||
|
import SearchIcon from "@material-ui/icons/Search";
|
||||||
|
import ProfileIcon from "@material-ui/icons/Person";
|
||||||
|
|
||||||
|
const useStyles = makeStyles({
|
||||||
|
root: {
|
||||||
|
width: "100%",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
export function TwitterBottomNavigation({ activePage, handleChange }) {
|
||||||
|
const classes = useStyles();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<BottomNavigation
|
||||||
|
value={activePage}
|
||||||
|
onChange={handleChange}
|
||||||
|
className={classes.root}
|
||||||
|
>
|
||||||
|
<BottomNavigationAction icon={<HomeIcon />} />
|
||||||
|
<BottomNavigationAction icon={<SearchIcon />} />
|
||||||
|
<BottomNavigationAction icon={<ProfileIcon />} />
|
||||||
|
</BottomNavigation>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default TwitterBottomNavigation;
|
||||||
@@ -30,8 +30,8 @@ const useStyles = makeStyles((theme) => ({
|
|||||||
padding: "0px 3px 3px 0px",
|
padding: "0px 3px 3px 0px",
|
||||||
},
|
},
|
||||||
imgSmall: {
|
imgSmall: {
|
||||||
maxHeight: "75px", // constrain images so we don't overwhelm the UI
|
maxHeight: "200px", // constrain images so we don't overwhelm the UI
|
||||||
maxWidth: "125px",
|
maxWidth: "100%",
|
||||||
padding: "0px 1px 1px 0px",
|
padding: "0px 1px 1px 0px",
|
||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
|
|||||||
@@ -0,0 +1,29 @@
|
|||||||
|
import React from "react";
|
||||||
|
import { makeStyles } from "@material-ui/core/styles";
|
||||||
|
import Fab from "@material-ui/core/Fab";
|
||||||
|
import CreateIcon from "@material-ui/icons/Create";
|
||||||
|
|
||||||
|
const useStyles = makeStyles((theme) => ({
|
||||||
|
root: {
|
||||||
|
position: "absolute",
|
||||||
|
bottom: "75px",
|
||||||
|
right: "15px",
|
||||||
|
},
|
||||||
|
button: {
|
||||||
|
background: "#00acee",
|
||||||
|
},
|
||||||
|
}));
|
||||||
|
|
||||||
|
export function TweetButton({ openModal }) {
|
||||||
|
const classes = useStyles();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className={classes.root}>
|
||||||
|
<Fab className={classes.button} color="primary" onClick={openModal}>
|
||||||
|
<CreateIcon />
|
||||||
|
</Fab>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default TweetButton;
|
||||||
@@ -1,40 +1,31 @@
|
|||||||
import React, { useState, useCallback, useEffect } from "react";
|
import React, { useState, useEffect } from "react";
|
||||||
import { blue } from "@material-ui/core/colors";
|
import { makeStyles } from "@material-ui/core";
|
||||||
import { makeStyles, Button } from "@material-ui/core";
|
|
||||||
import AddCircleIcon from "@material-ui/icons/AddCircle";
|
|
||||||
|
|
||||||
import Nui from "../../../os/nui-events/utils/Nui";
|
import Nui from "../../../os/nui-events/utils/Nui";
|
||||||
import { AppTitle } from "../../../ui/components/AppTitle";
|
|
||||||
import { AppWrapper } from "../../../ui/components";
|
import { AppWrapper } from "../../../ui/components";
|
||||||
import { AppContent } from "../../../ui/components/AppContent";
|
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 TweetList from "./TweetList";
|
||||||
import AddTweetModal from "./AddTweetModal";
|
import AddTweetModal from "./AddTweetModal";
|
||||||
|
import { AppLoader } from "../../../ui/components/AppLoader";
|
||||||
|
import TweetButton from "./TweetButton";
|
||||||
|
import TwitterTitle from "./TwitterTitle";
|
||||||
|
import BottomNavigation from "./BottomNavigation";
|
||||||
|
import TwitterProfile from "./profile/TwitterProfile";
|
||||||
|
import { useProfile } from "../hooks/useProfile";
|
||||||
|
|
||||||
const useStyles = makeStyles((theme) => ({
|
import "./twitter.css";
|
||||||
root: {
|
|
||||||
height: "90px",
|
|
||||||
display: "flex",
|
|
||||||
justifyContent: "center",
|
|
||||||
backgroundColor: blue[600],
|
|
||||||
alignItems: "center",
|
|
||||||
},
|
|
||||||
header: {
|
|
||||||
fontFamily: "'Bebas Neue', cursive",
|
|
||||||
textAlign: "center",
|
|
||||||
fontSize: 50,
|
|
||||||
},
|
|
||||||
}));
|
|
||||||
|
|
||||||
|
const PAGE_COMPONENT_MAPPING = {
|
||||||
|
0: <TweetList />,
|
||||||
|
1: <TweetList />,
|
||||||
|
2: <TwitterProfile />,
|
||||||
|
};
|
||||||
const MINIMUM_LOAD_TIME = 750;
|
const MINIMUM_LOAD_TIME = 750;
|
||||||
|
|
||||||
export const TwitterApp = () => {
|
export const TwitterApp = () => {
|
||||||
const [modalVisible, setModalVisible] = useState(false);
|
|
||||||
const [minimumLoadPassed, setMimimumLoadPassed] = useState(false);
|
const [minimumLoadPassed, setMimimumLoadPassed] = useState(false);
|
||||||
const classes = useStyles();
|
const [modalVisible, setModalVisible] = useState(false);
|
||||||
const twitter = useApp("TWITTER");
|
const [activePage, setActivePage] = useState(2);
|
||||||
const { profile } = useProfile();
|
const { profile } = useProfile();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -50,32 +41,33 @@ export const TwitterApp = () => {
|
|||||||
|
|
||||||
const openModal = () => setModalVisible(true);
|
const openModal = () => setModalVisible(true);
|
||||||
const hideModal = () => setModalVisible(false);
|
const hideModal = () => setModalVisible(false);
|
||||||
|
const handlePageChange = (e, page) => setActivePage(page);
|
||||||
|
|
||||||
// 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 = profile && minimumLoadPassed;
|
||||||
|
const showTweetButton = hasLoaded && activePage === 0;
|
||||||
|
const component = hasLoaded ? (
|
||||||
|
PAGE_COMPONENT_MAPPING[activePage]
|
||||||
|
) : (
|
||||||
|
<AppLoader />
|
||||||
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<AppWrapper>
|
<AppWrapper>
|
||||||
<AppTitle app={twitter} className={classes.root} />
|
<TwitterTitle />
|
||||||
<Button
|
|
||||||
onClick={openModal}
|
|
||||||
variant="contained"
|
|
||||||
style={{ backgroundColor: "#232323" }}
|
|
||||||
>
|
|
||||||
<AddCircleIcon color="action" />
|
|
||||||
</Button>
|
|
||||||
<AppContent>
|
<AppContent>
|
||||||
{hasLoaded ? (
|
<div id="twitter-content">
|
||||||
<>
|
<AddTweetModal visible={modalVisible} handleClose={hideModal} />
|
||||||
<AddTweetModal visible={modalVisible} handleClose={hideModal} />
|
{component}
|
||||||
<TweetList />
|
</div>
|
||||||
</>
|
|
||||||
) : (
|
|
||||||
<AppLoader />
|
|
||||||
)}
|
|
||||||
</AppContent>
|
</AppContent>
|
||||||
|
{showTweetButton && <TweetButton openModal={openModal} />}
|
||||||
|
<BottomNavigation
|
||||||
|
activePage={activePage}
|
||||||
|
handleChange={handlePageChange}
|
||||||
|
/>
|
||||||
</AppWrapper>
|
</AppWrapper>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
import React from "react";
|
||||||
|
import AppBar from "@material-ui/core/AppBar";
|
||||||
|
import Paper from "@material-ui/core/Paper";
|
||||||
|
import { makeStyles } from "@material-ui/core";
|
||||||
|
import TwitterIcon from "@material-ui/icons/Twitter";
|
||||||
|
|
||||||
|
const useStyles = makeStyles((theme) => ({
|
||||||
|
root: {
|
||||||
|
height: "60px",
|
||||||
|
width: "100%",
|
||||||
|
display: "flex",
|
||||||
|
flexFlow: "row nowrap",
|
||||||
|
justifyContent: "center",
|
||||||
|
alignItems: "center",
|
||||||
|
background: "#424242",
|
||||||
|
},
|
||||||
|
icon: {
|
||||||
|
color: "#00acee",
|
||||||
|
fontSize: 30,
|
||||||
|
},
|
||||||
|
}));
|
||||||
|
|
||||||
|
export function TwitterTitle() {
|
||||||
|
const classes = useStyles();
|
||||||
|
return (
|
||||||
|
<Paper elevation={24} variant="outlined" square className={classes.root}>
|
||||||
|
<TwitterIcon className={classes.icon} />
|
||||||
|
</Paper>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default TwitterTitle;
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
import React from "react";
|
||||||
|
import { makeStyles } from "@material-ui/core/styles";
|
||||||
|
import { TextField } from "@material-ui/core";
|
||||||
|
|
||||||
|
const useStyles = makeStyles({
|
||||||
|
formContainer: {
|
||||||
|
width: "100%",
|
||||||
|
marginTop: "8px",
|
||||||
|
},
|
||||||
|
textField: {
|
||||||
|
width: "100%",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
function ProfileField({ label, value, handleChange, allowChange, multiline }) {
|
||||||
|
const classes = useStyles();
|
||||||
|
const _handleChange = (e) => handleChange(e.target.value);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className={classes.formContainer}>
|
||||||
|
<TextField
|
||||||
|
className={classes.textField}
|
||||||
|
label={label}
|
||||||
|
value={value}
|
||||||
|
onChange={_handleChange}
|
||||||
|
disabled={!allowChange}
|
||||||
|
multiline={multiline}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
ProfileField.defaultProps = {
|
||||||
|
allowChange: true,
|
||||||
|
multiline: false,
|
||||||
|
};
|
||||||
|
|
||||||
|
export default ProfileField;
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
import React, { useState, useEffect } from "react";
|
||||||
|
import { makeStyles } from "@material-ui/core/styles";
|
||||||
|
import Fab from "@material-ui/core/Fab";
|
||||||
|
import PublishIcon from "@material-ui/icons/Publish";
|
||||||
|
import { useProfile } from "../../hooks/useProfile";
|
||||||
|
|
||||||
|
const useStyles = makeStyles((theme) => ({
|
||||||
|
root: {
|
||||||
|
position: "absolute",
|
||||||
|
bottom: "15px",
|
||||||
|
right: "15px",
|
||||||
|
},
|
||||||
|
button: {
|
||||||
|
background: "#00acee",
|
||||||
|
},
|
||||||
|
}));
|
||||||
|
|
||||||
|
const MINIMUM_LOAD_TIME = 750;
|
||||||
|
|
||||||
|
export function ProfileUpdateButton({ handleClick }) {
|
||||||
|
const classes = useStyles();
|
||||||
|
const [minimumLoadPassed, setMimimumLoadPassed] = useState(true);
|
||||||
|
const { updateInProgress } = useProfile();
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setMimimumLoadPassed(false);
|
||||||
|
const timeout = window.setTimeout(() => {
|
||||||
|
console.log("debug 1.0");
|
||||||
|
setMimimumLoadPassed(true);
|
||||||
|
}, MINIMUM_LOAD_TIME);
|
||||||
|
return () => window.clearTimeout(timeout);
|
||||||
|
}, [updateInProgress]);
|
||||||
|
|
||||||
|
const isLoading = updateInProgress || !minimumLoadPassed;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className={classes.root}>
|
||||||
|
<Fab
|
||||||
|
className={classes.button}
|
||||||
|
color="primary"
|
||||||
|
onClick={handleClick}
|
||||||
|
disabled={isLoading}
|
||||||
|
>
|
||||||
|
<PublishIcon />
|
||||||
|
</Fab>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default ProfileUpdateButton;
|
||||||
@@ -0,0 +1,86 @@
|
|||||||
|
import React, { useState } from "react";
|
||||||
|
import { makeStyles } from "@material-ui/core/styles";
|
||||||
|
import { useTranslation } from "react-i18next";
|
||||||
|
|
||||||
|
import Nui from "../../../../os/nui-events/utils/Nui";
|
||||||
|
import { useProfile } from "../../hooks/useProfile";
|
||||||
|
import Avatar from "../Avatar";
|
||||||
|
import ProfileField from "./ProfileField";
|
||||||
|
import ProfileUpdateButton from "./ProfileUpdateButton";
|
||||||
|
|
||||||
|
const useStyles = makeStyles((theme) => ({
|
||||||
|
root: {
|
||||||
|
position: "relative",
|
||||||
|
width: "100%",
|
||||||
|
height: "100%",
|
||||||
|
padding: "15px",
|
||||||
|
},
|
||||||
|
spacer: {
|
||||||
|
height: "8px",
|
||||||
|
},
|
||||||
|
}));
|
||||||
|
|
||||||
|
export function TwitterProfile() {
|
||||||
|
const classes = useStyles();
|
||||||
|
const { t } = useTranslation();
|
||||||
|
const { profile } = useProfile();
|
||||||
|
|
||||||
|
// note that this assumes we are defensively checking
|
||||||
|
// that profile is not null in a parent above this component.
|
||||||
|
// Annoyingling adding conditionals above this line to not render
|
||||||
|
// when profile === null results in a react error that different
|
||||||
|
// amounts of hooks are rendering
|
||||||
|
const [avatarUrl, handleAvatarChange] = useState(profile.avatar_url);
|
||||||
|
const [name, handleNameChange] = useState(profile.profile_name || "");
|
||||||
|
const [bio, handleBioChange] = useState(profile.bio || "");
|
||||||
|
const [location, handleLocationChange] = useState(profile.location || "");
|
||||||
|
const [job, handleJobChange] = useState(profile.job || "");
|
||||||
|
|
||||||
|
const handleUpdate = () => {
|
||||||
|
console.log("Update database");
|
||||||
|
const data = {
|
||||||
|
avatar_url: avatarUrl,
|
||||||
|
profile_name: name,
|
||||||
|
bio,
|
||||||
|
location,
|
||||||
|
job,
|
||||||
|
};
|
||||||
|
Nui.send("phone:updateTwitterProfile", data);
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className={classes.root}>
|
||||||
|
<Avatar avatarUrl={avatarUrl} showInvalidImage />
|
||||||
|
<div className={classes.spacer} />
|
||||||
|
<ProfileField
|
||||||
|
label={t("APPS_TWITTER_EDIT_PROFILE_AVATAR")}
|
||||||
|
value={avatarUrl}
|
||||||
|
handleChange={handleAvatarChange}
|
||||||
|
/>
|
||||||
|
<ProfileField
|
||||||
|
label={t("APPS_TWITTER_EDIT_PROFILE_NAME")}
|
||||||
|
value={name}
|
||||||
|
handleChange={handleNameChange}
|
||||||
|
/>
|
||||||
|
<ProfileField
|
||||||
|
label={t("APPS_TWITTER_EDIT_PROFILE_BIO")}
|
||||||
|
value={bio}
|
||||||
|
handleChange={handleBioChange}
|
||||||
|
multiline
|
||||||
|
/>
|
||||||
|
<ProfileField
|
||||||
|
label={t("APPS_TWITTER_EDIT_PROFILE_LOCATION")}
|
||||||
|
value={location}
|
||||||
|
handleChange={handleLocationChange}
|
||||||
|
/>
|
||||||
|
<ProfileField
|
||||||
|
label={t("APPS_TWITTER_EDIT_PROFILE_JOB")}
|
||||||
|
value={job}
|
||||||
|
handleChange={handleJobChange}
|
||||||
|
/>
|
||||||
|
<ProfileUpdateButton handleClick={handleUpdate} />
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default TwitterProfile;
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
.Mui-selected {
|
||||||
|
color: #00acee !important;
|
||||||
|
}
|
||||||
@@ -17,4 +17,12 @@ export const twitterState = {
|
|||||||
key: "createTweetSuccess",
|
key: "createTweetSuccess",
|
||||||
default: null,
|
default: null,
|
||||||
}),
|
}),
|
||||||
|
updateProfileLoading: atom({
|
||||||
|
key: "createTweetLoading",
|
||||||
|
default: false,
|
||||||
|
}),
|
||||||
|
updateProfileSuccess: atom({
|
||||||
|
key: "createTweetSuccess",
|
||||||
|
default: null,
|
||||||
|
}),
|
||||||
};
|
};
|
||||||
@@ -3,5 +3,7 @@ import { twitterState } from "./state";
|
|||||||
|
|
||||||
export const useProfile = () => {
|
export const useProfile = () => {
|
||||||
const profile = useRecoilValue(twitterState.profile);
|
const profile = useRecoilValue(twitterState.profile);
|
||||||
return { profile };
|
const updateInProgress = useRecoilValue(twitterState.updateProfileLoading);
|
||||||
|
const updateSuccessful = useRecoilValue(twitterState.updateProfileSuccess);
|
||||||
|
return { profile, updateInProgress, updateSuccessful };
|
||||||
};
|
};
|
||||||
@@ -30,6 +30,12 @@ function processTweet(tweet) {
|
|||||||
*/
|
*/
|
||||||
export const useTwitterService = () => {
|
export const useTwitterService = () => {
|
||||||
const setProfile = useSetRecoilState(twitterState.profile);
|
const setProfile = useSetRecoilState(twitterState.profile);
|
||||||
|
const setUpdateProfileLoading = useSetRecoilState(
|
||||||
|
twitterState.updateProfileLoading
|
||||||
|
);
|
||||||
|
const setUpdateProfileSuccess = useSetRecoilState(
|
||||||
|
twitterState.updateProfileSuccess
|
||||||
|
);
|
||||||
const setTweets = useSetRecoilState(twitterState.tweets);
|
const setTweets = useSetRecoilState(twitterState.tweets);
|
||||||
const setCreateLoading = useSetRecoilState(twitterState.createTweetLoading);
|
const setCreateLoading = useSetRecoilState(twitterState.createTweetLoading);
|
||||||
const setCreateSuccess = useSetRecoilState(twitterState.createTweetSuccess);
|
const setCreateSuccess = useSetRecoilState(twitterState.createTweetSuccess);
|
||||||
@@ -37,10 +43,14 @@ export const useTwitterService = () => {
|
|||||||
const _setProfile = (profile) => {
|
const _setProfile = (profile) => {
|
||||||
setProfile(profile[0]); // server returns an array of 1 profile
|
setProfile(profile[0]); // server returns an array of 1 profile
|
||||||
};
|
};
|
||||||
|
const _setUpdateProfileSuccess = (isSuccessful) => {
|
||||||
|
setUpdateProfileSuccess(isSuccessful === 1); // numeric 1 is returned by MySQL on successful query
|
||||||
|
setUpdateProfileLoading(false); // on any result we should set loading to false
|
||||||
|
};
|
||||||
|
|
||||||
const _setCreateSuccess = (isSuccessful) => {
|
const _setCreateSuccess = (isSuccessful) => {
|
||||||
setCreateSuccess(isSuccessful === 1); // numeric 1 is returned by MySQL on successful query
|
setCreateSuccess(isSuccessful === 1);
|
||||||
setCreateLoading(false); // on any result we should set loading to false
|
setCreateLoading(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
const _setTweets = (tweets) => {
|
const _setTweets = (tweets) => {
|
||||||
@@ -48,6 +58,16 @@ export const useTwitterService = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
useNuiEvent(types.APP_TWITTER, "getOrCreateTwitterProfile", _setProfile);
|
useNuiEvent(types.APP_TWITTER, "getOrCreateTwitterProfile", _setProfile);
|
||||||
|
useNuiEvent(
|
||||||
|
types.APP_TWITTER,
|
||||||
|
"updateProfileLoading",
|
||||||
|
setUpdateProfileLoading
|
||||||
|
);
|
||||||
|
useNuiEvent(
|
||||||
|
types.APP_TWITTER,
|
||||||
|
"updateProfileResult",
|
||||||
|
_setUpdateProfileSuccess
|
||||||
|
);
|
||||||
useNuiEvent(types.APP_TWITTER, "fetchTweets", _setTweets);
|
useNuiEvent(types.APP_TWITTER, "fetchTweets", _setTweets);
|
||||||
useNuiEvent(types.APP_TWITTER, "createTweetLoading", setCreateLoading);
|
useNuiEvent(types.APP_TWITTER, "createTweetLoading", setCreateLoading);
|
||||||
useNuiEvent(types.APP_TWITTER, "createTweetResult", _setCreateSuccess);
|
useNuiEvent(types.APP_TWITTER, "createTweetResult", _setCreateSuccess);
|
||||||
|
|||||||
@@ -0,0 +1,2 @@
|
|||||||
|
export const IMG_DEFAULT_AVATAR = "./media/twitter/egg.png";
|
||||||
|
export const IMG_INVALID_AVATAR = "./media/twitter/invalid.png";
|
||||||
@@ -19,6 +19,11 @@
|
|||||||
"APPS_TWITTER_CLOSE_IMAGE": "Close",
|
"APPS_TWITTER_CLOSE_IMAGE": "Close",
|
||||||
"APPS_TWITTER_TWEET": "Tweet",
|
"APPS_TWITTER_TWEET": "Tweet",
|
||||||
"APPS_TWITTER_CLOSE": "Close",
|
"APPS_TWITTER_CLOSE": "Close",
|
||||||
"APPS_TWITTER_CREATE_FAILED": "Failed to send your tweet"
|
"APPS_TWITTER_CREATE_FAILED": "Failed to send your tweet",
|
||||||
|
"APPS_TWITTER_EDIT_PROFILE_AVATAR": "Avatar URL",
|
||||||
|
"APPS_TWITTER_EDIT_PROFILE_NAME": "Profile name",
|
||||||
|
"APPS_TWITTER_EDIT_PROFILE_BIO": "Bio",
|
||||||
|
"APPS_TWITTER_EDIT_PROFILE_LOCATION": "Location",
|
||||||
|
"APPS_TWITTER_EDIT_PROFILE_JOB": "Job"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -8,6 +8,7 @@ const useStyles = makeStyles((theme) => ({
|
|||||||
},
|
},
|
||||||
box: {
|
box: {
|
||||||
width: "100%",
|
width: "100%",
|
||||||
|
height: "100%", // allow application to fill entireity of space
|
||||||
position: "relative",
|
position: "relative",
|
||||||
overflow: "auto",
|
overflow: "auto",
|
||||||
},
|
},
|
||||||
@@ -17,6 +18,7 @@ const useStyles = makeStyles((theme) => ({
|
|||||||
},
|
},
|
||||||
paper: {
|
paper: {
|
||||||
width: "100%",
|
width: "100%",
|
||||||
|
height: "100%", // allow application to fill entireity of space
|
||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
|||||||
@@ -271,3 +271,9 @@ AddEventHandler('onResourceStop', function(resource)
|
|||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Citizen.CreateThread(function()
|
||||||
|
Citizen.Wait(0)
|
||||||
|
Phone()
|
||||||
|
end)
|
||||||
@@ -41,8 +41,15 @@ RegisterNUICallback('phone:createTweet', function(data)
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
RegisterNUICallback('phone:getOrCreateTwitterProfile', function()
|
RegisterNUICallback('phone:getOrCreateTwitterProfile', function()
|
||||||
print('phone:getOrCreateTwitterProfile')
|
|
||||||
ESX.TriggerServerCallback('phone:getOrCreateTwitterProfile', function(profile)
|
ESX.TriggerServerCallback('phone:getOrCreateTwitterProfile', function(profile)
|
||||||
sendMessage('getOrCreateTwitterProfile', profile)
|
sendMessage('getOrCreateTwitterProfile', profile)
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
RegisterNUICallback('phone:updateTwitterProfile', function(data)
|
||||||
|
sendMessage('updateProfileLoading', true)
|
||||||
|
ESX.TriggerServerCallback('phone:updateTwitterProfile', function(result)
|
||||||
|
sendMessage('updateProfileResult', result)
|
||||||
|
TriggerEvent('phone:getOrCreateTwitterProfile')
|
||||||
|
end, data)
|
||||||
|
end)
|
||||||
@@ -8,6 +8,8 @@ Config.PhoneAsItem = false
|
|||||||
|
|
||||||
Config.twitter = {}
|
Config.twitter = {}
|
||||||
Config.twitter.characterLimit = 240
|
Config.twitter.characterLimit = 240
|
||||||
|
Config.twitter.allowEdtiableProfileName = true
|
||||||
|
Config.twitter.showAvatars = true
|
||||||
Config.twitter.enableEmojis = true
|
Config.twitter.enableEmojis = true
|
||||||
Config.twitter.renderImages = true -- whether or not links to images are automatically rendered on the UI
|
Config.twitter.renderImages = true -- whether or not links to images are automatically rendered on the UI
|
||||||
Config.twitter.maxImages = 3 -- max amount of images that can be attached to a single tweet
|
Config.twitter.maxImages = 3 -- max amount of images that can be attached to a single tweet
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 3.5 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 16 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 4.2 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 149 KiB |
@@ -104,3 +104,33 @@ ESX.RegisterServerCallback('phone:getOrCreateTwitterProfile', function(source, c
|
|||||||
cb(result)
|
cb(result)
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
function updateProfile(identifier, data, cb)
|
||||||
|
print(identifier)
|
||||||
|
print(data)
|
||||||
|
MySQL.Async.execute('UPDATE npwd_twitter_profiles SET avatar_url = @avatar_url, profile_name = @profile_name, bio = @bio, location = @location, job = @job WHERE identifier = @identifier',
|
||||||
|
{
|
||||||
|
['identifier'] = identifier,
|
||||||
|
['avatar_url'] = data.avatar_url,
|
||||||
|
['profile_name'] = data.profile_name,
|
||||||
|
['bio'] = data.bio,
|
||||||
|
['location'] = data.location,
|
||||||
|
['job'] = data.job,
|
||||||
|
}, function(result)
|
||||||
|
print('result1: ', result)
|
||||||
|
cb(result)
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
ESX.RegisterServerCallback('phone:updateTwitterProfile', function(source, cb, data)
|
||||||
|
local _source = source
|
||||||
|
local xPlayer = ESX.GetPlayerFromId(_source)
|
||||||
|
local _identifier = xPlayer.getIdentifier()
|
||||||
|
|
||||||
|
updateProfile(_identifier, data, function(result)
|
||||||
|
print('result2: ', result)
|
||||||
|
cb(result)
|
||||||
|
end)
|
||||||
|
end)
|
||||||
|
|
||||||
Reference in new issue
Block a user