working profile and editing of profile

This commit is contained in:
erik-sn committed 2020-09-26 16:29:33 -04:00
1 parent 5072a31aab
commit 9fe4cf0188
27 files changed
+459 -51

No files matched your search

@@ -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;