Skip to content
This repository has been archived by the owner on Sep 1, 2021. It is now read-only.

Revert "Intuitive" #35

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 6 additions & 35 deletions src/components/DashBoard/Dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ import AccountSettings from "./Account/Account";
import plugins from "./Discord/Plugins/plugins.json";
import { DiscordContextProvider, DiscordContext } from "../../contexts/DiscordContext";
import { useMediaQuery } from "@material-ui/core";
import Snackbar from "@material-ui/core/Snackbar";
import IconButton from "@material-ui/core/IconButton";
import CloseIcon from "@material-ui/icons/Close";

const Dashboard = props => {
const [overlaySettings, setOverlaySettings] = useState();
Expand All @@ -21,15 +18,7 @@ const Dashboard = props => {
const { currentUser, dropDownOpen: open } = useContext(AppContext);
const id = firebase.auth.currentUser.uid;
const [discordId, setDiscordId] = useState("");
const { activePlugins, dashboardOpen, setDashboardOpen } = useContext(DiscordContext);

const handleClose = (event, reason) => {
if (reason === "clickaway") {
return;
}
setDashboardOpen(false);
};

const { activePlugins } = useContext(DiscordContext);
useEffect(() => {
const idRegex = new RegExp("/\\d{17,19}[/\\b]");
const path = props.location.pathname + "/";
Expand Down Expand Up @@ -88,13 +77,13 @@ const Dashboard = props => {
.filter(key => activePlugins[key])
.sort(),
[activePlugins]
);

const showDropdown = useMediaQuery("(min-width: 900px)");
);
const showDropdown = useMediaQuery("(min-width: 900px)")

return (
<div className="settings-container">
<div className={`${open ? "dashboard-open" : ""} setting-options`}>
<div className={`${open ? "dashboard-open" : "" } setting-options`}>
<NavLink className="setting-link" activeClassName="active" to={`${props.match.url}/appsettings`}>
App Settings
</NavLink>
Expand All @@ -104,13 +93,12 @@ const Dashboard = props => {
<NavLink className="setting-link" activeClassName="active" to={`${props.match.url}/discord${discordId ? `/${discordId}` : ""}`}>
Discord Settings
</NavLink>
{showDropdown && !!displayPlugins.length && window?.location?.pathname?.includes?.("discord") && (
{showDropdown && !!displayPlugins.length && window?.location?.pathname?.includes?.("discord") && (
<ul>
{displayPlugins.map(key => {
const plugin = plugins.find(plugin => plugin.id === key);
return (
<NavLink
key={plugin?.id}
className="setting-link smaller"
activeClassName="active"
to={`${props.match.url}/discord/${discordId}/${plugin?.id}`}
Expand Down Expand Up @@ -169,23 +157,6 @@ const Dashboard = props => {
</Route>
<Redirect to={`${props.match.url}/appsettings`} />
</Switch>
<Snackbar
anchorOrigin={{
vertical: "bottom",
horizontal: "left",
}}
open={dashboardOpen}
autoHideDuration={6000}
onClose={handleClose}
message="Saved"
action={
<React.Fragment>
<IconButton size="small" aria-label="close" color="inherit" onClick={handleClose}>
<CloseIcon fontSize="small" />
</IconButton>
</React.Fragment>
}
/>
</div>
</div>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const FancySwitch = withStyles({
opacity: "1 !important",
},
},

focusVisible: {},
})(Switch);

const parseSelectValue = value => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import RoleItem from "../../../../Shared/RoleItem";
import { CommandContext } from "../../../../../contexts/CommandContext";

const CreateRoleCommand = ({ setCreatingCommand, guild: userConnectedGuildInfo }) => {
const { setActivePlugins } = useContext(DiscordContext);
const { roleToGive, setRoleToGive } = useContext(CommandContext);
return (
<>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import React, { useContext } from "react";
import { CommandContext } from "../../../../../contexts/CommandContext";

const CreateTextCommand = () => {
const { setActivePlugins, userConnectedGuildInfo } = useContext(DiscordContext);
const { response, setResponse } = useContext(CommandContext);
return (
<>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@ import CommandItem from "./CommandItem";
import { CommandContext } from "../../../../../contexts/CommandContext";

const CustomCommands = ({ location, guild: userConnectedGuildInfo }) => {
const [loggingChannel, setLoggingChannel] = useState("");
const [activeEvents, setActiveEvents] = useState({});
const [allEvents, setAllEvents] = useState({});
const [creatingCommand, setCreatingCommand] = useState(false);
const [commands, setCommands] = useState({});
const { setActivePlugins, setDashboardOpen } = useContext(DiscordContext);
const { setActivePlugins } = useContext(DiscordContext);
const guildId = userConnectedGuildInfo?.id;
const {
setName,
Expand Down Expand Up @@ -93,7 +96,6 @@ const CustomCommands = ({ location, guild: userConnectedGuildInfo }) => {
});
return newPlugs;
});
setDashboardOpen(true)
}}
>
Disable
Expand Down
38 changes: 6 additions & 32 deletions src/components/DashBoard/Discord/Plugins/Leveling.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { useMediaQuery } from "@material-ui/core";

const ToggleChevron = styled.span`
& > * {
transition: 0.25s;
transition: .25s;
transform: rotate(${props => (!props.closed ? "180deg" : "0deg")});
}
`;
Expand Down Expand Up @@ -61,20 +61,15 @@ const Leveling = ({ location, guild: userConnectedGuildInfo }) => {
const [levelUpAnnouncement, setLevelUpAnnouncement] = useState();
const [announcementChannel, setAnnouncementChannel] = useState(false);
const [levelUpMessage, setLevelUpMessage] = useState("Congrats {player}, you leveled up to level {level}!");
const { setActivePlugins, setDashboardOpen, saveOnType } = useContext(DiscordContext);
const { setActivePlugins } = useContext(DiscordContext);
const [ranksClosed, setRanksClosed] = useState(false);
const guildId = userConnectedGuildInfo?.id;

const handleTypeSelect = useCallback(
async e => {
const guildLevelRef = firebase.db.collection("Leveling").doc(guildId);
setLevelUpAnnouncement(e);
try {
await guildLevelRef.update({ type: e.value });
} catch (err) {
await guildLevelRef.set({ type: e.value });
}
setDashboardOpen(true);
await guildLevelRef.update({ type: e.value });
},
[guildId]
);
Expand All @@ -84,12 +79,7 @@ const Leveling = ({ location, guild: userConnectedGuildInfo }) => {
const guildLevelRef = firebase.db.collection("Leveling").doc(guildId);
const message = e.target.value;
setLevelUpMessage(message);
try {
await guildLevelRef.update({ message });
} catch (err) {
await guildLevelRef.set({ message });
}
saveOnType();
await guildLevelRef.update({ message });
},
[guildId]
);
Expand All @@ -98,12 +88,7 @@ const Leveling = ({ location, guild: userConnectedGuildInfo }) => {
async e => {
const guildLevelRef = firebase.db.collection("Leveling").doc(guildId);
setAnnouncementChannel(e);
try {
guildLevelRef.update({ notifications: e.value });
} catch (err) {
guildLevelRef.set({ notifications: e.value });
}
setDashboardOpen(true);
guildLevelRef.update({ notifications: e.value });
},
[guildId]
);
Expand Down Expand Up @@ -140,7 +125,7 @@ const Leveling = ({ location, guild: userConnectedGuildInfo }) => {
})();
}, [location, guildId]);

const smallScreen = useMediaQuery("(max-width: 500px)");
const smallScreen = useMediaQuery("(max-width: 500px)")

return (
<div>
Expand All @@ -154,25 +139,14 @@ const Leveling = ({ location, guild: userConnectedGuildInfo }) => {
onClick={() => {
setActivePlugins(prev => {
const newPlugs = { ...prev, leveling: false };

firebase.db
.collection("DiscordSettings")
.doc(guildId || " ")
.update({
activePlugins: newPlugs,
})
.catch(err => {
firebase.db
.collection("DiscordSettings")
.doc(guildId || " ")
.set({
activePlugins: newPlugs,
});
});

return newPlugs;
});
setDashboardOpen(true);
}}
>
Disable
Expand Down
74 changes: 23 additions & 51 deletions src/components/DashBoard/Discord/Plugins/Logging.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ import { DiscordContext } from "../../../../contexts/DiscordContext";
import { colorStyles } from "../../../Shared/userUtils";
import Select from "react-select";
import FormControlLabel from "@material-ui/core/FormControlLabel";
import { Switch, Tooltip } from "@material-ui/core";
import { Switch } from "@material-ui/core";
import { withStyles } from "@material-ui/core/styles";
import { blueGrey } from "@material-ui/core/colors";
import InfoTwoToneIcon from "@material-ui/icons/InfoTwoTone";

const FancySwitch = withStyles({
root: {
Expand Down Expand Up @@ -35,13 +34,14 @@ const FancySwitch = withStyles({
opacity: "1 !important",
},
},
focusVisible: {},
})(Switch);

const Leveling = ({ location, guild: userConnectedGuildInfo }) => {
const [loggingChannel, setLoggingChannel] = useState("");
const [activeEvents, setActiveEvents] = useState({});
const [allEvents, setAllEvents] = useState({});
const { setActivePlugins, setDashboardOpen } = useContext(DiscordContext);
const { setActivePlugins } = useContext(DiscordContext);
const [channelOverrides, setChannelOverrides] = useState({});
const guildId = userConnectedGuildInfo?.id;

Expand Down Expand Up @@ -88,9 +88,9 @@ const Leveling = ({ location, guild: userConnectedGuildInfo }) => {
setActiveEvents(active || {});
} else {
try {
await firebase.db.collection("loggingChannel").doc(guildId).update({});
firebase.db.collection("loggingChannel").doc(guildId).update({});
} catch (err) {
await firebase.db.collection("loggingChannel").doc(guildId).set({});
firebase.db.collection("loggingChannel").doc(guildId).set({});
}
}
})();
Expand All @@ -102,52 +102,32 @@ const Leveling = ({ location, guild: userConnectedGuildInfo }) => {
}, [location, guildId]);

const handleOverrideSelect = useCallback(
async (e, category) => {
(e, category) => {
setChannelOverrides(prev => ({
...prev,
[category]: e,
}));
try {
await firebase.db
.collection("loggingChannel")
.doc(guildId)
.update({
[`channelOverrides.${category}`]: e?.value || false,
});
} catch (err) {
await firebase.db
.collection("loggingChannel")
.doc(guildId)
.set({
[`channelOverrides.${category}`]: e?.value || false,
});
}
setDashboardOpen(true);
firebase.db
.collection("loggingChannel")
.doc(guildId)
.update({
[`channelOverrides.${category}`]: e?.value || false,
});
},
[guildId]
);

const handleEventToggle = useCallback(async (e, id) => {
const handleEventToggle = useCallback((e, id) => {
setActiveEvents(prev => ({
...prev,
[id]: e.target.checked,
}));
try {
await firebase.db
.collection("loggingChannel")
.doc(guildId)
.update({
[`activeEvents.${id}`]: e.target.checked,
});
} catch (err) {
await firebase.db
.collection("loggingChannel")
.doc(guildId)
.set({
[`activeEvents.${id}`]: e.target.checked,
});
}
setDashboardOpen(true);
firebase.db
.collection("loggingChannel")
.doc(guildId)
.update({
[`activeEvents.${id}`]: e.target.checked,
});
});

const handleAnnoucmentSelect = useCallback(
Expand All @@ -159,7 +139,6 @@ const Leveling = ({ location, guild: userConnectedGuildInfo }) => {
} catch (err) {
await guildLevelRef.set({ server: e.value });
}
setDashboardOpen(true);
},
[guildId]
);
Expand All @@ -184,7 +163,6 @@ const Leveling = ({ location, guild: userConnectedGuildInfo }) => {
});
return newPlugs;
});
setDashboardOpen(true);
}}
>
Disable
Expand Down Expand Up @@ -227,15 +205,10 @@ const Leveling = ({ location, guild: userConnectedGuildInfo }) => {
/>
</div>
{[...new Set(Object.values(allEvents || {}).map(val => val.category))].sort().map(category => (
<React.Fragment key={category}>
<>
<h4 className="plugin-section-title">{category}</h4>
<div className="plugin-section">
<h4 className="plugin-section-title">
Category Logging Channel Override{" "}
<Tooltip placement="top" arrow title="If set, events in this category will be logged in this channel instead of the default">
<InfoTwoToneIcon />
</Tooltip>
</h4>
<h4 className="plugin-section-title">Channel Override</h4>
<div className="plugin-section subtitle" style={{ width: "100%" }}>
<Select
closeMenuOnSelect
Expand Down Expand Up @@ -264,7 +237,7 @@ const Leveling = ({ location, guild: userConnectedGuildInfo }) => {
}}
/>
<span className="toggle-button">
<button onClick={() => handleOverrideSelect(null, category)}>Clear Category Override</button>
<button onClick={() => handleOverrideSelect(null, category)}>Clear Channel Override</button>
</span>
</div>
<h4 className="plugin-section-title" style={{ width: "100%" }}>
Expand All @@ -276,7 +249,6 @@ const Leveling = ({ location, guild: userConnectedGuildInfo }) => {
.sort()
.map(([key, event]) => (
<FormControlLabel
key={key}
control={
<FancySwitch
color="primary"
Expand All @@ -291,7 +263,7 @@ const Leveling = ({ location, guild: userConnectedGuildInfo }) => {
/>
))}
</div>
</React.Fragment>
</>
))}
</div>
</div>
Expand Down
Loading