import React, { useState, useEffect } from "react"; import * as BS from "react-bootstrap"; import { useRouteMatch } from "react-router-dom"; import autosize from "autosize"; import "moment-timezone"; import Popup from "reactjs-popup"; import twemoji from 'twemoji'; import history from "../../History.js"; import defaultAvatar from "../../default_discord_avatar.png"; import { FaAddressCard } from "react-icons/fa"; import EditSystem from "./Edit/EditSystem.js"; import EditSystemPrivacy from "./Edit/EditSystemPrivacy.js"; export default function System() { // match the url, if there's a member ID there, don't render this component at all const match = useRouteMatch("/dash/:memberID"); // get the user from the localstorage const [user, setUser] = useState(JSON.parse(localStorage.getItem("user"))); // bunch of useState stuff, used in the useEffect() hook below const [name, setName] = useState(""); const [tag, setTag] = useState(""); const [timezone, setTimezone] = useState(""); const [avatar, setAvatar] = useState(""); const [banner, setBanner] = useState(""); const [desc, setDesc] = useState(""); const [editDesc, setEditDesc] = useState(""); // more useState, this time to actually handle state // TODO: name them something more intuitive maybe? const [editMode, setEditMode] = useState(false); const [privacyEdit, setPrivacyEdit] = useState(false); const [privacyView, setPrivacyView] = useState(false); const [errorAlert, setErrorAlert] = useState(false); const [ errorMessage, setErrorMessage ] = useState(""); // this useEffect does a couple of things after the user is gotten from localstorage useEffect(() => { // first require the discord markdown parser const { toHTML } = require("../../Functions/discord-parser.js"); // check if there's a name object in user, if it's null, set name to a blank string, otherwise set name to user.name if (user.name) { setName(user.name); } else setName(""); // same as above, but with the user tag instead if (user.tag) { setTag(user.tag); } else setTag(""); // same as above but with timezone if (user.tz) { setTimezone(user.tz); } else setTimezone(""); // also trims the avatar url so that 1. pngs won't be converted to jpegs and 2. won't be resized to 256x256 if (user.avatar_url) { var avatarsmall = user.avatar_url.replace("&format=jpeg", ""); setAvatar(avatarsmall.replace("?width=256&height=256", "")); } else setAvatar(""); if (user.banner) { setBanner(user.banner); } else setBanner(""); // same as above, but with descriptions // two description variables! one is just the plain description, the other is parsed and converted to html if (user.description) { setDesc(toHTML(user.description)); setEditDesc(user.description); } else { setDesc("(no description)"); setEditDesc(""); } }, [user.description, user.tag, user.avatar_url, user.tz, user.name, user.banner]); // this just resizes the textarea when filled with larger amounts of text useEffect(() => { autosize(document.querySelector("textarea")); }); if (match) return null; return ( <> { user.banner && !localStorage.getItem("hidebanners") ?
: ""}Description:
{ localStorage.getItem("twemoji") ? : } { !user.banner || !localStorage.getItem("bottombanners") ? "" :