From ef653b0a6f12c0e05c4d960657f673f5a2c6463d Mon Sep 17 00:00:00 2001 From: David Snyder <45735850+GypsyDangerous@users.noreply.github.com> Date: Fri, 9 Oct 2020 23:19:31 -0400 Subject: [PATCH] Revert "Better dashboard (#20)" This reverts commit 80330588f7827f6d6fc930b3c4b0520b418feead. --- src/App.js | 2 +- src/components/DashBoard/Dashboard.js | 14 +- src/components/DashBoard/Dashboard.scss | 33 +--- .../DashBoard/Discord/DiscordPage.js | 160 ++++++++++++------ .../DashBoard/Discord/Plugins/App.js | 104 ------------ .../Plugins/CustomCommands/CommandItem.js | 21 +-- .../Plugins/CustomCommands/CreateCommand.js | 10 +- .../CustomCommands/CreateRoleCommand.js | 14 +- .../Plugins/CustomCommands/CustomCommands.js | 144 ++++++++-------- .../DashBoard/Discord/Plugins/Leveling.js | 4 +- .../DashBoard/Discord/Plugins/Logging.js | 12 +- .../DashBoard/Discord/Plugins/PluginCard.js | 43 +++-- .../DashBoard/Discord/Plugins/PluginHome.js | 59 ++----- 13 files changed, 252 insertions(+), 368 deletions(-) delete mode 100644 src/components/DashBoard/Discord/Plugins/App.js diff --git a/src/App.js b/src/App.js index 62abdb3..b8b053e 100644 --- a/src/App.js +++ b/src/App.js @@ -1,7 +1,7 @@ // production import React, { useEffect, useState, useRef } from "react"; import firebase from "./firebase"; -import { BrowserRouter as Router, Route, Redirect, Switch } from "react-router-dom"; +import { HashRouter as Router, Route, Redirect, Switch } from "react-router-dom"; import Home from "./components/Home/Home"; import About from "./components/About/About"; import Community from "./components/Community/Community"; diff --git a/src/components/DashBoard/Dashboard.js b/src/components/DashBoard/Dashboard.js index eb83096..c88bb36 100644 --- a/src/components/DashBoard/Dashboard.js +++ b/src/components/DashBoard/Dashboard.js @@ -13,16 +13,7 @@ const Dashboard = props => { const [appSettings, setAppSettings] = useState(); const [defaultSettings, setDefaultSettings] = useState(); const { currentUser } = useContext(AppContext); - const id = firebase.auth.currentUser.uid; - const [discordId, setDiscordId] = useState("") - useEffect(() => { - const idRegex = new RegExp("/\\d{17,19}[/\\b]") - const path = props.location.pathname+"/" - const id = path.match(idRegex) - if(id){ - setDiscordId(id[0].replace(/\//g, "")) - } - }, [props]) + const id = firebase.auth.currentUser.uid; useEffect(() => { (async () => { @@ -76,7 +67,7 @@ const Dashboard = props => { {/* overlay Settings */} - + Discord Settings @@ -86,7 +77,6 @@ const Dashboard = props => {
- {/* { const [refreshed, setRefreshed] = useState(false); const { isLoading, sendRequest: sendLoadingRequest } = useFetch(); const id = firebase.auth.currentUser.uid; - const { id: guildId } = useParams(); const { sendRequest } = useFetch(); const { currentUser, setCurrentUser } = useContext(AppContext); const { @@ -38,28 +37,25 @@ const DiscordPage = React.memo(({ location, history, match }) => { }, [rawDiscordData, discordDataLoading, setUserDiscordInfo]); useEffect(() => { - (async () => { - const guild = userDiscordInfo?.guilds?.find?.(guild => guild.id === guildId); - if (guild) { - setDisplayGuild(guildOption(guild)); - } - })(); - }, [userDiscordInfo, guildId]); + if (userConnectedGuildInfo?.name) { + setDisplayGuild(guildOption(userConnectedGuildInfo)); + } + }, [userConnectedGuildInfo]); const refreshToken = userDiscordInfo?.refreshToken; useEffect(() => { (async () => { if (!refreshToken || !id) return; if (refreshed) return console.log("already refreshed"); - console.log("refreshing"); - const otcData = (await firebase.db.collection("Secret").doc(id).get()).data(); - const otc = otcData?.value; + console.log("refreshing"); + const otcData = (await firebase.db.collection("Secret").doc(id).get()).data() + const otc = otcData?.value setRefreshed(true); const response = await fetch(`${process.env.REACT_APP_API_URL}/discord/token/refresh?token=${refreshToken}&id=${id}&otc=${otc}`); if (!response.ok) return; - const json = await response.json(); - console.log({ json }); + const json = await response.json(); + console.log({json}) if (!json) return; await firebase.db .collection("Streamers") @@ -95,7 +91,6 @@ const DiscordPage = React.memo(({ location, history, match }) => { }, [id, disconnect, setCurrentUser]); const guilds = userDiscordInfo?.guilds; - useSnapshot( firebase.db.collection("Streamers").doc(id).collection("discord").doc("data"), async snapshot => { @@ -108,15 +103,15 @@ const DiscordPage = React.memo(({ location, history, match }) => { const guildId = guildByName.id; const value = await sendRequest(`${process.env.REACT_APP_API_URL}/ismember?guild=` + guildId); const response = await sendRequest(`${process.env.REACT_APP_API_URL}/getchannels?new=true&guild=` + guildId); - const channelReponse = response.channels; - console.log(response.roles); - setUserConnectedGuildInfo({ + const channelReponse = response.channels + console.log(response.roles) + setUserConnectedGuildInfo({ name: guildByName.name, isMember: value?.result, icon: guildByName.icon, id: guildByName.id, - channels: channelReponse, - roles: response.roles, + channels: channelReponse, + roles: response.roles, connectedChannels: channelReponse?.filter(channel => userData.liveChatId?.includes(channel.id)), connected: true, }); @@ -153,36 +148,50 @@ const DiscordPage = React.memo(({ location, history, match }) => { async e => { const name = e.value; const guildByName = userDiscordInfo.guilds.find(guild => guild.name === name); - const selectedGuildId = guildByName.id; - try{ - - if (guildId) { - const path = match.url.split("/"); - if (path.length > 3) { - history.push(`${path.slice(0, 3).join("/")}/${selectedGuildId}`); - } else { - history.push(`${selectedGuildId}`); - } - } else { - history.push(`${match.url}/${selectedGuildId}`); - } - }catch(err){ - - } - const { result: isMember } = await sendLoadingRequest(`${process.env.REACT_APP_API_URL}/ismember?guild=` + selectedGuildId); - // const channelReponse = await sendLoadingRequest(`${process.env.REACT_APP_API_URL}/getchannels?guild=` + selectedGuildId); + const guildId = guildByName.id; + const { result: isMember } = await sendLoadingRequest(`${process.env.REACT_APP_API_URL}/ismember?guild=` + guildId); + const channelReponse = await sendLoadingRequest(`${process.env.REACT_APP_API_URL}/getchannels?guild=` + guildId); - // setUserConnectedGuildInfo({ - // name, - // isMember, - // icon: guildByName.icon, - // id: guildByName.id, - // channels: channelReponse, - // }); + setUserConnectedGuildInfo({ + name, + isMember, + icon: guildByName.icon, + id: guildByName.id, + channels: channelReponse, + }); }, [userDiscordInfo, sendLoadingRequest] ); + const onChannelSelect = useCallback( + async e => { + setUserConnectedGuildInfo(s => ({ + ...s, + connectedChannels: + e?.map(c => ({ + id: c.value, + name: c.label.props.children[0].props.children, + parent: c.label.props.children[1].props.children, + })) || [], + })); + await firebase.db + .collection("Streamers") + .doc(id) + .update({ + liveChatId: e?.map(c => c.value) || [], + }); + await firebase.db + .collection("Streamers") + .doc(id) + .collection("discord") + .doc("data") + .update({ + liveChatId: e?.map(c => c.value) || [], + }); + }, + [id] + ); + return (

Discord Settings

@@ -201,6 +210,7 @@ const DiscordPage = React.memo(({ location, history, match }) => { placeholder="Select Guild" options={userDiscordInfo?.guilds?.filter(guild => guild.permissions.includes("MANAGE_GUILD")).map(guildOption)} styles={colorStyles} + isDisabled={!!userConnectedGuildInfo?.connected} /> @@ -221,15 +231,67 @@ const DiscordPage = React.memo(({ location, history, match }) => {
- ) : guildId ? ( - ) : ( - <> + <> + {userConnectedGuildInfo.connected ? ( + <> +

select channels to listen to

+ a.parent.localeCompare(b.parent)) - ?.map(channel => ({ - value: channel.id, - label: ( - <> - {channel.name} - {channel.parent} - - ), - }))} - options={userConnectedGuildInfo.channels - .sort((a, b) => a.parent.localeCompare(b.parent)) - .map(channel => ({ - value: channel.id, - label: ( - <> - {channel.name} - {channel.parent} - - ), - }))} - styles={{ - ...colorStyles, - container: styles => ({ ...styles, ...colorStyles.container }), - }} - isMulti - /> - - )} -
- - ); -}; - -export default React.memo(App); diff --git a/src/components/DashBoard/Discord/Plugins/CustomCommands/CommandItem.js b/src/components/DashBoard/Discord/Plugins/CustomCommands/CommandItem.js index 742920f..c3202f7 100644 --- a/src/components/DashBoard/Discord/Plugins/CustomCommands/CommandItem.js +++ b/src/components/DashBoard/Discord/Plugins/CustomCommands/CommandItem.js @@ -13,14 +13,14 @@ const CommandItem = ({ description, setCommands, bannedRoles, - permittedRoles, + allowedRoles, allowedChannels, cooldown, deleteUsage, setCreatingCommand, role, - guild: userConnectedGuildInfo, }) => { + const { userConnectedGuildInfo } = useContext(DiscordContext); const { setName, setResponse, @@ -34,7 +34,6 @@ const CommandItem = ({ setError, setEditing, } = useContext(CommandContext); - const [allowedRoles, setPermittedRoles] = useState([]); const guildId = userConnectedGuildInfo.id; const deleteMe = useCallback(async () => { setCommands(prev => { @@ -48,18 +47,6 @@ const CommandItem = ({ }); }, [guildId, name, setCommands]); - useEffect(() => { - setPermittedRoles( - permittedRoles.map(id => { - const role = userConnectedGuildInfo?.roles?.find?.(r => r.id === id); - return { - value: `${role.name}=${JSON.stringify(role)}`, - label: {role.name}, - }; - }) - ); - }, [permittedRoles, userConnectedGuildInfo]); - const edit = async () => { setName(name); setResponse(message); @@ -71,7 +58,6 @@ const CommandItem = ({ }); } setDescription(description); - console.log({ allowedRoles }); setAllowedRoles(allowedRoles || []); setAllowedChannels(allowedChannels || []); setBannedRoles(bannedRoles || []); @@ -87,13 +73,14 @@ const CommandItem = ({ setDisplayRole(userConnectedGuildInfo.roles.find(r => r.id === role)); }, []); + console.log(displayRole); return (
- +
diff --git a/src/components/DashBoard/Discord/Plugins/CustomCommands/CreateCommand.js b/src/components/DashBoard/Discord/Plugins/CustomCommands/CreateCommand.js index be59ce2..b73df81 100644 --- a/src/components/DashBoard/Discord/Plugins/CustomCommands/CreateCommand.js +++ b/src/components/DashBoard/Discord/Plugins/CustomCommands/CreateCommand.js @@ -53,8 +53,8 @@ const parseSelectValue = value => { } }; -const CreateCommand = ({ setCreatingCommand, children, role, guild: userConnectedGuildInfo }) => { - console.log(userConnectedGuildInfo) +const CreateCommand = ({ setCreatingCommand, children, role }) => { + const { userConnectedGuildInfo } = useContext(DiscordContext); const { editing, setEditing, @@ -89,8 +89,7 @@ const CreateCommand = ({ setCreatingCommand, children, role, guild: userConnecte })) ); } - }, [editing]); - + }, [editing]); return ( <> @@ -265,8 +264,7 @@ const CreateCommand = ({ setCreatingCommand, children, role, guild: userConnecte bannedRoles: parsedBannedRoles, permittedRoles: parsedAllowedRoles, allowedChannels: parsedAllowedChannels, - cooldownTime: cooldown*60000, - cooldown, + cooldown, DM: false, description, }; diff --git a/src/components/DashBoard/Discord/Plugins/CustomCommands/CreateRoleCommand.js b/src/components/DashBoard/Discord/Plugins/CustomCommands/CreateRoleCommand.js index a2e03ae..a634c6d 100644 --- a/src/components/DashBoard/Discord/Plugins/CustomCommands/CreateRoleCommand.js +++ b/src/components/DashBoard/Discord/Plugins/CustomCommands/CreateRoleCommand.js @@ -6,9 +6,9 @@ import { colorStyles } from "../../../../Shared/userUtils"; import RoleItem from "../../../../Shared/RoleItem"; import { CommandContext } from "../../../../../contexts/CommandContext"; -const CreateRoleCommand = ({ setCreatingCommand, guild: userConnectedGuildInfo }) => { - const { setActivePlugins } = useContext(DiscordContext); - const { roleToGive, setRoleToGive } = useContext(CommandContext); +const CreateRoleCommand = ({ setCreatingCommand }) => { + const { setActivePlugins, userConnectedGuildInfo } = useContext(DiscordContext); + const { roleToGive, setRoleToGive } = useContext(CommandContext); return ( <>

Role To give

@@ -16,13 +16,13 @@ const CreateRoleCommand = ({ setCreatingCommand, guild: userConnectedGuildInfo } - - or @DisStreamBot -

@@ -96,39 +80,28 @@ const PluginHome = ({ match, guildId }) => {
- {displayPlugins.map(plugin => ( - + ))}
{activePlugins["leveling"] && ( - + )} {activePlugins["logging"] && ( - + )} {activePlugins["commands"] && ( - + )} - - -