Skip to content

Commit

Permalink
improve mod channel updating
Browse files Browse the repository at this point in the history
  • Loading branch information
GypsyDangerous committed Aug 19, 2020
1 parent 381b7a4 commit ddd089e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
9 changes: 1 addition & 8 deletions src/components/Channels.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,15 +157,8 @@ const Channels = React.memo(props => {

useEffect(() => {
(async () => {
const channelsInfo = await Promise.all(
userData.ModChannels?.map?.(async channel => {
const apiUrl = `${process.env.REACT_APP_SOCKET_URL}/resolveuser?user=${channel.id}&platform=twitch`;
const response = await fetch(apiUrl);
return response.json();
}) || []
);
setModChannels(
channelsInfo
userData.modChannels
?.sort((a, b) => a.login.localeCompare(b.login))
?.map(channel => {
return { ...channel, modPlatform: "twitch", uid: sha1(channel.id) };
Expand Down
8 changes: 6 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,13 @@ const App = () => {
const removedChannels = userData.removedChannels || [];
const NewModChannels = (await modChannelResponse.json()).filter(channel => !removedChannels.includes(channel.id));

const ModChannels = [...NewModChannels, ...(userData.ModChannels || [])].filter(
const ModChannels = await Promise.all([...NewModChannels, ...(userData.ModChannels || [])].filter(
(thing, index, self) => index === self.findIndex(t => t.id === thing.id)
);
).map(async channel => {
const apiUrl = `${process.env.REACT_APP_SOCKET_URL}/resolveuser?user=${channel.id}&platform=twitch`;
const response = await fetch(apiUrl);
return response.json();
}));
firebase.db.collection("Streamers").doc(currentUser.uid).update({
profilePicture,
ModChannels,
Expand Down

0 comments on commit ddd089e

Please sign in to comment.