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

Revert "fixed issue with channels in app plugin" #23

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
113 changes: 46 additions & 67 deletions src/components/DashBoard/Discord/DiscordPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,30 +29,6 @@ const DiscordPage = React.memo(({ location, history, match }) => {
setUserConnectedChannels,
setUserConnectedGuildInfo,
} = useContext(DiscordContext);
const [connectedGuild, setConnectedGuild] = useState();

useEffect(() => {
(async () => {
const guild = userDiscordInfo?.guilds?.find?.(guild => guild.id === guildId);
if (guild) {
const response = await fetch(`${process.env.REACT_APP_API_URL}/getchannels?new=true&guild=` + guildId);
const memberResponse = await fetch(`${process.env.REACT_APP_API_URL}/ismember?guild=` + guildId);
const json = await response.json();
const memberJson = await memberResponse.json();
const roles = json.roles;
const channels = json.channels;
const userData = (await firebase.db.collection("Streamers").doc(id).get()).data();
setConnectedGuild({ ...guild, roles, channels, isMember: memberJson?.result });
setUserConnectedGuildInfo({
...guild,
roles,
channels,
isMember: memberJson?.result,
connectedChannels: channels?.filter(channel => userData.liveChatId?.includes(channel.id)),
});
}
})();
}, [guildId, userDiscordInfo?.guilds, setUserConnectedGuildInfo]);

const [rawDiscordData, discordDataLoading, DiscordDataError] = useDocument(firebase.db.doc(`Streamers/${id}/discord/data`));

Expand Down Expand Up @@ -120,35 +96,35 @@ const DiscordPage = React.memo(({ location, history, match }) => {

const guilds = userDiscordInfo?.guilds;

// useSnapshot(
// firebase.db.collection("Streamers").doc(id).collection("discord").doc("data"),
// async snapshot => {
// const data = snapshot.data();
// if (data) {
// const userData = (await firebase.db.collection("Streamers").doc(id).get()).data();
// const connectedGuildId = data.connectedGuild;
// const guildByName = guilds?.find?.(guild => guild.id === connectedGuildId);
// if (guildByName) {
// 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({
// name: guildByName.name,
// isMember: value?.result,
// icon: guildByName.icon,
// id: guildByName.id,
// channels: channelReponse,
// roles: response.roles,
// connectedChannels: channelReponse?.filter(channel => userData.liveChatId?.includes(channel.id)),
// connected: true,
// });
// }
// }
// },
// [id, guilds]
// );
useSnapshot(
firebase.db.collection("Streamers").doc(id).collection("discord").doc("data"),
async snapshot => {
const data = snapshot.data();
if (data) {
const userData = (await firebase.db.collection("Streamers").doc(id).get()).data();
const connectedGuildId = data.connectedGuild;
const guildByName = guilds?.find?.(guild => guild.id === connectedGuildId);
if (guildByName) {
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({
name: guildByName.name,
isMember: value?.result,
icon: guildByName.icon,
id: guildByName.id,
channels: channelReponse,
roles: response.roles,
connectedChannels: channelReponse?.filter(channel => userData.liveChatId?.includes(channel.id)),
connected: true,
});
}
}
},
[id, guilds]
);

useSnapshot(
firebase.db.collection("Streamers").doc(id).collection("discord").doc("data"),
Expand Down Expand Up @@ -177,19 +153,22 @@ 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 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);

Expand Down Expand Up @@ -243,7 +222,7 @@ const DiscordPage = React.memo(({ location, history, match }) => {
</a>
</div>
) : guildId ? (
<PluginHome connectedGuild={connectedGuild} guildId={guildId} match={match} />
<PluginHome guildId={guildId} match={match} />
) : (
<></>
)}
Expand Down
16 changes: 15 additions & 1 deletion src/components/DashBoard/Discord/Plugins/PluginHome.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,23 @@ import CustomCommands from "./CustomCommands/CustomCommands";
import { CommandContextProvider } from "../../../../contexts/CommandContext";
import App from "./App";

const PluginHome = ({ match, guildId, connectedGuild }) => {
const PluginHome = ({ match, guildId }) => {
const [prefix, setPrefix] = useState("!");
const { userDiscordInfo, activePlugins, setActivePlugins } = useContext(DiscordContext);
const [connectedGuild, setConnectedGuild] = useState();

useEffect(() => {
(async () => {
const guild = userDiscordInfo?.guilds?.find?.(guild => guild.id === guildId);
if (guild) {
const response = await fetch(`${process.env.REACT_APP_API_URL}/getchannels?new=true&guild=` + guildId);
const json = await response.json();
const roles = json.roles;
const channels = json.channels
setConnectedGuild({ ...guild, roles, channels });
}
})();
}, [guildId, userDiscordInfo?.guilds]);

useEffect(() => {
(async () => {
Expand Down